Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| elektronik:drehlicht-mit-dimm-effekt-soft-pwm [22.07.2025 12:09] – angelegt Martin Fitzel | elektronik:drehlicht-mit-dimm-effekt-soft-pwm [Unbekanntes Datum] (aktuell) – Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | <code bascomavr [enable_line_numbers=" | ||
| + | ' | ||
| + | ' | ||
| + | ' ************************************ | ||
| + | ' *** *** | ||
| + | ' *** Drehlicht | ||
| + | ' *** *** | ||
| + | ' ************************************ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | |||
| + | $regfile = " | ||
| + | $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 | ||
| + | ' | ||
| + | Dim Timerzaehler As Byte ' | ||
| + | |||
| + | |||
| + | Config Timer0 = Timer , Prescale = 8 'Timer konfigurieren | ||
| + | On Timer0 Timerroutine | ||
| + | Enable Timer0 | ||
| + | Start Timer0 | ||
| + | Timer0 = 205 'Timer vorladen | ||
| + | |||
| + | Enable Interrupts | ||
| + | Portb = 0 | ||
| + | |||
| + | '*** Hauptschleife ************************************************************* | ||
| + | |||
| + | Do | ||
| + | |||
| + | |||
| + | For Led1 = 0 To 49 | ||
| + | If Led4 < 21 Then ' | ||
| + | If Led4 > 0 Then Decr Led4. 'Werte begrenzen um Timerüberläufe abzufangen, DED4 weiter abdimmen | ||
| + | End If | ||
| + | Waitms Fade_up | ||
| + | Next Led1 | ||
| + | |||
| + | | ||
| + | |||
| + | For Led1 = 49 To 20 Step -1 ' | ||
| + | Waitms Fade_down | ||
| + | Next Led1 | ||
| + | | ||
| + | ' | ||
| + | For Led2 = 0 To 49 | ||
| + | If Led1 < 21 Then | ||
| + | If Led1 > 0 Then Decr Led1. | ||
| + | End If | ||
| + | Waitms Fade_up | ||
| + | Next Led2 | ||
| + | |||
| + | | ||
| + | |||
| + | For Led2 = 49 To 20 Step -1 | ||
| + | Waitms Fade_down | ||
| + | Next Led2 | ||
| + | | ||
| + | ' | ||
| + | For Led3 = 0 To 49 | ||
| + | If Led2 < 21 Then | ||
| + | If Led2 > 0 Then Decr Led2. | ||
| + | End If | ||
| + | Waitms Fade_up | ||
| + | Next Led3 | ||
| + | |||
| + | | ||
| + | |||
| + | For Led3 = 49 To 20 Step -1 | ||
| + | Waitms Fade_down | ||
| + | Next Led3 | ||
| + | | ||
| + | ' | ||
| + | For Led4 = 0 To 49 | ||
| + | If Led3 < 21 Then | ||
| + | If Led3 > 0 Then Decr Led3. | ||
| + | End If | ||
| + | Waitms Fade_up | ||
| + | Next Led4 | ||
| + | |||
| + | | ||
| + | |||
| + | For Led4 = 49 To 20 Step -1 | ||
| + | Waitms Fade_down | ||
| + | Next Led4 | ||
| + | | ||
| + | |||
| + | |||
| + | |||
| + | Loop | ||
| + | |||
| + | ' | ||
| + | End | ||
| + | |||
| + | |||
| + | '*** Subs ********************************************************************** | ||
| + | Timerroutine: | ||
| + | | ||
| + | Incr Timerzaehler | ||
| + | If Timerzaehler = 49 Then Timerzaehler = 0 ' | ||
| + | If Timerzaehler < Led1 Then Led1_pin = 1 Else Led1_pin = 0 ' | ||
| + | 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 | ||
| + | |||
| + | </ | ||