$regfile "m8def.dat"
$crystal = 1000000
Config Scl = Portc.5 'Is serial
clock SCL
Config Sda = Portc.4 'Is serial
data SDA
Declare Sub Ausgabedaten()
Declare Sub Uhr_stellen()
Declare Sub Ausgabe(byval N As Byte)
Declare Sub Randanzeige()
Config Portb = Output
Dat Alias Portb
Config Portc.0 = Output
A0 Alias Portc.0
Config Portc.1 = Output
A1 Alias Portc.1
Config Portc.2 = Output
A2 Alias Portc.2
Config Portc.3 = Output
A3 Alias Portc.3
Config Portd.2 = Output
A4 Alias Portd.2
Config Portd.3 = Output
A5 Alias Portd.3
Config Portd.4 = Output
A6 Alias Portd.4
Config Portd.5 = Output
A7 Alias Portd.5
Config Portd.6 = Output
A8 Alias Portd.6
Config Portd.0 = Input
Portd.0 = 1
Key1 Alias Pind.0
Config Portd.1 = Input
Portd.1 = 1
Key2 Alias Pind.1
Dim Minute As Byte , Stunde As Byte , Hstring As String * 10
Dim Daten(10) As Byte , I As Byte , Count As Word
Stunde = 0
Minute = 0
Do
'RTC auslesen
I2cstart
I2cwbyte &HD0
I2cwbyte 0
I2cstart
I2cwbyte &HD1
I2crbyte I , Ack
I2crbyte Minute , Ack
I2crbyte Stunde , Nack
I2cstop
Call Ausgabedaten
Call Ausgabe(50)
Call Randanzeige
'Uhr stellen
If Key1 = 0 Then Call Uhr_stellen()
If Key2 = 0 Then Call Uhr_stellen()
Loop
Sub Uhr_stellen()
Count = 0
While Count < 100
Call Ausgabedaten
Call Ausgabe(50)
Call Randanzeige
Hstring = Hex(minute)
Minute = Val(hstring)
Hstring = Hex(stunde)
Stunde = Val(hstring)
If Key1 = 0 Then Gosub Incmin
If Key2 = 0 Then Gosub Incstd
Waitms 100
Hstring = "0" + Str(minute)
Hstring = Right(hstring , 2)
Hstring = "&H" + Hstring
Minute = Hexval(hstring)
Hstring = "0" + Str(stunde)
Hstring = Right(hstring , 2)
Hstring = "&H" + Hstring
Stunde = Hexval(hstring)
Incr Count
Wend
I2cstart
I2cwbyte &HD0
I2cwbyte 0
I2cwbyte &H00 'Sekunde
I2cwbyte Minute 'Minute
I2cwbyte Stunde 'Stunde
'I2cwbyte 1 'Wochentag
'I2cwbyte &H25 'Tag
'I2cwbyte &H01 'Monat
'I2cwbyte &H11 'Jahr
'I2cwbyte 0
I2cstop
End Sub
Incmin:
Incr Minute
If Minute > 59 Then Minute = 0
Count = 0
Return
Incstd:
Incr Stunde
If Stunde > 11 Then Stunde = 0
Count = 0
Return
'Matrixausgabe
Sub Ausgabe(byval N As Byte)
For I = 1 To N
A0 = 0 : Dat = Daten(1) : A0 = 1 : Dat = 0
A1 = 0 : Dat = Daten(2) : A1 = 1 : Dat = 0
A2 = 0 : Dat = Daten(3) : A2 = 1 : Dat = 0
A3 = 0 : Dat = Daten(4) : A3 = 1 : Dat = 0
A4 = 0 : Dat = Daten(5) : A4 = 1 : Dat = 0
A5 = 0 : Dat = Daten(6) : A5 = 1 : Dat = 0
A6 = 0 : Dat = Daten(7) : A6 = 1 : Dat = 0
A7 = 0 : Dat = Daten(8) : A7 = 1 : Dat = 0
A8 = 0 : Dat = Daten(9) : A8 = 1 : Dat = 0
Next
End Sub
' Randanzeige
Sub Randanzeige()
A0 = 0 : Dat = 16 : A0 = 1 : Dat = 0
A1 = 0 : Dat = 66 : A1 = 1 : Dat = 0
A2 = 0 : Dat = 8 : A2 = 1 : Dat = 0
A3 = 0 : Dat = 33 : A3 = 1 : Dat = 0
A4 = 0 : Dat = 132 : A4 = 1 : Dat = 0
A5 = 0 : Dat = 16 : A5 = 1 : Dat = 0
A6 = 0 : Dat = 66 : A6 = 1 : Dat = 0
A7 = 0 : Dat = 152 : A7 = 1 : Dat = 0
A8 = 0 : Dat = 36 : A8 = 1 : Dat = 0
End Sub
'Ausgabedaten ermitteln
Sub Ausgabedaten()
'Daten leeren
For I = 1 To 9
Daten(i) = 0
Next
Select Case Minute
Case &H00 : Daten(8) = 8
Case &H01 : Daten(1) = 1
Case &H02 : Daten(1) = 2
Case &H03 : Daten(1) = 4
Case &H04 : Daten(1) = 8
Case &H05 : Daten(1) = 16
Case &H06 : Daten(1) = 32
Case &H07 : Daten(1) = 64
Case &H08 : Daten(1) = 128
Case &H09 : Daten(2) = 1
Case &H10 : Daten(2) = 2
Case &H11 : Daten(2) = 4
Case &H12 : Daten(2) = 8
Case &H13 : Daten(2) = 16
Case &H14 : Daten(2) = 32
Case &H15 : Daten(2) = 64
Case &H16 : Daten(2) = 128
Case &H17 : Daten(3) = 1
Case &H18 : Daten(3) = 2
Case &H19 : Daten(3) = 4
Case &H20 : Daten(3) = 8
Case &H21 : Daten(3) = 16
Case &H22 : Daten(3) = 32
Case &H23 : Daten(3) = 64
Case &H24 : Daten(3) = 128
Case &H25 : Daten(4) = 1
Case &H26 : Daten(4) = 2
Case &H27 : Daten(4) = 4
Case &H28 : Daten(4) = 8
Case &H29 : Daten(4) = 16
Case &H30 : Daten(4) = 32
Case &H31 : Daten(4) = 64
Case &H32 : Daten(4) = 128
Case &H33 : Daten(5) = 1
Case &H34 : Daten(5) = 2
Case &H35 : Daten(5) = 4
Case &H36 : Daten(5) = 8
Case &H37 : Daten(5) = 16
Case &H38 : Daten(5) = 32
Case &H39 : Daten(5) = 64
Case &H40 : Daten(5) = 128
Case &H41 : Daten(6) = 1
Case &H42 : Daten(6) = 2
Case &H43 : Daten(6) = 4
Case &H44 : Daten(6) = 8
Case &H45 : Daten(6) = 16
Case &H46 : Daten(6) = 32
Case &H47 : Daten(6) = 64
Case &H48 : Daten(6) = 128
Case &H49 : Daten(7) = 1
Case &H50 : Daten(7) = 2
Case &H51 : Daten(7) = 4
Case &H52 : Daten(7) = 8
Case &H53 : Daten(7) = 16
Case &H54 : Daten(7) = 32
Case &H55 : Daten(7) = 64
Case &H56 : Daten(7) = 128
Case &H57 : Daten(8) = 1
Case &H58 : Daten(8) = 2
Case &H59 : Daten(8) = 4
End Select
Select Case Stunde
Case &H00 : Daten(8) = Daten(8) + 128
Case &H01 : Daten(9) = 1
Case &H02 : Daten(9) = 2
Case &H03 : Daten(9) = 4
Case &H04 : Daten(9) = 8
Case &H05 : Daten(9) = 16
Case &H06 : Daten(9) = 32
Case &H07 : Daten(9) = 64
Case &H08 : Daten(9) = 128
Case &H09 : Daten(8) = Daten(8) + 16
Case &H10 : Daten(8) = Daten(8) + 32
Case &H11 : Daten(8) = Daten(8) + 64
Case &H12 : Daten(8) = Daten(8) + 128
Case &H13 : Daten(9) = 1
Case &H14 : Daten(9) = 2
Case &H15 : Daten(9) = 4
Case &H16 : Daten(9) = 8
Case &H17 : Daten(9) = 16
Case &H18 : Daten(9) = 32
Case &H19 : Daten(9) = 64
Case &H20 : Daten(9) = 128
Case &H21 : Daten(8) = Daten(8) + 16
Case &H22 : Daten(8) = Daten(8) + 32
Case &H23 : Daten(8) = Daten(8) + 64
End Select
End Sub |