Hello David
You've done quite a bit. I have re-arranged the code a bit. I think this will work. I am awed by your enthusiasm. Changes that I made are highlighted by capitals.
Code:
'************************************************* **************************
' Lighthouse led flashing routines in which pressing button on rb4 is intended
' to sequence thru Pattern1 -- Pattern2 --off or if no button is pressed
' shutdown will occur when pattern is completed'
' When (if ?) program finally works the simple flashing will be replaced
' by appropriate lighthouse patterns.
' ************************************************** *************************
@ DEVICE pic16f628a,intrc_osc_noclkout,mclr_on,wdt_off
x var byte
pattern var byte
TRISB = 110000
TRISA = 000000
CMCON = 7
OPTION_REG.7=0 ' 0 = Enable PORTB Pull Ups
@ Device wdt_off ' Disable the WatchDog Timer
INTCON.3=1 ' Interrupt Control Register (RBIE)
PORTB = 0
PORTA = 0
porta.0 = 1
porta.1 = 1
porta.2 = 1
PORTB.4 = 1 ' THIS NEEDS TO BE SET HIGH SINCE YOU ARE LATER
' USING A LOW TO SENSE A BUTTON PRESS
PATTERN = 1
main:
INTCON.0=0 ' clear any pending (RBIF)
@ SLEEP ' Start program with pic asleep
INTCON.0=0 ' clear any pending (RBIF) rb4 pulled low to wake
' BIFURCATE THE OPERATION DEPENDING ON PATTERN SELECTED
IF PATTERN = 1 THEN GOTO PATTERN1
IF PATTERN = 2 THEN GOTO PATTERN2
goto main
pattern1:
for x = 1 to 100
PORTA.0 = 0 ' pattern 2 flag prevents
pause 200 ' premature jump when rb4
' PUTTING THE EVALUATION HERE, SPEEDS UP THE BUTTON SENSING
IF PORTB.4 = 0 THEN
PATTERN = 2 ' INTERRUPTS LOOP TO JUMP TO
GOTO PATTERN2
ENDIF
porta.0 = 1 ' first pulled low
pause 200
' PUTTING THE EVALUATION HERE, PREVENTS A PREMATURE JUMP
IF PORTB.4 = 0 THEN
PATTERN = 2 ' INTERRUPTS LOOP TO JUMP TO
GOTO PATTERN2
ENDIF
next x
goto main 'puts the pic to sleep
pattern2:
for x = 1 to 100
PORTA.1 = 0
pause 200
IF PORTB.4 = 0 THEN
PATTERN = 1 ' INTERRUPTS LOOP TO JUMP TO
GOTO PATTERN1
ENDIF
porta.1 = 1
pause 200
IF PORTB.4 = 0 THEN
PATTERN = 1 ' INTERRUPTS LOOP TO JUMP TO
GOTO PATTERN1
ENDIF
next x
goto main 'puts the pic to sleep
shutdown: 'puts pic to sleep and returns to program start
goto main
end
Bookmarks