9.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 TMR2, TMR4 and make the following configurations:

    Timer2 Configuration:

    • Enable Timer: checked
    • Control Mode: Roll over pulse
    • Ext. Reset Source: TMR4_postscaled
    • Start/Reset Option: Starts at T2ON = 1 and TMR2_ers = 0
    • Timer Clock tab
      • Clock Source: LFINTOSC
      • Clock Prescaler: 1:64
      • Postscaler: 1:1
    • Set 100 ms period in the Timer Period tab
      • Enabled Timer Interrupt: checked
  5. Timer4 Configuration:

    • Enable Timer: checked
    • Control mode: One shot
    • Ext. Reset Source: T4INPPS pin
    • Start/Reset Option: Starts at TMR4_ers = 0 and Resets at TMR4_ers = 1
    • Timer Clock tab:
      • Clock Source: LFINTOSC
      • Clock Prescaler: 1:64
      • Postscaler: 1:1
    • Set 500 ms period in the Timer Period tab
  6. Open Pin Manager → Grid View window, select UQFN40 in the MCU package field and select the I/O pins outputs to enable the internal signal access to the I/O.
    Figure 9-1. Pin Mapping
  7. Click Pin Module in the Project Resources, set the custom name for RE0 to LED0 and select Output box. For RC7 pin, select WPU.
  8. Click Generate in the Project Resources tab.
  9. The Interrupt function that will toggle LED0 at Timer2 period will need to be added before main function:
    void TMR2_interrupt(void)
    {
        /* Toggle LED0 at the Timer2Period frequency */
        LED0_Toggle();
    }
    
    void main(void)
    {
        // Initialize the device
        SYSTEM_Initialize();
        TMR2_SetInterruptHandler(TMR2_interrupt);
        // Enable the Global Interrupts
        INTERRUPT_GlobalInterruptEnable();
        // Enable the Peripheral Interrupts
       INTERRUPT_PeripheralInterruptEnable();
        while (1)
        {
            // Add your application code
        }
    }