here is my code and my objective is to make all the LEDs turn on and off at the same time, but when a switch is pressed and let go, the PWM should pause, and when you press the switch again it should resume where it left off. I have tried to implement this on my program, I konw that the theory is valid, but the output is not working. any help or suggestions would be greatly appreciated.
here is where I have so far:
==============================================
include "modedefs.bas"
'Objective to turn LEDS on and off at the same time
Duty VAR Word
Cycle0 VAR BYTE
Cycle1 VAR BYTE
cycles VAR Word
Switch Var PORTC.6
TRISB = %00000000
TRISC = %01000000
DEFINE OSC 20
start:
Cycle1 = 2
Loop:
'sequence 1
For Duty = 0 to 2000 'ALL OFF ---> All ON
if(Switch = 0) then pause 100 'waiting for debounce to stop
if(Switch = 1) then Duty = Duty - 1 'now the pause to PWM appears when switch is high
For cycles = 0 to Cycle1
Portb = %00000000 Pauseus 2000 - Duty
Portb = %11110000
Pauseus Duty
Next cycles
Next Duty
Pause 1000
'sequence 0 (t = 1)
For Duty = 2000 to 0 step -1 'ALL ON--> ALL OFF
if(Switch = 0) then pause 100
if(Switch = 1) then Duty = Duty - 1
For cycles = 0 to Cycle1
Portb = %11110000 Pauseus Duty Portb = %00100000
Pauseus 2000 - Duty
Next cycles
Next Duty
Pause 1000
Goto Loop
Bookmarks