;Blinky VR1 requires the use of VR1 (DIP switch VR1 = ON)
LIST p=16F88
INCLUDE "p16f88.inc"
ERRORLEVEL 0, -302
__CONFIG _CONFIG1, 0x2F30
__CONFIG _CONFIG2, 0x3FFC
movlf macro x,y ;MACRO movlf <literal>, <register>
movlw x ;W = literal
banksel y ;make sure it's in the right bank
movwf y ;register = W
endm
cblock 0x20 ;start of general purpose registers
Delay_Count ;delay loop counter
endc
org 0x000 ;this is where the program starts running
Init movlf 0x07, CMCON ;turn comparators off (make it like a 16F84)
movlf b'00000000', ADCON1 ;
movlf b'00000010', ANS ;select RA1/AN1 as analog input
movlf b'11001101', ADCON0 ;AD enabled, RC clock, AN1 selected (VR1) & begin conversion
Red1 movlf b'01000000', PORTA ;LED1 RED
movlf b'10111110', TRISA
call Delay
Red2 movlf b'10000000', PORTA ;LED2 RED
movlf b'00111111', TRISA
call Delay
Red3 movlf b'00000001', PORTA ;LED3 RED
movlf b'01111110', TRISA
call Delay
Green3 movlf b'10000000', PORTA ;LED3 GREEN
movlf b'01111110', TRISA
call Delay
Green2 movlf b'01000000', PORTA ;LED2 GREEN
movlf b'00111111', TRISA
call Delay
Green1 movlf b'00000001', PORTA ;LED1 GREEN
movlf b'10111110', TRISA
call Delay
goto Red1 ;repeat forever
Delay
banksel ADRESH ;
movf ADRESH, W ;W = VR1 value 0x00-0xFF
banksel ADCON0 ;
bsf ADCON0,0x2 ;start next conversion
banksel Delay_Count ;
movwf Delay_Count ;Delay_Count = W
addlw 0x00 ;used to set Zero flag
btfsc STATUS, Z ;if ADRESH = 0 (Z flag is set)
return ;then return early (no need to delay)
Loop
nop ;32KHz Clock (default internal OSC speed)
decfsz Delay_Count, f ;
goto Loop ;
return ;return
END