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 do the following configuration:
    • Oscillator Select: HFINTOSC
    • HF Internal Clock: 1 MHz
    • Clock Divider: 1
    • In the Watchdog Timer Enable field in WWDT tab, make sure “WDT Disabled” is selected
    • In the Programming tab, make sure Low-Voltage Programming Enable is checked.
  4. From the Device Resources window, add ADCC, then do the following configuration:
    • Enable ADC: Check
    • Operating: Basic Mode
    • Clock Source: FRC
    • Result Alignment: Right
    • Positive Reference: VDD
    • Negative Reference: VSS
  5. Go to Pin Manager → Grid View and select the RA0 pin as ANx input for the ADCC.
    Figure 2-1. Pin Mapping
  6. Go to the Pin Module in the Project Resources tab and set the RA0 pin as analog and as input (check to see if output is not checked).
  7. Press the Generate button. The generated code can now be found in the project folder.
  8. Add the following code to the main function.

    Add this before the main function. This is the variable that stores the value and can be read with the debugger.

    uint16_t volatile adcVal;
    Add this code inside the body of the main() function. This discharges the sample capacitor and adds a function that starts the conversion on the analog channel and returns the value.
    ADCC_DischargeSampleCapacitor();
    adcVal = ADCC_GetSingleConversion(channel_ANA0);
    
    while (1)
    {
       ;
    }