$regfile = "m128def.dat"
$crystal = 16000000
Config Lcd = 20 * 4a , Chipset = Ks077
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.3
Config Lcdbus = 4
'*******************************************************************************
Config Timer0 = Timer , Prescale = 64
Const Timervorgabe = 6
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Compare C Pwm = Clear Down , Prescale = 8
'Config Timer3 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Compare C Pwm = Clear Down , Prescale = 8
Cls
Dim Eramdummy As Eram Byte
Dim E_licht As Eram Byte , E_gruent As Eram Byte , E_rott As Eram Byte , E_blaut As Eram Byte , E_rotb As Eram Byte
Dim E_gruenb As Eram Byte , E_farbet As Eram Byte , E_farbeb As Eram Byte , E_blaub As Eram Byte
Dim Licht As Byte , Gruent As Byte , Rott As Byte , Blaut As Byte , Rotb As Byte , Blaub As Byte , Gruenb As Byte
Dim Farbet As Byte , Farbeb As Byte
Dim H As Byte , P As Byte , T As Byte , W As Word , Deca As Byte , Wtemp As Byte
Dim S As Bit
Initlcd
Wait 1
Cls
Cursor Off 'off Blink
Lcd "RS - RWM-RGB V0.1" '
'
'
Config Debounce = 10 '
Config Int0 = Falling 'Rising Falling
Config Int2 = Falling
Config Pind.0 = Input
Config Pind.1 = Input
Config Pind.2 = Input
Config Pinb.0 = Output
Config Pinb.5 = Output
Config Pinb.6 = Output
Config Pinb.7 = Output
Const Debouncetime = 3
On Int0 Decoder
On Int2 Dec_taste
On Timer0 T0isr
'Led2r Alias Ocr3a
'Led2g Alias Ocr3b
'Led2b Alias Ocr3c
Enable Interrupts
Enable Int0
Enable Int2
Enable Timer1
Enable Timer0
'Enable Timer3
'Start Timer3
Start Timer1
Portd.0 = 1
Portd.1 = 1
Portd.2 = 1
T = 1
H = 0
P = 0
Cls
Licht = E_licht
Rotb = E_rotb
Gruenb = E_gruenb
Blaub = E_blaub
Led1r Alias Ocr1a
Led1g Alias Ocr1b
Led1b Alias Ocr1c
Led1r = Rotb
Led1g = Gruenb
Led1b = Blaub
Locate 1 , 2 : Lcd "* * * Menue: * * *"
Locate 2 , 1 : Lcd " Probe V1.0 "
Wait 2
Gosub Menue
'--------------------------------HAUPTPROGRAMM---------------------------------
Do
Led1r = Rotb
Led1g = Gruenb
Led1b = Blaub
Loop
End
'--------------------------------Decoder Auswertung Rechts/Links----------------
Decoder:
If Pind.0 = 0 Then
If Pind.1 = 1 Then Gosub Rechts Else Gosub Links
End If
Return
'--------------------------------Decoder Auswertung Taste-----------------------
Dec_taste:
'If T = 2 And H = 0 Then
' Led1r = 255
'Led1g = 255
'Led1b = 255
' Incr T
'End If
If T < 3 Then
Incr T
End If
If T = 3 And H = 1 And P = 4 Then
Incr T
P = 1
End If
If T = 4 And H = 2 And P = 4 Then
Incr T
P = 1
H = 0
End If
If T = 5 And H = 3 And P = 5 Then
Incr T
P = 2
H = 0
End If
If T = 6 And H = 4 And P = 2 Then
T = 1
P = 0
H = 0
End If
If T = 6 And H = 4 And P = 4 Then
T = 7
P = 0
H = 0
End If
Gosub Menue
Gosub Punkt
Locate 4 , 1 : Lcd T
Locate 4 , 2 : Lcd H
Return
'--------------------------------Incrementiere----------------------------------
Rechts:
If Deca < 255 Then Incr Deca
If H = 0 And T = 2 And Licht < 30 Then
Incr Licht
Locate 3 , 14 : Lcd " "
Locate 3 , 14 : Lcd Licht
End If
If H = 1 Or H = 2 And P < 4 And Pind.2 = 1 Then
Incr P
End If
If H = 3 And P < 5 And Pind.2 = 1 Then
Incr P
If P = 3 Then P = 5
End If
If H = 4 And P < 4 And Pind.2 = 1 Then
Incr P
If P = 3 Then P = 4
End If
If H = 1 And Pind.2 = 0 Then
Select Case P
Case 1 And Rotb > 0
Decr Rotb
Locate 2 , 7 : Lcd " "
Locate 2 , 7 : Lcd Rotb
Case 2 And Blaub > 0
Decr Blaub
Locate 3 , 7 : Lcd " "
Locate 3 , 7 : Lcd Blaub
Case 3 And Gruenb > 0
Decr Gruenb
Locate 2 , 18 : Lcd " "
Locate 2 , 18 : Lcd Gruenb
End Select
End If
Locate 4 , 20 : Lcd P
Gosub Punkt
Return
'--------------------------------Decrementiere----------------------------------
Links:
If Deca > 0 Then Decr Deca
If H = 0 And T = 2 And Licht > 0 Then
Decr Licht
Locate 3 , 14 : Lcd " "
Locate 3 , 14 : Lcd Licht
End If
If H = 1 Or H = 2 And P > 1 And Pind.2 = 1 Then
Decr P
End If
If H = 3 And P > 1 And Pind.2 = 1 Then
Decr P
If P = 4 Then P = 2
End If
If H = 4 And P > 2 And Pind.2 = 1 Then
Decr P
If P = 3 Then P = 2
End If
If H = 1 And Pind.2 = 0 Then
Select Case P
Case 1 And Rotb < 255
Incr Rotb
Locate 2 , 7 : Lcd Rotb
Case 2 And Blaub < 255
Incr Blaub
Locate 3 , 7 : Lcd Blaub
Case 3 And Gruenb < 255
Incr Gruenb
Locate 2 , 18 : Lcd Gruenb
End Select
End If
Locate 4 , 20 : Lcd P
Gosub Punkt
Return
'----------------------------------LCD-Anzeige mit(*) Aktive Farbe--------------
Punkt:
If H > 0 Then
Select Case P
Case 1
Locate 2 , 1 : Lcd "*"
Locate 2 , 11 : Lcd " "
Locate 3 , 1 : Lcd " "
Locate 3 , 11 : Lcd " "
Case 2
Locate 2 , 1 : Lcd " "
Locate 2 , 11 : Lcd " "
Locate 3 , 1 : Lcd "*"
Locate 3 , 11 : Lcd " "
Case 3
Locate 2 , 1 : Lcd " "
Locate 2 , 11 : Lcd "*"
Locate 3 , 1 : Lcd " "
Locate 3 , 11 : Lcd " "
Case 4
Locate 2 , 1 : Lcd " "
Locate 2 , 11 : Lcd " "
Locate 3 , 1 : Lcd " "
Locate 3 , 11 : Lcd "*"
Case 5
Locate 2 , 1 : Lcd " "
Locate 2 , 11 : Lcd " "
Locate 3 , 1 : Lcd " "
Locate 3 , 11 : Lcd " "
Locate 4 , 1 : Lcd "*"
End Select
End If
Return
'----------------------------------MENÜ-----------------------------------------
Menue:
Locate 4 , 1 : Lcd T
Select Case T
Case 1
Cls
Locate 1 , 1 : Lcd "XXXXXXXXXXXXXXXXXXXX"
Locate 2 , 1 : Lcd "X V0.1 X"
Locate 3 , 1 : Lcd "X E X"
Locate 4 , 1 : Lcd "XXXXXXXXXXXXXXXXXXXX"
Case 2
Cls
Locate 1 , 1 : Lcd " NACHTLICHT"
Locate 2 , 1 : Lcd " Dauermax = 30sec"
Locate 3 , 1 : Lcd " Dauer/sec = " ; Licht
Case 3
H = 1
Cls
Locate 1 , 1 : Lcd "FARBE-BEDIENELEMENTE"
Locate 2 , 2 : Lcd "ROT> " ; Rotb
Locate 2 , 12 : Lcd "GRUEN>" ; Gruenb
Locate 3 , 2 : Lcd "BLAU>" ; Blaub
Locate 3 , 12 : Lcd "WEITER "
Case 4
H = 2
Cls
Locate 1 , 1 : Lcd " FARBE-TACHO "
Locate 2 , 2 : Lcd "ROT> " ; Rott
Locate 2 , 12 : Lcd "GRUEN>" ; Gruent
Locate 3 , 2 : Lcd "BLAU> " ; Blaut
Locate 3 , 12 : Lcd "WEITER"
Case 5
H = 3
Cls
Locate 1 , 1 : Lcd " DEFENIERTE FARBEN"
Locate 2 , 2 : Lcd "BEDIENELEMENTE " ; Farbeb
Locate 3 , 2 : Lcd "TACHO " ; Farbet
Locate 4 , 2 : Lcd "WEITER "
Case 6
H = 4
Cls
Locate 1 , 3 : Lcd "VOREISTELLUNGEN"
Locate 2 , 6 : Lcd " SPEICHERN"
Locate 3 , 12 : Lcd "JA "
Locate 3 , 2 : Lcd "NEIN"
Case 7
Cls
Locate 1 , 1 : Lcd "** EISTELLUNGEN **"
Locate 2 , 1 : Lcd "**** WERDEN ****"
Locate 3 , 1 : Lcd "** GESPEICHERT **"
Locate 4 , 1 : Lcd "********************"
T = 1
Gosub Eram_schreiben
End Select
Return
'----------------------DATEN-IN-EEPROM------------------------------------------
Eram_schreiben:
E_licht = Licht
Wait 2
Gosub Menue
Return
'-------------------------------------------------------------------------------------
Tacho_farbe:
Led1r = 0
Led1g = 0
Led1b = 0
Return
'-------------------------------------------------------------------------------
Bedien_farbe:
Led1r = Rotb
Led1g = Gruenb
Led1b = Blaub
Return
'Start Timer0
'Set Portb.0
T0isr:
Timer0 = Timervorgabe
Incr W
If W = 1000 Then
W = 0
Incr Wtemp
If Wtemp = Licht Then
Stop Timer0
Wtemp = 0
Reset Portb.0
End If
End If
Return