Hi,
Not exactly new but sporadic (and ancient) Have dumped code using RA2 and after more study produced the following using rb4. Amost works! i can now sequence through the patterns if I allow them to complete but if I press the button whilst the pattern is in progress I can only toggle between patterns 1 and 2 and am unable to get it to shut down ! Sorry about the code layout I seem to be using the tags incorrectly will try again here goes;
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
TRISB = %11110000
TRISA = %00000000
CMCON = 7
OPTION_REG.7=0 ' 0 = Enable PORTB Pull Ups
@ Device wdt_off ' Disable the WatchDog Timer
INTCON.3=1 ' Interrupt Control Register
PORTB = 0
PORTA = 0
flag var byte
flag = 0
porta.0 = 1
porta.1 = 1
porta.2 = 1
main:
INTCON.0=0 '
@ SLEEP ' Start program with pic asleep
INTCON.0=0 ' rb4 pulled low to wake
pattern1:
for x = 1 to 100
if flag = 1 and portb.4 = 0 then pattern2 ' Interrupts loop to jump to
PORTA.0 = 0 ' pattern 2 flag prevents
pause 200 ' premature jump when rb4
porta.0 = 1 ' first pulled low
pause 200
flag = 1
next x
INTCON.0=0 ' puts pic to sleep at natural
@ SLEEP ' end of pattern1
INTCON.0=0
goto main
pattern2:
flag = 0
for x = 1 to 100
if flag = 1 and portb.4 = 0 then shutdown ' Interrupts loop to jump to
flag = 0 ' shutdown
PORTA.1 = 0
pause 200
porta.1 = 1
pause 200
flag = 1
next x
INTCON.0=0 'puts pic to sleep at natural
@ SLEEP 'end of pattern2
INTCON.0=0
goto main
shutdown: 'puts pic to sleep and returns to program start
INTCON.0=0
@ sleep
INTCON.0=0
goto main
end
/code
Bookmarks