$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 8
$framesize = 24
' Pins konfigurieren
LED_01 Alias Portd.0 ' PWM-Ausgänge für LED (oder Treiber)
LED_02 Alias Portd.1
LED_03 Alias Portd.2
LED_04 Alias Portd.3
LED_05 Alias Portd.4
LED_06 Alias Portb.6
LED_07 Alias Portb.7
LED_08 Alias Portd.5
LED_09 Alias Portd.6
Config LED_01 = Output ' PWM-Ausgänge als Ausgang konfigurieren
Config LED_02 = Output
Config LED_03 = Output
Config LED_04 = Output
Config LED_05 = Output
Config LED_06 = Output
Config LED_07 = Output
Config LED_08 = Output
Config LED_09 = Output
Const PWMCount_Max = 63 ' PWM-Max-Wert (Auflösung)
Dim TmrCount as Byte ' Zähler für PWM-Aufrufe
Dim PWM_01 as Byte ' Werte für die 9 PWM-Kanäle
Dim PWM_02 as Byte
Dim PWM_03 as Byte
Dim PWM_04 as Byte
Dim PWM_05 as Byte
Dim PWM_06 as Byte
Dim PWM_07 as Byte
Dim PWM_08 as Byte
Dim PWM_09 as Byte
Dim AfterGlow as Byte ' Nachleuchtdauer Einstellwert (Max-Wert)
Dim _AfterGlow_Count as Byte ' Verzögerung Nachleuchteffekt (Zähler)
Dim Motion_Step as Byte
Dim Flags as Byte
Const fMotionChange = 6 ' Flag=1, dann Effekt-Bewegung
Dim tmpWord as Word
AfterGlow = 100 ' Hier Nachleuchtdauer einstellen (0..255)
Config ADC = Single , Prescaler = 32 , Reference = AVCC
Config Timer1 = Timer , Prescale = 1024 , Clear Timer = 1
Compare1A = 2000
Config Timer2 = Timer , Prescale = 8 , Clear Timer = 1
ocr2 = 156 - 1
On oc1a ISR_Timer1
On OC2 ISR_Timer2
Enable OC1A
Enable OC2
Enable Interrupts
' --------------------------------------------------------
' Hauptschleife
' --------------------------------------------------------
do
nop
if Flags.fMotionChange = 1 then ' Flag=1, dann Bewegungs-Routine aufrufen
Gosub _MotionSet_02 ' Aufruf der Bewegungs-Routine
Flags.fMotionChange = 0 ' Flag zieder auf NULL
tmpWord = GetADC(1) ' Nachleuchtdauer Einstellbar machen
shift tmpWord , right , 2
AfterGlow = low(tmpWord)
tmpWord = GetADC(0) ' Bewegungsgeschwindigkeit
tmpWord = tmpWord + 20
tmpWord = tmpWord * 8
Compare1A = tmpWord
End if
loop
End
ISR_Timer1:
Set Flags.fMotionChange ' Flag setzen, Effekt-Bewegung erforderlich
Return
' --------------------------------------------------------
' PWM-Routine
' --------------------------------------------------------
ISR_Timer2:
If TmrCount = 0 then
TmrCount = PWMCount_Max
Reset LED_01 ' wenn TmrCounter=0, dann Counter auf Max. setzen (PWMCount_Max)
Reset LED_02 ' und alle Ports ausschalten
Reset LED_03
Reset LED_04
Reset LED_05
Reset LED_06
Reset LED_07
Reset LED_08
Reset LED_09
Else ' Wenn TmrCounter>0
If PWM_01 = TmrCount then Set LED_01
If PWM_02 = TmrCount then Set LED_02
If PWM_03 = TmrCount then Set LED_03
If PWM_04 = TmrCount then Set LED_04
If PWM_05 = TmrCount then Set LED_05
If PWM_06 = TmrCount then Set LED_06
If PWM_07 = TmrCount then Set LED_07
If PWM_08 = TmrCount then Set LED_08
If PWM_09 = TmrCount then Set LED_09
Decr TmrCount
End If
If _AfterGlow_Count = 0 then ' Nachleucht-Routine
_AfterGlow_Count = AfterGlow
If PWM_01 > 0 then Decr PWM_01
If PWM_02 > 0 then Decr PWM_02
If PWM_03 > 0 then Decr PWM_03
If PWM_04 > 0 then Decr PWM_04
If PWM_05 > 0 then Decr PWM_05
If PWM_06 > 0 then Decr PWM_06
If PWM_07 > 0 then Decr PWM_07
If PWM_08 > 0 then Decr PWM_08
If PWM_09 > 0 then Decr PWM_09
Else
Decr _AfterGlow_Count
End If
Return
' --------------------------------------------------------
' Effekt-Routine
' --------------------------------------------------------
_MotionSet_02:
Select Case Motion_Step
Case 0
PWM_09 = PWMCount_Max
Case 1
PWM_08 = PWMCount_Max
Case 2
PWM_07 = PWMCount_Max
Case 3
PWM_06 = PWMCount_Max
Case 4
PWM_05 = PWMCount_Max
Case 5
PWM_04 = PWMCount_Max
Case 6
PWM_03 = PWMCount_Max
Case 7
PWM_02 = PWMCount_Max
Case 8
PWM_01 = PWMCount_Max
Case 9
PWM_02 = PWMCount_Max
Case 10
PWM_03 = PWMCount_Max
Case 11
PWM_04 = PWMCount_Max
Case 12
PWM_05 = PWMCount_Max
Case 13
PWM_06 = PWMCount_Max
Case 14
PWM_07 = PWMCount_Max
Case 15
PWM_08 = PWMCount_Max
End Select
incr Motion_Step
If Motion_Step > 15 then Motion_Step = 0
Return