Aborting a PAUSE
I have a very simple program that turns an LED on and off. I want the program to immediately stop if a switch on RA.2 is pushed. If I do it this way (see below) it may take one second to exit the loop. I want the RA.2 input to even override a pause command.
plp_a = 0
DO WHILE RA.2 = 1
RA.0 = ~RA.0
pause 1000
LOOP
rb = %00111100
Thanks
Post Edited By Moderator (Bean (Hitt Consulting)) : 7/29/2007 10:03:59 PM GMT
plp_a = 0
DO WHILE RA.2 = 1
RA.0 = ~RA.0
pause 1000
LOOP
rb = %00111100
Thanks
Post Edited By Moderator (Bean (Hitt Consulting)) : 7/29/2007 10:03:59 PM GMT

Comments
DO WHILE AbortBtn = No PAUSE 50 INC ledTmr IF ledTmr = 20 THEN Led = ~Led ledTmr = 0 ENDIF LOOPThis checks the abort button 20 times per second, instead of once per second as with your code.
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 PROGRAM Start Start: plp_a = 0 tris_b = 0 tris_c = 0 ctr var byte rnd var byte DO RC = %00000001 'Light Normal Mode LED indicator. RB = 255 'Turn lights on. DO WHILE RA.1 = 1 'Normal Mode (Activates dimmer switch.) IF RB < 255 THEN RB = RB + ~RA.2 ENDIF IF rb > 0 THEN RB = RB - ~RA.3 ENDIF PAUSE 2 LOOP RC = %00000010 'Light Fade Mode LED indicator. DO WHILE RA.1 = 1 'Fade Mode (Lights adjust to a random brightness.) RANDOM rnd 'Generate random number. IF rnd <= RB THEN FOR ctr = RB TO rnd STEP -1 DEC RB PAUSE 2 NEXT ELSE FOR ctr = RB TO rnd INC RB PAUSE 2 NEXT ENDIF LOOP RB = 0 RC = %00000100 'Light Blink Mode LED indicator. DO WHILE RA.1 = 1 'Blink Mode (Lights turn on and off.) rb = ~rb pause 1000 LOOP LOOPConnected to the RB port is another SX that dies the PWM command.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NOTE this isn't actual code
main:
if btn_a = 1 then mode = mode+1
if btn_b = 1 then goto THEEND
if mode => maxmode then mode=0
if mode = 0 gosub loopa
if mode = 1 gosub loopb
if mode = 2 gosub loopc
goto main
loopa:
turn output on
return
loopb:
if delaytemp = maxdelay then toggle output
if delaytemp = maxdelay then delaytemp = 0
delaytemp = delaytemp + 1
return
etc
If your just flashing a led why not
a pushbutton· +· resistor + flashing led all in series
············································ led that flashes by itself..
··············································|\
·+
·PushB·
[noparse][[/noparse]·resistor]
| ||----· -
············································· |/
Or a 555 timer astable with a reset button wired to pin 4
Ronald Nollet