Device = 18F1220
Clock = 8
Config OSC = INTIO2
Include "INTOSC8.bas"
Dim ledB As PORTB.7
Dim ledR As PORTB.6
Dim ledG As PORTB.5
Dim Duty As Word
// import PWM module...
Include "PW.bas"
Include "Utils.bas"
Output (ledB)
Output (ledR)
Output (ledG)
High (ledB)
High (ledR)
High (ledG)
// main program...
While true
If PWM.SetFreq(5000) Then
Low (ledB)
Duty = 0
Repeat
PWM.SetDutyPercent(Duty)
Inc(Duty)
DelayMS(10)
Until Duty > 100
Repeat
PWM.SetDutyPercent(Duty)
Dec(Duty)
DelayMS(10)
Until Duty = 0
High (ledB)
EndIf
If PWM.SetFreq(5000) Then
Low (ledR)
Duty = 0
Repeat
PWM.SetDutyPercent(Duty)
Inc(Duty)
DelayMS(10)
Until Duty > 100
Repeat
PWM.SetDutyPercent(Duty)
Dec(Duty)
DelayMS(10)
Until Duty = 0
High (ledR)
EndIf
If PWM.SetFreq(5000) Then
Low (ledG)
Duty = 0
Repeat
PWM.SetDutyPercent(Duty)
Inc(Duty)
DelayMS(10)
Until Duty > 100
Repeat
PWM.SetDutyPercent(Duty)
Dec(Duty)
DelayMS(10)
Until Duty = 0
High (ledG)
EndIf
Wend