Hallo Roberto,
ich habe gerade ein kleines Programm zusammengebastelt.
Wenn Du einen Mega 8 µC hast, kannst Du das Programm 1 zu 1 übernehmen und ein bischen experimentieren.
Gruß
tooltime
Code:
' ---------[ Initialisierung ]--------
$regfile = "m8def.dat" ' Chip auswählen
$crystal = 1000000 ' Quarzfrequenz festlegen
Config Scl = Portc.5 ' I2C-Clock festlegen
Config Sda = Portc.4 ' I2C-Data festlegen
Config Lcdmode = Port
Config Lcdbus = 4
Config Lcdpin = Pin , Db4 = Portb.5 , Db5 = Portb.4 , Db6 = Portb.3 , Db7 = Portb.2 , E = Portb.1 , Rs = Portb.0
Config Lcd = 16 * 2 ' LCD-Typ festlegen
Cursor = Off ' Cursor ausschalten
Cls
Dim S As Byte , M As Byte , H As Byte , D As Byte , Month As Byte
Dim Wm As Byte , Yd As Byte
'-----[ Hauptprogramm ]----------------------------------------
Wm = 3
D = 8
Month = 2
Yd = 1
H = 22
M = 00
S = 00
Settime:
'values are stored as BCD values so convert the values first
S = Makebcd(s) 'seconds
M = Makebcd(m) 'minuts
H = Makebcd(h) 'hours
D = Makebcd(d) 'days
Month = Makebcd(month) 'months
Yd = Makebcd(yd) 'seconds
Wm = Makebcd(wm) 'minuts
I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte 0 'select control register
I2cwbyte 8 'set year and day bit for masking
I2cstop 'generate stop
I2cstart 'generate start
I2cwbyte &HA0 'write mode
I2cwbyte 2 'select seconds Register
I2cwbyte S 'write seconds
I2cwbyte M 'write minuts
I2cwbyte H 'write hours
I2cwbyte Yd 'write jear
I2cwbyte D 'write day
I2cwbyte Wm 'wirte weekday
I2cwbyte Month 'write month
I2cstop 'generate stop
Goto Gettime
Gettime:
I2cstart 'generate start
I2cwbyte &HA0 'write addres
I2cwbyte 2 'select second register
I2cstart 'generate repeated start
I2cwbyte &HA1 'write address for reading
I2crbyte S , Ack 'read seconds
I2crbyte M , Ack 'read minuts
I2crbyte H , Ack 'read hours
I2crbyte Yd , Ack 'read year
I2crbyte D , Ack 'read day
I2crbyte Wm , Ack 'read weekday
I2crbyte Month , Nack 'read month
I2cstop 'generate stop
Goto Zeit
Zeit:
S = Makedec(s)
M = Makedec(m)
H = Makedec(h)
Yd = Makedec(yd)
D = Makedec(d)
Wm = Makedec(wm)
Month = Makedec(month)
If H >= 10 Then
Locate 1 , 1 : Lcd H
Else
Locate 1 , 1 : Lcd " " ; H
End If
Locate 1 , 3 : Lcd ":"
If M >= 10 Then
Locate 1 , 4 : Lcd M
Else
Locate 1 , 4 : Lcd "0" ; M
End If
Locate 1 , 6 : Lcd ":"
If S >= 10 Then
Locate 1 , 7 : Lcd S
Else
Locate 1 , 7 : Lcd "0" ; S
End If
Locate 2 , 1 : Lcd D ; "." ; Month ; "." ; Yd ; " " ; Wm
Waitms 100
Goto Gettime
Lesezeichen