PIC12F675 ADC code and Proteus simulation
This post provides the ADC code using PIC12F675 microcontroller. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.
It is assumed that you know how to interface LCD with PIC12F675 microcontroller. If you don’t then please read this page first, before proceeding with this article.
The result of simulating the code in Proteus is shown below.
In the above figure, pin3(AN3) of PIC12F675 is being used as ADC input pin. The result of ADC conversion is shown on the LCD screen. If you attach pin3 of PIC12F675 to ground, then a value of 0000 will be displayed on the LCD screen and if you attach pin3 with 5v power supply, then a value of 1023 will be displayed on the LCD screen. In other words, ADC resolution is 10bits and value of ADC result varies from 0(0v) to 1023(5v). Because there is a variable resistor of 50% value attached on pin3 of PIC12F675 in Figure1, that is why it has 2.5v on it. As a result, a value of 511(Half of 1023) is being displayed on the LCD.
Consider the figure shown below.
This figure shows that at a single time, only one ADC channel can be selected as an input channel for ADC conversion. We can select AN0 or AN1 or AN2 or AN3 channel depending upon CHS1:CHS0 bits. In the code I have given a simple channel selection method (Explained below in the code section). I have selected VCFG to be zero, hence VREF is equal to VDD (Of-course you can change this if you want).
The code used to initialize ADC input channels is shown below.
ADC code using PIC12F675 was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.
For more detail: PIC12F675 ADC code and Proteus simulation
For All Your PCB Need, One-stop PCB Solution Services Appear:
EasyEDA: free PCB design tool, 200,000+ engineers are using
PCBs: 10pcs 2-layer 10x10cm only $8.21, on-time global shipping
Components: save 50% on cost, save on freight if shipped with ordered PCBs
Current Project / Post can also be found using:
- adc code for mplab
- pic 12f675 mplab code