' PicBasic Pro Compiler 2.42, 16F877A,
' PicBasic Pro program to demonstrate the setup and use of analog comparators.
' This program will not compile for the 16F877, as it has no comparators. You
' must use the 16F877A, or another PICmicro MCU with comparators. Inputs are
' analog voltages on RA0 and RA3. The program will compare the voltages and
' tell you which is greater.
a
C1OUT VAR CMCON.6 ' Alias C1OUT to output bit in CMCON
ADCON1 = 7 ' Make all PORTA and PORTE pins digital
CMCON = 2 ' Set comparators to mode 010 (see datasheet)
Low PORTE.2 ' Set LCD to write mode
Pause 150 ' Pause to let LCD power up
Loop:
If C1OUT Then ' Check comparator output
' Display if C1OUT = 1
LCDOut $fe,1, "C1OUT = 1"
LCDOut $fe,$C0, "PORTA.3 GREATER"
Else
' Display if C1OUT = 0
LCDOut $fe,1, "C1OUT = 0"
LCDOut $fe,$C0, "PORTA.0 GREATER"
End If
Pause 100 ' Pause 100mS to reduce LCD flicker
GoTo loop ' Do it forever