dim V as word ' Declarations section
main: ' Main program
TRISIO = %00001000 ' set GP4 as input GP0,1,3 as output
ANSEL = %00001000 ' GP ,1,2,3,5 as digital, GP4 as analog
'ADON0 ADC register setup
ADCON0 = %10001101
'R justify result
'use VDD as Vreff
'select channel 3
'enable ADC
GPIO = 0 ' reset all outputs
run:
delay_ms(10)
V = ADC_read(3) ' check battery voltage from AN3 pin
if V < 700 then GPIO.2 = 1 'if V is under 11 V
else GPIO.2 = 0 end if 'the red warning led will stay on
if (V < 920) and (V > 703) then GPIO.0 = 1
else GPIO.0 = 0 end if 'if V is under 14.4 V then lightup red led
if V > 780 then GPIO.1 = 1
else GPIO.1 = 0 end if 'if V is over 12.2 V then lightup green led
' warning level check and flash routine which will be locked into if over volt
' occurs
if V > 990 then
GPIO = 0
Flash:
GPIO.2 = 1
delay_ms(300)
GPIO.2 = 0
delay_ms(400)
goto Flash
else
goto run
end if
'repaeat cycle
end.