Device 16F628A
Config INTRC_OSC_NOCLKOUT, WDT_off, PWRTE_off, LVP_off, MCLRE_on
ALL_DIGITAL TRUE
PORTB_PULLUPS = On
'In en uitgangen
'Nixies en neons
Symbol klok = PORTA.1
Symbol ZetVast = PORTA.0
Symbol Data_Pin = PORTA.2
'Temperatuursensor en RTC
Symbol SDA = PORTB.4
Symbol SLC = PORTB.3
'Knoppen
Symbol KnopR = PORTB.7 : TRISB.7 = 1
Symbol KnopM = PORTB.6 : TRISB.6 = 1
Symbol KnopL = PORTB.5 : TRISB.5 = 1
'Variabelen declareren
Dim Teller As Byte
Dim Temp1 As Byte
Dim Temp2 As Byte
Dim BCD_Opt As Byte
Dim index As Byte
Dim Seconden As Byte
Dim Minuten As Byte
Dim Uren As Byte
Dim Datum As Byte
Dim Maand As Byte
Dim Jaar As Byte
Dim Temperatuur As Byte
Dim neon As Byte
Symbol Reg_Seconden = $00
Symbol Reg_Minuten = $01
Symbol Reg_Uren = $02
Symbol Reg_Dag = $03
Symbol Reg_Datum = $04
Symbol Reg_Maand = $05
Symbol Reg_Jaar = $06
Symbol Lezen = %11010001
Symbol Schrijven = %11010000
Clear
While 1 = 1
Tijd:
For index = 0 To 50
I2CIN SDA, SLC, Lezen, Reg_Uren, [Uren]
I2CIN SDA, SLC, Lezen, Reg_Minuten, [Minuten]
I2CIN SDA, SLC, Lezen, Reg_Seconden, [Seconden]
neon = %01111001
SHOut Data_Pin, klok, msbfirst, [neon \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Uren \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Minuten \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Seconden \ 8]
High ZetVast
DelayUS 20
Low ZetVast
If KnopR = 0 Or KnopM = 0 Or KnopL = 0 Then
GoSub TijdInst
EndIf
DelayMS 200
Next
Date:
For index = 0 To 10
I2CIN SDA, SLC, Lezen, Reg_Jaar, [Jaar]
I2CIN SDA, SLC, Lezen, Reg_Maand, [Maand]
I2CIN SDA, SLC, Lezen, Reg_Datum, [Datum]
neon = %01111010
SHOut Data_Pin, klok, msbfirst, [neon \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Datum \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Maand \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Jaar \ 8]
High ZetVast
DelayUS 20
Low ZetVast
If KnopR = 0 Or KnopM = 0 Or KnopL = 0 Then
GoSub DatumInst
EndIf
DelayMS 200
Next
Temp:
For index = 0 To 10
I2Cin SDA, SLC,$91,[Temperatuur]
Temp1 = Temperatuur / 10
Temp2 = (Temperatuur - (Temp1 * 10))
Temperatuur = Temp2
Temperatuur.7 = Temp1.3
Temperatuur.6 = Temp1.2
Temperatuur.5 = Temp1.1
Temperatuur.4 = Temp1.0
neon = %00100100
SHOut Data_Pin, klok, msbfirst, [neon \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [$FF \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Temperatuur \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [$FF \ 8]
High ZetVast
DelayUS 20
Low ZetVast
DelayMS 200
Next
Wend
TijdInst:
I2CIN SDA, SLC, Lezen, Reg_Uren, [Uren]
I2CIN SDA, SLC, Lezen, Reg_Minuten, [Minuten]
I2CIN SDA, SLC, Lezen, Reg_Seconden, [Seconden]
neon = %01111001
While 1 = 1
SHOut Data_Pin, klok, msbfirst, [neon \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Uren \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Minuten \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Seconden \ 8]
High ZetVast
DelayUS 20
Low ZetVast
DelayMS 200
Inc Teller
If KnopR = 0 Then
BCD_Opt = Seconden
GoSub bcd_tellen
Seconden = BCD_Opt
Teller = 0
EndIf
If KnopM = 0 Then
BCD_Opt = Minuten
GoSub bcd_tellen
Minuten = BCD_Opt
Teller = 0
EndIf
If KnopL = 0 Then
BCD_Opt = Uren
GoSub bcd_uur
Uren = BCD_Opt
Teller = 0
EndIf
DelayMS 250
If Teller = 12 Then Break
Wend
'Wegschrijven
I2COUT SDA, SLC, Schrijven ,Reg_Seconden, [Seconden]
I2COUT SDA, SLC, Schrijven ,Reg_Minuten, [Minuten]
I2COUT SDA, SLC, Schrijven ,Reg_Uren, [Uren]
Return
bcd_tellen:
Temp1 = BCD_Opt & %00001111 'Xor
Temp2 = BCD_Opt - Temp1
Temp2 = Temp2 >> 4
Inc Temp1
If Temp1 > 9 Then
Temp1 = 0
Inc Temp2
If Temp2 > 5 Then
Temp2 = 0
EndIf
EndIf
Temp2 = Temp2 << 4
BCD_Opt = Temp2 + Temp1
Return
bcd_uur:
Temp1 = BCD_Opt & %00001111 'Laagste bits doorlaten
Temp2 = BCD_Opt - Temp1
Temp2 = Temp2 >> 4
Inc Temp1
If Temp1 > 9 Then
Temp1 = 0
Inc Temp2
If Temp2 > 5 Then
Temp2 = 0
EndIf
EndIf
Temp2 = Temp2 << 4
BCD_Opt = Temp2 + Temp1
If BCD_Opt > 23 Then
BCD_Opt = 0
EndIf
Return
DatumInst:
I2CIN SDA, SLC, Lezen, Reg_Jaar, [Jaar]
I2CIN SDA, SLC, Lezen, Reg_Maand, [Maand]
I2CIN SDA, SLC, Lezen, Reg_Datum, [Datum]
neon = %01111010
While 1 = 1
SHOut Data_Pin, klok, msbfirst, [neon \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Datum \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Maand \ 8]
DelayUS 20
SHOut Data_Pin, klok, msbfirst, [Jaar \ 8]
High ZetVast
DelayUS 20
Low ZetVast
DelayMS 200
Inc Teller
If KnopR = 0 Then
BCD_Opt = Jaar
GoSub bcd_jaar
Jaar = BCD_Opt
Teller = 0
EndIf
If KnopM = 0 Then
BCD_Opt = Maand
GoSub bcd_Maand
Maand = BCD_Opt
Teller = 0
EndIf
If KnopL = 0 Then
BCD_Opt = Datum
GoSub bcd_Datum
Datum = BCD_Opt
Teller = 0
EndIf
DelayMS 250
If Teller = 12 Then Break
Wend
'Wegschrijven
I2COUT SDA, SLC, Schrijven ,Reg_Jaar, [Jaar]
I2COUT SDA, SLC, Schrijven ,Reg_Maand, [Maand]
I2COUT SDA, SLC, Schrijven ,Reg_Datum, [Datum]
Return
bcd_jaar:
Temp1 = BCD_Opt & %00001111 'Xor
Temp2 = BCD_Opt - Temp1
Temp2 = Temp2 >> 4
Inc Temp1
If Temp1 > 9 Then
Temp1 = 0
Inc Temp2
If Temp2 > 9 Then
Temp2 = 0
EndIf
EndIf
Temp2 = Temp2 << 4
BCD_Opt = Temp2 + Temp1
Return
bcd_Maand:
Temp1 = BCD_Opt & %00001111 'Laagste bits doorlaten
Temp2 = BCD_Opt - Temp1
Temp2 = Temp2 >> 4
Inc Temp1
If Temp1 > 9 Then
Temp1 = 0
Inc Temp2
EndIf
Temp2 = Temp2 << 4
BCD_Opt = Temp2 + Temp1
If BCD_Opt = $13 Then
BCD_Opt = 1
EndIf
If BCD_Opt = 0 Then
BCD_Opt = 1
EndIf
Return
bcd_Datum:
Temp1 = BCD_Opt & %00001111 'Laagste bits doorlaten
Temp2 = BCD_Opt - Temp1
Temp2 = Temp2 >> 4
Inc Temp1
If Temp1 > 9 Then
Temp1 = 0
Inc Temp2
EndIf
Temp2 = Temp2 << 4
BCD_Opt = Temp2 + Temp1
If BCD_Opt = $32 Then
BCD_Opt = 1
EndIf
If BCD_Opt = 0 Then
BCD_Opt = 1
EndIf
Return
End