This is how I would write code so that a pattern is displayed when the switch is pressed and then a different pattern would be displayed 1 second later.
Note how calling multiplex 25 times makes up a delay of 10mS and therefore makes timing 1 second very easy.
Have fun.
Mike.
Code:
;******** Main Code
start
movlw b'001000' ; Configure only GP3 as a input
tris GPIO
loop btfsc GPIO,3 ; Is switch 3 pressed?
goto TurnOn ;yes so go turn on LEDs
clrf LEDs ;turn off LEDs
clrf LEDs2
clrf DisplayCount ;reset counter
goto Display
TurnOn movfw DisplayCount
xorlw .10 ;reached 1 second
btfsc STATUS,Z
goto Pattern2 ;yes, go do pattern 2
incf DisplayCount,F ;increment counter - only if displaying pattern 1
;do pattern 1
movlw 0x55 ;setup pattern 1
movwf LEDs
movlw 0x05
movwf LEDs2
goto Display
Pattern2
movlw 0xAA ;setup pattern 2
movwf LEDs
movlw 0x0A
movwf LEDs2
Display
movlw .25 ;400uS * 25 = 10mS
movwf MultiCount
DisLoop call Multiplex ;this takes 400uS
decfsz MultiCount,F ;time up
goto DisLoop ;no, so do it again
goto loop
;****************** Delay Subroutine ( 10 ms )
Note how calling multiplex 25 times makes up a delay of 10mS and therefore makes timing 1 second very easy.
Have fun.
Mike.