Device = 16F628A
Warnings False
Dead_Code_
Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_ON, MCLRE_OFF, BOREN_OFF, LVP_OFF, CPD_OFF, CP_OFF
Xtal = 4
All_Digital true
PortB_Pullups On
LCD_DTPin PORTB.4
LCD_DTPort PORTB
LCD_RSPin PORTB.2
LCD_ENPin PORTB.3
LCD_Interface = 4
LCD_Lines = 2
Symbol KN_Enter = PORTA.5
Symbol KN_Up = PORTB.0
Symbol KN_Down = PORTB.1
TRISA.5 = 1
TRISB.0 = 1
TRISB.1 = 1
Dim Buf_Enter As Byte
Dim Buf_Up As Byte
Dim Buf_Down As Byte
Symbol Led_Red = PORTA.0
Symbol Led_Yellow = PORTA.1
Symbol Led_Green = PORTA.4
TRISA.0 = 0
TRISA.1 = 0
TRISA.4 = 0
Symbol SDA = PORTA.3
Symbol SCL = PORTA.2
Dim Menu As Byte
Dim Mode As Bit
Dim Hour As Byte
Dim Minit As Byte
Dim Second As Byte
Dim KN_Delay As Byte
Dim KN_Rate As Byte
Dim Red_Hour As Byte
Dim Red_Minit As Byte
Dim Yellow_Hour As Byte
Dim Yellow_Minit As Byte
Dim Green_Hour As Byte
Dim Green_Minit As Byte
Dim Off_Hour As Byte
Dim Off_Minit As Byte
Dim Delay_Timer As Byte
Dim TempB1 As Byte
Dim TempB2 As Byte
Dim FormTemp0 As Byte
Dim FormTemp1 As Byte
Dim FormTemp2 As Byte
TempB1 = ERead 0
If TempB1 <> 127 Then
EWrite 0,[127]
EWrite 1,[128]
EWrite 2,[50]
EWrite 10,[7]
EWrite 11,[0]
EWrite 12,[7]
EWrite 13,[30]
EWrite 14,[8]
EWrite 15,[0]
EWrite 16,[9]
EWrite 17,[30]
EndIf
KN_Delay = ERead 1
KN_Rate = ERead 2
Red_Hour = ERead 10
Red_Minit = ERead 11
Yellow_Hour = ERead 12
Yellow_Minit = ERead 13
Green_Hour = ERead 14
Green_Minit = ERead 15
Off_Hour = ERead 16
Off_Minit = ERead 17
DelayMS 500
Print At 1,1,"Stoplicht Timer!"
Print At 2,1," V1.0 "
DelayMS 1000
Cls
Led_Red = 1
Led_Yellow = 1
Led_Green = 1
Main_Loop:
If Delay_Timer = 0 Then GoSub Display_Time
Inc Delay_Timer
DelayMS 1
GoSub Knoppen
GoTo Main_Loop
Knoppen:
Button KN_Enter,0,KN_Delay,KN_Rate,Buf_Enter,0,No_Enter
If Menu > 0 And Mode = 0 Then
Mode = 1
Else
Mode = 0
EndIf
Cls : GoSub Display_Menu
No_Enter:
Button KN_Up,0,KN_Delay,KN_Rate,Buf_Up,0,No_Up
If Mode = 0 Then Inc Menu
If Menu = 13 Then Menu = 0
If Mode = 1 Then
If Menu = 1 And Hour < 23 Then Inc Hour
If Menu = 2 And Minit < 59 Then Inc Minit
If Menu = 3 And Red_Hour < 23 Then Inc Red_Hour
If Menu = 4 And Red_Minit < 59 Then Inc Red_Minit
If Menu = 5 And Yellow_Hour < 23 Then Inc Yellow_Hour
If Menu = 6 And Yellow_Minit < 59 Then Inc Yellow_Minit
If Menu = 7 And Green_Hour < 23 Then Inc Green_Hour
If Menu = 8 And Green_Minit < 59 Then Inc Green_Minit
If Menu = 9 And Off_Hour < 23 Then Inc Off_Hour
If Menu = 10 And Off_Minit < 59 Then Inc Off_Minit
If Menu = 11 Then Inc KN_Delay
If Menu = 12 Then Inc KN_Rate
EndIf
Cls : GoSub Display_Menu
No_Up:
Button KN_Down,0,KN_Delay,KN_Rate,Buf_Down,0,No_Down
If Mode = 0 And Menu > 0 Then Dec Menu
If Menu = 0 Then Cls : GoSub Display_Time
If Mode = 1 Then
If Menu = 1 And Hour > 0 Then Dec Hour
If Menu = 2 And Minit > 0 Then Dec Minit
If Menu = 3 And Red_Hour > 0 Then Dec Red_Hour
If Menu = 4 And Red_Minit > 0 Then Dec Red_Minit
If Menu = 5 And Yellow_Hour > 0 Then Dec Yellow_Hour
If Menu = 6 And Yellow_Minit > 0 Then Dec Yellow_Minit
If Menu = 7 And Green_Hour > 0 Then Dec Green_Hour
If Menu = 8 And Green_Minit > 0 Then Dec Green_Minit
If Menu = 9 And Off_Hour > 0 Then Dec Off_Hour
If Menu = 10 And Off_Minit > 0 Then Dec Off_Minit
If Menu = 11 Then Dec KN_Delay
If Menu = 12 Then Dec KN_Rate
EndIf
Cls : GoSub Display_Menu
No_Down:
Return
Display_Time:
If Menu = 0 Then
I2CIn SDA,SCL,%10100001,3,[FormTemp0]
GoSub Hex2Dec : Minit = FormTemp0
I2CIn SDA,SCL,%10100001,4,[FormTemp0]
GoSub Hex2Dec : Hour = FormTemp0
Print At 1,1,"Tijd: ", Dec2 Hour,":",Dec2 Minit
EndIf
If Hour = Red_Hour And Minit = Red_Minit Then Low Led_Red : High Led_Yellow : High Led_Green
If Hour = Yellow_Hour And Minit = Yellow_Minit Then Low Led_Yellow : High Led_Red : High Led_Green
If Hour = Green_Hour And Minit = Green_Minit Then Low Led_Green : High Led_Yellow : High Led_Red
If Hour = Off_Hour And Minit = Off_Minit Then High Led_Green : High Led_Yellow : High Led_Red
Return
Hex2Dec:
If FormTemp0 > 15 Then
FormTemp1 = FormTemp0 / 16
FormTemp2 = FormTemp0 - (FormTemp1 * 16)
FormTemp0 = (FormTemp1 * 10) + FormTemp2
EndIf
Return
Dec2Hex:
If FormTemp0 > 9 Then
FormTemp1 = FormTemp0 / 10
FormTemp2 = FormTemp0 - (FormTemp1 * 10)
FormTemp0 = (FormTemp1 * 16) + FormTemp2
EndIf
Return
Display_Menu:
Cls
If Menu = 1 Then Print At 1,1,"Tijd Uren?"
If Menu = 2 Then Print At 1,1,"Tijd Minuten?"
If Menu = 3 Then Print At 1,1,"Licht Rood Uur?"
If Menu = 4 Then Print At 1,1,"Licht Rood Min.?"
If Menu = 5 Then Print At 1,1,"Licht Geel Uur?"
If Menu = 6 Then Print At 1,1,"Licht Geel Min.?"
If Menu = 7 Then Print At 1,1,"Licht Groen Uur?"
If Menu = 8 Then Print At 1,1,"Licht Groen Min.?"
If Menu = 9 Then Print At 1,1,"Licht UIT Uur?"
If Menu = 10 Then Print At 1,1,"Licht UIT Min.?"
If Menu = 11 Then Print At 1,1,"Keyb. Delay ?"
If Menu = 12 Then Print At 1,1,"Keyb. Rate ?"
If Mode = 1 Then
Print At 2,1,"Waarde: "
If Menu = 1 Then
Print At 2,9,Dec2 Hour
FormTemp0 = Hour : GoSub Dec2Hex : I2COut SDA,SCL,%10100000,4,[FormTemp0]
Else If Menu = 2 Then
Print At 2,9,Dec2 Minit
FormTemp0 = Minit : GoSub Dec2Hex : I2COut SDA,SCL,%10100000,3,[FormTemp0]
Else If Menu = 3 Then
Print At 2,9,Dec2 Red_Hour : EWrite 10,[Red_Hour]
Else If Menu = 4 Then
Print At 2,9,Dec2 Red_Minit : EWrite 11,[Red_Minit]
Else If Menu = 5 Then
Print At 2,9,Dec2 Yellow_Hour : EWrite 12,[Yellow_Hour]
Else If Menu = 6 Then
Print At 2,9,Dec2 Yellow_Minit : EWrite 13,[Yellow_Minit]
Else If Menu = 7 Then
Print At 2,9,Dec2 Green_Hour : EWrite 14,[Green_Hour]
Else If Menu = 8 Then
Print At 2,9,Dec2 Green_Minit : EWrite 15,[Green_Minit]
Else If Menu = 9 Then
Print At 2,9,Dec2 Off_Hour : EWrite 16,[Off_Hour]
Else If Menu = 10 Then
Print At 2,9,Dec2 Off_Minit : EWrite 17,[Off_Minit]
Else If Menu = 11 Then
Print At 2,9,Dec2 KN_Delay : EWrite 1,[KN_Delay]
Else If Menu = 12 Then
Print At 2,9,Dec2 KN_Rate : EWrite 2,[KN_Rate]
EndIf
Else
If Menu > 0 Then Print At 2,1,"Menu: ",Dec2 Menu
EndIf
Return