2.1 MCC Generated Code

To generate this project using MPLAB Code Configurator (MCC), follow the next steps:

  1. Create a new MPLAB X IDE project for PIC18F47Q10.
  2. Open MCC from the toolbar (more information about how to install the MCC plug-in can be found here).
  3. Go to Project Resources → System → System Module and make the following configurations:
    • Oscillator Select: HFINTOSC
    • HF Internal Clock: 1 MHz
    • Clock Divider: 1
    • In the Watchdog Timer Enable field in the WWDT tab, WDT Disabled has to be selected
    • In the Programming tab, Low-Voltage Programming Enable has to be checked
  4. From the Device Resources window, add TMR0 and do the following configurations:

    Timer0 Configuration:

    • Enable Timer: checked
    • Timer Clock tab
      • Clock Source: LFINTOSC
      • Clock Prescaler: 1:16
      • Postscaler: 1:1
      • Timer mode: 8-bit
      • Enable Synchronization: unchecked
    • Timer period: 100 ms
    • Enable Timer Interrupt: checked
  5. Open Pin Manager → Grid View window and select UQFN40 in the MCU package field and make the following pin configuration:
    • Set Port E pin 0 (RE0) as output
    Figure 2-1. Pin Mapping
  6. Click Pin Module in the Project Resources and set the custom name for RE0 to LED0.
  7. Click Generate in the Project Resources tab.
  8. In the main.c file generated by MCC, change or add the following code:
    • Enable the global and peripheral interrupts
    • Add the TMR0 Interrupt function
    • Set the TMR0 interrupt handler initializer
    void TMR0_compareInterrupt(void);
    
    void main(void)
    {
        // Initialize the device
        SYSTEM_Initialize();
    
        // Enable the Global Interrupts
        INTERRUPT_GlobalInterruptEnable();
    
        // Enable the Peripheral Interrupts
        INTERRUPT_PeripheralInterruptEnable();
    
        TMR0_SetInterruptHandler(TMR0_compareInterrupt);
        
        while (1)
        {
            // Add your application code
        }
    }
    
    void TMR0_compareInterrupt(void)
    {
        LED0_Toggle();
    }