Hi all I’m doing a small led project. It has only three patterns. The patterns are changing through RB0 external switch.
Inside the Delay loop I’m checking the INTF flag bit. The patterns are not changing very well. Mostly it’s skipping the patterns & changing in a messy way.
Help me to solve this problem.
Thanks
Inside the Delay loop I’m checking the INTF flag bit. The patterns are not changing very well. Mostly it’s skipping the patterns & changing in a messy way.
Help me to solve this problem.
Thanks
Code:
processor PIC16F84A
include <P16F84A.inc>
__config 3ffbh
errorlevel -302
cblock 20h
d1,d2,Select
endc
org 0000h
Main bsf STATUS,RP0
movlw b'00000001'
movwf TRISB
bsf INTCON,GIE ;enable global int enable
bsf INTCON,INTE ;enable ext interrupt
bcf STATUS,RP0
clrf PORTB
clrf Select
movlw 01h ;load 1 to Select reg
movwf Select
goto PAT1
************************************
Delay & detect which PATTERN to loop
************************************
DEL0.1 btfsc INTCON,INTF ;has external Int occur?
goto Choose ;YES,then goto choose pattern
movlw 0x1F ;NO,then carry on the delay
movwf d1
movlw 0x4F
movwf d2
DEL0.1A
decfsz d1, f
goto $+2
decfsz d2, f
goto DEL0.1A
goto $+1
return
Choose bcf INTCON,INTF ;turn off ext interrupt
incf Select,F ;increment Select value by one
movf Select,W
bcf STATUS,Z
xorlw .2 ;check the Select reg value 2 or not?
btfsc STATUS,Z
goto PAT2
xorlw .3 ;check the Select reg value 3 or not?
btfsc STATUS,Z
goto PAT3
xorlw .4 ;check the Select reg value is 4?
btfsc STATUS,Z
goto $+1
clrf Select
goto PAT1
************
LED patterns
************
PAT1 movlw 01H ;pattern 1
movwf PORTB
call DEL0.1
movlw 02H
movwf PORTB
call DEL0.1
movlw 04H
movwf PORTB
call DEL0.1
movlw 0AH
movwf PORTB
call DEL0.1
movlw 14H
movwf PORTB
call DEL0.1
movlw 2AH
movwf PORTB
call DEL0.1
movlw 54H
movwf PORTB
call DEL0.1
movlw 28H
movwf 06H
call DEL0.1
movlw 50H
movwf PORTB
call DEL0.1
movlw 20H
movwf PORTB
call DEL0.1
movlw 40H
movwf PORTB
call DEL0.1
movlw 00H
movwf PORTB
call DEL0.1
goto PAT1
PAT2 movlw 02H ;pattern 2
movwf PORTB
PAT2A call DEL0.1
bcf STATUS,C
rlf PORTB,F
btfss PORTB,6
goto $-4
PAT2B call DEL0.1
rrf PORTB,F
btfss PORTB,1
goto PAT2B
goto PAT2A
PAT3 movlw 00H ;pattern 3
movwf PORTB
call DEL0.1
movlw 02H
movwf PORTB
call DEL0.1
movlw 06H
movwf PORTB
call DEL0.1
movlw 0EH
movwf PORTB
call DEL0.1
movlw 1EH
movwf PORTB
call DEL0.1
movlw 3EH
movwf PORTB
call DEL0.1
movlw 7EH
movwf PORTB
call DEL0.1
goto PAT3
end