list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
[COLOR="Red"]__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT[/COLOR]
[COLOR="Red"]#define Pat_1 0x1
#define Pat_2 0x2
#define Pat_3 0x3[/COLOR]
[COLOR="Red"]w_temp EQU 0x71 ; variable used for context saving
status_temp EQU 0x72 ; variable used for context saving
cblock 0x20
PatFlags
Del0
Del1
Select
endc[/COLOR]
org 0000h
goto Main
org 0004h
[COLOR="Red"]movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
[/COLOR]
[COLOR="Red"]clrf PatFlags[/COLOR]
incf Select,F ;increment the Select register on each press
movf Select,W
bcf STATUS,Z
xorlw .1 ;if it is press once?
btfsc STATUS,Z
[COLOR="Red"]bsf PatFlags, Pat_1 ;YES,then set Pattern1[/COLOR]
movf Select,W
bcf STATUS,Z
xorlw .2 ;if it is press twice?
btfsc STATUS,Z
[COLOR="Red"]bsf PatFlags, Pat_2 ;YES,then set Pattern2[/COLOR]
movf Select,W
bcf STATUS,Z
xorlw .3 ;if it is press thrise?
btfsc STATUS,Z
[COLOR="Red"]bsf PatFlags, Pat_3 ;YES,then set Pattern3[/COLOR]
[COLOR="Red"]movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents[/COLOR]
retfie
Main bsf STATUS,RP0
movlw b'00000001'
movwf TRISB
bsf INTCON,GIE
bsf INTCON,INTE
bcf STATUS,RP0
clrf PORTB
clrf Select
[COLOR="Red"] clrf PatFlags
bsf PatFlags, Pat_1 ; Set pattern 1 as default at startup.
loop
btfsc PatFlags, Pat_1
call PAT1
btfsc PatFlags, Pat_2
call PAT2
btfsc PatFlags, Pat_3
call PAT3
goto loop[/COLOR]
;********
;Patterns
;********
PAT1; --
; ---
call Delay
[COLOR="Red"]return[/COLOR]
PAT2; ---
; ---
call Delay
[COLOR="Red"]return[/COLOR]
PAT3; ---
; ---
call Delay
[COLOR="Red"]return[/COLOR]
;*****
;Delay
;*****
Delay decfsz Del0, f
goto $-1
decfsz Del1, f
goto $-3
return
end