kann sich bitte mal jemand den code anschauen was daran falsch ist
Code:
$regfile "m16def.dat" ' use the byte lib since we do not need longs
$crystal = 20000000
$baud = 19200
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'config
'I²C
Config I2cdelay = 5 '
Config Sda = Portc.1
Config Scl = Portc.0
'Display Setup
Config Lcdpin = Pin , Db4 = Porta.6 , Db5 = Porta.5 , Db6 = Porta.4 , Db7 = Porta.3 , E = Porta.7 , Rs = Porta.2 ' Natürlich so wie es wirklich angeschlossen ist (4-Bit-Modus)
Config Lcd = 20 * 4
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Subs
'Uhr
Declare Sub Gettime
Declare Sub Settime
'Speicher
Declare Sub Speichern
Declare Sub Write_eeprom(byval Dev As Byte , Byref Address As Word , Byval Wert_
As Byte)
Declare Sub Lösche
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Variablen und Konstanten
'Uhr
Dim S as byte, m as byte, h as byte ,d as byte
Dim Wm As Byte , Yd As Byte , Month As Byte
'Speicher
Const Ff = &H0D 'Steuerzeichen Formfeed
Const Lf = &H0A 'Steuerzeichen Linefeed
Const Pu = &H2E 'Punkt
Const Dp = &H3A 'Doppelpunkt
Const Le = &H20 'Leerzeichen
Const Ko = &H2C 'Komma
Const Adr = 162 'Adresse Eeprom
Dim Adrcount As Word 'Zähler Speicherplatz Eeprom
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dim Hi As Byte
Dim L As Byte
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Uhr Variablen setzen
S = 0
m = 0
h = 0
d = 1
Month = 1
Wm = 1
Yd = 1
ddrd = &B00010000
Cls
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Program start
Call Settime
Print Chr(27) ; "[2J"; 'clear screen
Print "PCF8583 Clock Sample"
Do
Call Gettime
Print Chr(27) ; "[2;2f";
Print Hex(h) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " Err:" ; Err
Wait 1
Loop
End
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'subs
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Settime
S = Makebcd(s) 'Sek
M = Makebcd(m) 'Min
H = Makebcd(h) 'Std
D = Makebcd(d) 'Tag
Month = Makebcd(month) 'Monat
'Setzen der vorgebenen Werte
I2cstart
I2cwbyte &HA0 'Schreibmodus
I2cwbyte 0 'select control register
I2cwbyte 8 'set year and day bit for masking
i2cstart
I2cwbyte &HA0 'Schreibmodus
I2cwbyte 2 'Sekundenregister auswählen
I2cwbyte S 'Sek schreiben
I2cwbyte M 'min schreiben
I2cwbyte H 'std schreiben
I2cwbyte D 'tag schreiben
I2cwbyte Month 'monat schreiben
i2cstop
End Sub Settime
Sub Gettime
'Aktuelle Werte auslesen
'---------------------- sekunden --------------------
i2cstart
I2cwbyte &HA0
i2cwbyte 2 'Sek register auswählen
i2cstart
I2cwbyte &HA1
i2crbyte s,nack 'lese sek
'---------------------- minuten --------------------
i2cstart
I2cwbyte &HA0
i2cwbyte 3 'min register auswählen
i2cstart
I2cwbyte &HA1
i2crbyte m,nack 'lese min
'---------------------- stunden --------------------
i2cstart
I2cwbyte &HA0
i2cwbyte 4 'Std register auswählen
i2cstart
I2cwbyte &HA1
i2crbyte h,nack 'lese std
'---------------------- tag --------------------
i2cstart
I2cwbyte &HA0
i2cwbyte 5 'tag register auswählen
i2cstart
I2cwbyte &HA1
i2crbyte yd,nack 'lese jahr und tag
'---------------------- wotag --------------------
i2cstart
I2cwbyte &HA0
i2cwbyte 6 'mon register auswählen
i2cstart
I2cwbyte &HA1
i2crbyte wm,nack 'lese wochentag und monat
i2cstop
End Sub Gettime
Sub Speichern
Hi =(high)adrcount
L=AdrCount
I2cstart
I2cwbyte Adr
I2cwbyte H 'Speicherstelle im Eeprom
I2cwbyte L
I2cwbyte D
I2cwbyte Pu
I2cwbyte Month
I2cwbyte Le
I2cwbyte S
I2cwbyte Dp
I2cwbyte M
I2cwbyte Le
I2cwbyte FF
I2cwbyte LF 'damit ist die Formatierung auch im Eeprom
I2cstop
End Sub Speichern
Lesezeichen