3.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. The peripherals can be added to the project from the Device Resources window. Add ADCC and FVR. The peripherals are now available for configuration in the Project Resources window under Peripherals.
  5. ADCC configuration:
    • Enable ADC: Check
    • Operating: Basic Mode
    • Clock Source: FRC
    • Result Alignment: Right
    • Positive Reference: VDD
    • Negative Reference: VSS
  6. FVR configuration:
    • Enable FVR: Check
    • Enable Temperature Sensor: Check
    • Voltage Range Selection: Lo_Range
  7. Press the Generate button. The generated code can now be found in the project folder.
  8. Add the following code to the main.c file. Add the following code before the main() function. It provides two macros that will convert the value read from the ADCC to a value in Celsius or Fahrenheit.
    #define VDD                                 3.3
    #define ADC_TO_CELSIUS(adcVal)              (int16_t) \
                    ((1241.4967 - VDD * (1024 - (adcVal))) / 2.70336)
    #define ADC_TO_FAHRENHEIT(adcVal)           (int16_t) \
                    ((((1241.4967 - VDD * (1024 - (adcVal))) / 2.70336) * 1.8) + 32)
    
    uint16_t volatile adcVal;
    int16_t volatile celsiusValue;
    int16_t volatile fahrenheitValue; 
    Add the following code to the main() function. It will discharge the sampling capacitor and start a conversion on the temperature channel and return the value in a variable.
    ADCC_DischargeSampleCapacitor();
    adcVal = ADCC_GetSingleConversion(channel_Temp);
            
    celsiusValue = ADC_TO_CELSIUS(adcVal); 
    fahrenheitValue = ADC_TO_FAHRENHEIT(adcVal);