Device = 16F628A
XTAL
10
CMCON=7
ALL_DIGITAL true
Declare WATCHDOG 0
Output PORTB.0 'leds1
Output PORTB.1 'leds2
Output PORTB.2 'leds3
Output PORTB.3 'pwm leds
Input PORTA.0 'input low active
Symbol led1 =PORTB.0
Symbol led2 =PORTB.1
Symbol led3 =PORTB.2
Symbol pwmled =PORTB.3
Symbol inp =PORTA.0
led1 =0
led2 =0
led3 =0
pwmled =0
Dim duty As Byte
Dim
i As Byte
Dim
lck As Bit
Clear
DelayMS
100
GoTo oversub
Include "modedefs.bas"
step1:
For duty=0 To 255
HPWM 0,duty,2000
DelayMS 10
Next duty
led1=1
DelayMS 200
led2=1
DelayMS 200
led3=1
Return
step2:
For duty=255 To 0 Step -1
HPWM 0,duty,2000
DelayMS 10
Next duty
led1=0
led2=0
led3=0
Return
oversub:
While 1=1
If inp=0 Then
DelayMS
10
If inp=0 And lck=0 Then
lck=1
For duty=i To 250
DelayMS 10
If inp=1 Then Break
HPWM
0,duty,3000
Next duty
i=duty
led1=1
DelayMS 200
led2=1
DelayMS 200
led3=1
EndIf
EndIf
If
inp=1 Then
DelayMS
10
If inp=1 And lck=1 Then
lck=0
For duty=i To 1 Step - 1
DelayMS 10
If inp=0 Then Break
HPWM
0,duty,3000
Next duty
i=duty
HPWM 0,0,3000
led1=0
led2=0
led3=0
EndIf
EndIf
DelayMS
5
Wend