How to Use Analog Comparators in PIC16F877A (Mode-5)
The following code demonstrate how to use analog comparator module in mode-5. In this mode positive input of the two comparators are combine. The default output of each comparator can be monitor on C1OUT on RA4 pin and C2OUT on RA5 pin. You can also map theses outputs on general purpose IOs. The code is written in “mikroC PRO for PIC v.6.6.3” IDE and simulation is done with Proteus 8.0 SP0. At the end of code, you can find complete project files for download. Code in mikroC // Two Common Reference Comparators with Outputs #define CMP_MODE 5 // default comparators o/p signals sbit C1OUT_Dir at TRISA.B4; sbit C2OUT_Dir at TRISA.B5; sbit C1OUT_Out at PORTA.B4; sbit C2OUT_Out at PORTA.B5; // user assign comparator o/p signals sbit CMP1_Dir at TRISC.B0; sbit CMP2_Dir at TRISC.B1; sbit CMP1_Out at PORTC.B0; sbit CMP2_Out at PORTC.B1; // function proto-type void CMP_Setting(void); void main(void) { // set direction as output ...