Kod: Zaznacz cały
$regfile = "2313def.dat"
$crystal = 4000000
Config Portb = &B11111111
Portb = &B11111111
Config Portd = &B1111111
Portd = &B0000000
Config Timer1 = Pwm , Pwm = 10 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Disconnect 'Clear Up
Readeeprom Pwm1a , 0
Stop Timer1
Config Int1 = Falling
Declare Sub Nint
Declare Sub O1nint
Enable Int1
Enable Interrupts
On Int1 Nint
Stop Timer1
Toggle Portb.7
Idle
Do
If Pind.1 = 1 Then 'UP
If Pwm1a < 500 Then
Stop Timer1
Pwm1a = Pwm1a + 5
Start Timer1
Waitms 30
End If
End If
If Pind.0 = 1 Then 'down
If Pwm1a > 1 Then
Stop Timer1
Pwm1a = Pwm1a - 5
Start Timer1
Waitms 30
End If
End If
If Pind.4 = 1 Then '10%
Stop Timer1
Pwm1a = 151
Start Timer1
End If
If Pind.6 = 1 Then '100%
Stop Timer1
Pwm1a = 701
Start Timer1
End If
If Pind.3 = 1 Then 'sleep
Waitms 250
If Pind.3 = 1 Then
Call O1nint
End If
End If
Loop
Sub O1nint
Writeeeprom Pwm1a , 0
Toggle Portb.7
Stop Timer1
Wait 1
Enable Int1
Enable Interrupts
Idle
End Sub
Sub Nint
Toggle Portb.7
Waitms 250
Readeeprom Pwm1a , 0
Start Timer1
Disable Int1
Disable Interrupts
Waitms 500
End Sub