PIC12F675 Comparator Code and Proteus Simulation
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.
In the above circuit, 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.
The code for the main function is shown below.
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
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days
Current Project / Post can also be found using:
- pic12f comparator
- simulation of an op amp as a comparator using proteous