Quote:
INCLUDE "modedefs.bas"
FF var PortC.0
FrontOut var PortC.1
RearOut var PortC.2
Voltage var word
Perfect var word
define OSC 20
DEFINE DEBUG_REG PortC
DEFINE DEBUG_BIT 5
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1
Define ADC_BITS 10
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 10
TRISC.0 = 1 'FF (Flip/Flop)
TRISC.1 = 0 'FrontOut
TRISC.2 = 0 'RearOut
'0 Digital 1 Analogue
ANSEL.6=0 'RearOut
ANSEL.5=0 'FrontOut
ANSEL.4=1 'FF
CM1CON0.7=0
CM2CON0.7=0 'Disable comparator
ADCON0.7=1 'Right Justified
ADCON0.6=0 'Voltage reference is VDD
ADCON0.5=0 'Turns on AN4 to analogue
ADCON0.4=1
ADCON0.3=0
ADCON0.2=0
ADCON0.0=1
CCP1CON.3=0
CCP1CON.2=0
CCP1CON.1=0
CCP1CON.0=0
Perfect = 512
Loop:
GOSUB Get_Voltage
gOSUB Compare
debug "Voltage=", DEC VOltage, cr
Goto Loop
Get_Voltage:
ADCIN FF, Voltage
Return
Compare:
If Voltage < Perfect then
Low FrontOut
endif
If Voltage > Perfect then
Low RearOut
endif
Return