4.1 MCC Generated Code
To generate this project using MPLAB Code Configurator (MCC), follow the next steps:
- Create a new MPLAB X IDE project for PIC18F47Q10.
- Open MCC from the toolbar (more
information about how to install the MCC plug-in can
be found here.
- 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.
- From the Device Resources window, add
ADCC. Then do the following configuration:
- Enable ADC: Check
- Operating: Low_pass_filter_mode
- Clock Source: FRC
- Result Alignment: Right
- Positive Reference: VDD
- Negative Reference: VSS
- In Computation
Features tab:
- Repeat: 100
- Arc Right Shift: 4
- Go to Pin Manager → Grid View and select the RA0 pin as ANx input for the ADCC:
- 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).
- Press the Generate button. The generated code can now be found in the project folder.
- Add to the main.c file before the
main()
function the following line of code.uint16_t volatile adcVal;
In themain()
function add the code that discharges the sample capacitor, starts the conversion on the analog channel and returns the value in the variable that can be read with the debugger.ADCC_DischargeSampleCapacitor(); adcVal = ADCC_GetSingleConversion(channel_ANA0); while (1) { ; }