de1A equ 20h ;
delB equ 21h ;
temp1 equ 22h ;
temp2 equ 23h ;
pushes equ 24h
flashes equ 25h
Stat_sav equ 26h
W_sav equ 27h
;****************************************************************
;Equates
;****************************************************************
status equ 0x03
rp1 equ 0x06
rp0 equ 0x05
status equ 03h
option_reg equ 81h
;bits
rp0 equ 5 ;bit 5 of the status register
;****************************************************************
;Beginning of program
;****************************************************************
org 0x00
GOTO SetUp
nop
ORG 4 ;interrupts always vector to here
GOTO isr
nop
SetUp bsf status, rp0 ;Bank 1
movlw b'11111000' ;Set TRIS GP0,1,2 out GP3,4,5 input
movwf TRISIO ;
bcf option_reg,7 ;pull-ups enabled
MOVLW b'00000100' ;prescaler (1:32)
MOVWF OPTION_REG 80h ;TMR0 interrupts = 6 mS apart
BCF STATUS, RP0 ;bank 0
movlw 07h ;turn off Comparator ports
movwf CMCON ;must be placed in bank 0
Clrf TMR0 ;clear Timer0 register
clrf flashes
incf flashes
movlw 0xA0 ;set GIE <7> and T0IE <5>
movwf INTCON ;enable Interrupts
goto Main
isr MOVWF W_sav ;first save critical registers
SWAPF STATUS,W
BCF STATUS,RP0 ;change to bank 0
MOVWF Stat_sav
btfss portA,0 ;test switchA
call switchPressed
BCF INTCON,T0IF
BCF INTCON,INTF
SWAPF Stat_sav,W
MOVWF STATUS ; restore status
SWAPF W_sav,F
SWAPF W_sav,W ; restore w without changing status
RETFIE
;********************
;* Delays *
;********************
_10mS movlw 0Ah
movwf delB
nop
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
_250mS nop
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
;****************************
;* Sub Routines *
;****************************
switchPressed
movf flashes,W
movwf temp1
movlw 06
xorwf temp1 ;if flashes=6
btfss status,z ;z=1 if flashes=6
goto $+4
movlw 1
movwf flashes
goto $-8
bsf portA,xx ;turn on LED
call _250mS
bcf portA,xx ;turn off LED
call _250mS
decfsz temp1,f
goto $-5
incf flashes,f
btfss portA,0 ;loop until SwA is released
goto $-1
retlw 00
;************************
;* Main *
;************************
Main
goto Main
;************************
;*EEPROM *
;************************
org 2100h
END