This post provides the comparatorΒ code for PIC12F675 microcontroller. As we know, PIC12F675 microcontroller has one built in op-amp, which can be used as comparator. 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 blink an LED 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[1].
In the above circuit[2], a variable voltage signal of 0 to 5 volts can be applied on Pin6 of PIC12F675 controller. Pin7 and Pin6 are the input pins for the comparator and Pin5 is output pin. In the above circuit shown, Pin6 is attached with the -ve pin of the comparator and on the +ve pin a reference voltage of 2.5v are appliedΒ internally. LED attached on the GP5 pin shows the result of the comparator.
So, in the above figure, GP5 pin is high because voltage on Pin6 of PIC12F675 is 2.45v, which is less than 2.5v. If a voltage higher than 2.5v is applied on Pin6, then GP5 will become low.
Code
The code for the main function is shown below.
Downloads
Comparator code for 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 Comparator Code and Proteus Simulation