'============================================================
'
' ************************************
' *** ***
' *** Drehlicht 18.05.2014 ***
' *** ***
' ************************************
'
'name : Drehlicht.bas
'purpose : Drehlicht mit 4 LEDs
'µC : ATtiny13
'
'============================================================
'
$regfile = "attiny13.dat"
$crystal = 300000
$hwstack = 20
$swstack = 20
$framesize = 12
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
Config Portb.3 = Output
Led1_pin Alias Portb.0
Led2_pin Alias Portb.1
Led3_pin Alias Portb.2
Led4_pin Alias Portb.3
Const Fade_up = 3
Const Fade_down = 3
Const Hold = 3
Const Pause = 3
Dim Led1 As Byte
Dim Led2 As Byte
Dim Led3 As Byte
Dim Led4 As Byte
'Auflösung 0 - 49
Dim Timerzaehler As Byte 'Maximalwerte wie LED1
Config Timer0 = Timer , Prescale = 8 'Timer konfigurieren
On Timer0 Timerroutine 'Timerinterrupt Subroutine zuweisen
Enable Timer0 'Timer aktivieren
Start Timer0 'Timer starten
Timer0 = 205 'Timer vorladen
Enable Interrupts 'Interrupt aktivieren
Portb = 0
'*** Hauptschleife *************************************************************
Do
For Led1 = 0 To 49
If Led4 < 21 Then 'Werte begrenzen um Timerüberläufe abzufangen
If Led4 > 0 Then Decr Led4. 'Werte begrenzen um Timerüberläufe abzufangen, DED4 weiter abdimmen
End If
Waitms Fade_up 'aufdimmen
Next Led1
Waitms Hold 'halten
For Led1 = 49 To 20 Step -1 'abdimmen
Waitms Fade_down
Next Led1
Waitms Pause 'Pause
'======================================
For Led2 = 0 To 49
If Led1 < 21 Then
If Led1 > 0 Then Decr Led1.
End If
Waitms Fade_up
Next Led2
Waitms Hold
For Led2 = 49 To 20 Step -1
Waitms Fade_down
Next Led2
Waitms Pause
'======================================
For Led3 = 0 To 49
If Led2 < 21 Then
If Led2 > 0 Then Decr Led2.
End If
Waitms Fade_up
Next Led3
Waitms Hold
For Led3 = 49 To 20 Step -1
Waitms Fade_down
Next Led3
Waitms Pause
'======================================
For Led4 = 0 To 49
If Led3 < 21 Then
If Led3 > 0 Then Decr Led3.
End If
Waitms Fade_up
Next Led4
Waitms Hold
For Led4 = 49 To 20 Step -1
Waitms Fade_down
Next Led4
Waitms Pause
Loop
'Ende Hauptschleife
End
'*** Subs **********************************************************************
Timerroutine: 'Beginn Subroutine
Timer0 = 205
Incr Timerzaehler
If Timerzaehler = 49 Then Timerzaehler = 0 'Timerzaehler auf LED-Auflösung begrenzen
If Timerzaehler < Led1 Then Led1_pin = 1 Else Led1_pin = 0 'Vergleich Timerzähler mit LED-Wert -> LED Ein- od. Ausschalten
If Timerzaehler < Led2 Then Led2_pin = 1 Else Led2_pin = 0
If Timerzaehler < Led3 Then Led3_pin = 1 Else Led3_pin = 0
If Timerzaehler < Led4 Then Led4_pin = 1 Else Led4_pin = 0
Return