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
;====================
duty=0
while duty !=2000
For cycles = 0 to Cycle1
Portb = %00000000
DelayV=2000-Duty
Gosub DelayUs
Portb = %11110000
DelayV=Duty
Gosub DelayUs
Next cycles
if StopAll=0 then duty=duty+1
Wend
DelayV=1000
Gosub DelayUs
;sequence 0 (t = 1)
;ALL ON--> ALL OFF
;===================
duty=2000
For Duty = 2000 to 0 step -1
For cycles = 0 to Cycle1
Portb = %11110000
DelayV=Duty
Gosub DelayUs
Portb = %00100000
DelayV=2000-Duty
Gosub DelayUs
Next cycles
if stopall=0 then duty=duty-1
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 50 ; cheap debounce time
If stopall=0 then
stopall=1
else
stopall=0
endif
return
now it's working... i hope
regards
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks