|
ME Labs, Inc. 719-520-5323 |
|
|
|
ME Labs, Inc. | 1-719-520-5323 | Example Program - CMP877A.pbpPICBASIC PRO 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. On the LAB-X1, POT1 and POT3 adjust the respective inputs.' Name : CMP877A.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : PM or MPASM
' Target PIC : 40-pin 16F877A
' Hardware : LAB-X1 Experimenter Board
' Oscillator : 4MHz external crystal
' Keywords : COMPARATORS, LCDOUT
' Description : PICBASIC PRO 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. On the LAB-X1, POT1 and POT3 adjust the respective
' inputs.
'
' Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
Define LOADER_USED 1 ' Required only for use with boot Loader
C1OUT VAR CMCON.6 ' Alias C1OUT to output bit in CMCON register
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
mainloop:
IF C1OUT Then ' Check comparator output
LCDOut $fe,1, "C1OUT = 1" ' Display if C1OUT = 1
LCDOut $fe,$C0, "PORTA.3 GREATER"
Else
LCDOut $fe,1, "C1OUT = 0" ' Display if C1OUT = 0
LCDOut $fe,$C0, "PORTA.0 GREATER"
EndIF
Pause 100 ' Pause 100mS to reduce LCD flicker
GoTo mainloop ' Do it forever
End
Download the program file. |
|
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|