Here's my version... we will check the switch action inside delay procedure.
Code:
'Objective to turn LEDS on and off at the same time
DEFINE OSC 20
Duty VAR Word
Cycle0 VAR BYTE
Cycle1 VAR BYTE
cycles VAR Word
Switch Var PORTC.6
DelayV VAR BYTE
TRISB = %00000000
TRISC = %01000000
start:
Cycle1 = 2
Loop:
;sequence 1
;==========
For Duty = 0 to 2000 'ALL OFF ---> All ON
For cycles = 0 to Cycle1
Portb = %00000000
DelayV=2000-Duty
Gosub DelayUs
Portb = %11110000
DelayV=Duty
Gosub DelayUs
Next cycles
Next Duty
DelayV=1000
Gosub DelayUs
;sequence 0 (t = 1)
;=================
For Duty = 2000 to 0 step -1 'ALL ON--> ALL OFF
For cycles = 0 to Cycle1
Portb = %11110000
DelayV=Duty
Gosub DelayUs
Portb = %00100000
DelayV=2000-Duty
Gosub DelayUs
Next cycles
Next Duty
DelayV=1000
Gosub DelayUs
Goto Loop
;I will assume the minimum uSec pause is 4 (3 by the book)
DelayUs:
DelayV=DelayV/4
while DelayV !=0
Pauseus 4
If switch then
gosub StopEverything
ENDIF
DelayV=DelayV-1
WEND
return
StopEverything:
While switch ;wait untill switch is release
Wend
PAUSE 100 ; cheap debounce time
While switch=0 ;wait for switch press
Wend
return
what about now srig ?
regards
Last edited by mister_e; - 5th November 2004 at 00:22.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks