Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
elektronik:knight-rider-lauflicht-mit-dimm-effekt [08.12.2024 21:53] – angelegt Martin Fitzel | elektronik:knight-rider-lauflicht-mit-dimm-effekt [Unbekanntes Datum] (aktuell) – Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Knight Rider Lauflicht mit Dimm-Effekt ====== | ||
+ | <code bascomavr [enable_line_numbers=" | ||
+ | ' | ||
+ | 'LEDs werden per Software-PWM über Timer1 ausgedimmt. | ||
+ | ' | ||
+ | 'für STK500 | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | $regfile = " | ||
+ | $crystal = 8000000 | ||
+ | $hwstack = 32 | ||
+ | $swstack = 24 | ||
+ | $framesize = 16 | ||
+ | Ddrc = 255 | ||
+ | Portc = 255 | ||
+ | Dim A As Byte | ||
+ | Dim B As Byte | ||
+ | Dim Z As Byte | ||
+ | Dim X As Byte | ||
+ | Dim Zeit As Word | ||
+ | Dim Richtung As Bit | ||
+ | Dim Led(8) As Byte | ||
+ | Config Timer0 = Timer , Prescale = 64 | ||
+ | Enable Timer0 | ||
+ | Enable Interrupts | ||
+ | On Timer0 Timer0_interrupt | ||
+ | A = 1 | ||
+ | Portc = 0 | ||
+ | Waitms 200 | ||
+ | Do | ||
+ | ' | ||
+ | If Zeit > 50 Then | ||
+ | | ||
+ | If Richtung = 0 Then | ||
+ | A = A + 1 | ||
+ | If A = 8 Then | ||
+ | | ||
+ | End If | ||
+ | Else | ||
+ | A = A - 1 | ||
+ | If A = 1 Then | ||
+ | | ||
+ | End If | ||
+ | End If | ||
+ | Zeit = 1 | ||
+ | End If | ||
+ | Z = Z + 1 | ||
+ | 'Soft PWM | ||
+ | ' | ||
+ | For B = 1 To 8 | ||
+ | If Led(b) > Z Then | ||
+ | B = B - 1 | ||
+ | Portc.b = 0 | ||
+ | Else | ||
+ | B = B - 1 | ||
+ | Portc.b = 1 | ||
+ | End If | ||
+ | B = B + 1 | ||
+ | Next | ||
+ | Loop | ||
+ | End | ||
+ | ' | ||
+ | Timer0_interrupt: | ||
+ | Timer0 = 6 | ||
+ | ' Prescale = 64 + Timer0 = 6 = 500Hz | ||
+ | ' Bei LED-Startwert von 255 ist nach 0,51 Sekunden ausgedimmt | ||
+ | Zeit = Zeit + 1 | ||
+ | For X = 1 To 8 | ||
+ | If Led(x) > 0 Then | ||
+ | Led(x) = Led(x) - 1 ' | ||
+ | End If | ||
+ | Next | ||
+ | Return | ||
+ | </ | ||
+ | |||
+ | |||
+ | {{tag> |