Oups forget the above.... damn
Code:
'Objective to turn LEDS on and off at the same time
DEFINE OSC 20
TRISB = %00000000
TRISC = %01000000
StopAll VAR bit
Duty VAR Word
Cycle0 VAR BYTE
Cycle1 VAR BYTE
cycles VAR Word
Switch Var PORTC.6
DelayV VAR BYTE
Cycle1 = 2
stopall = 0
Loop:
;sequence 1
;ALL OFF ---> All ON
;====================
cycles=0
for duty=0 to 2000
while cycles != Cycle1
Portb = %00000000
DelayV=2000-Duty
Gosub DelayUs
Portb = %11110000
DelayV=Duty
Gosub DelayUs
if stopall=0 then cycles = cycles +1
Wend
Next
DelayV=1000
Gosub DelayUs
;sequence 0 (t = 1)
;ALL ON--> ALL OFF
;===================
cycles=0
For duty=2000 to 0 step -1
while cycles != Cycle1
Portb = %11110000
DelayV=Duty
Gosub DelayUs
Portb = %00100000
DelayV=2000-Duty
Gosub DelayUs
if StopAll=0 then cycles = cycles + 1
wend
next
DelayV=1000
Gosub DelayUs
Goto Loop
;I assume 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 50 ; cheap debounce time
If stopall=0 then
stopall=1
else
stopall=0
endif
return
Better use this one... was missing my pillow when i post the one before...
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks