PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Adressierung die X'te



Xeus
18.10.2005, 07:55
Hallo,
ich benutze in meiner schaltung einen 24C256 von atmel.

in diesem eeprom will ich tabellarisch datum;uhrzei;var x;var y abspeichern.

an a0 meines eeproms liegt +5V und an A1 GND an. nun wollte ich fragen welche slaveadresse das eeprom hat und welche high und low adresse. ich habs schon versucht, aber anscheinend stimmt meines nicht.

gruß

xeus

Xeus
18.10.2005, 08:14
Hier ist mein code, aber der funzt nicht, ich krieg immer nur 255 zurück



$regfile "m16def.dat" ' use the byte lib since we do not need longs
$crystal = 20000000
$baud = 19200
'declare used subs



Declare Sub Settime
Declare Sub Gettime()
Declare Sub Schreibe
Declare Sub Lese

'Declare variables
Dim Tm(5) As Byte At &H60
Dim I As Byte , Temp As Byte

'These are pointers to tm() for simple handling.
Dim S As Byte At &H60 Overlay
Dim M As Byte At &H61 Overlay
Dim H1 As Byte At &H62 Overlay
Dim D As Byte At &H63 Overlay
Dim Month As Byte At &H64 Overlay
Dim Uhr(5) As Byte
Dim Adrcount As Word
Const Ff = &H0C
Const Lf = &H0A
Const Pu = &H2E
Const Dp = &H3A
Const Le = &H20
Const Ko = &H2C
Const Adr = &HA0
'Time Setup
Dim A As Byte

Dim Tag As Byte
Dim Monat As Byte
Dim Stunde As Byte
Dim Minute As Byte
Dim X As Byte
'configure the used port pin for I2C
Config I2cdelay = 5 ' default slow mode
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
Cls
Lcd "test"
' not needed since the pins are in the right state
'I2cinit
Print Chr(27) ; "[2J"; 'clear screen
Print "PCF8583 Clock Sample"
Do
Call Gettime
'since the values are stored in BCD format we can use Hex() to display them
Print Chr(27) ; "[2;2f"; ' VT100 emulation set pos to 2,2
Print Hex(h1) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " Err:" ; Err
Wait 1


If Pind.2 = 1 Then

Print "Schreibe"
Call Schreibe
Print "Schreiben beendet ERR" ; Err

End If

If Pind.4 = 1 Then

Print "Lese"
Call Lese
Lcd Str(x)
Print "Lesen beendet ERR" ; Err

End If

Loop





Sub Gettime()
'there are 2 ways to get the time. With low level i2c calls or with a high level call
'first the high level call
Tm(1) = 2 ' point to second register

I2creceive &HA0 , Tm(1) , 1 , 5 ' write the second address and get 5 bytes back
End Sub


Sub Settime '
'values are stored as BCD values so convert the values first
Inputbin Uhr(1) , 5

Tm(1) = Makebcd(s) 'seconds
Tm(2) = Makebcd(m) 'minutes
Tm(3) = Makebcd(h1) 'hours
Tm(4) = Makebcd(d) 'days
Tm(5) = Makebcd(month) 'months
I2cinit
I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte &H00 'select control register
I2cwbyte &H08 'set year and day bit for masking
I2cstart 'repeated start
I2cwbyte &HA0 'write mode
I2cwbyte 2 'select seconds Register
For I = 1 To 5
I2cwbyte Tm(i)
Next 'write seconds
I2cstop
End Sub

Sub Schreibe(byval Adressh As Byte , Adressl As Byte)
Call Gettime
Tag = Makebcd(tm(4))
Monat = Makebcd(tm(5))
Minute = Makebcd(tm(2))
Stunde = Makebcd(tm(3))

I2cinit
I2cstart
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cwbyte D 'Tag
I2cwbyte Pu
I2cwbyte Month 'Monat
I2cwbyte Le
I2cwbyte H1 'Stunde
I2cwbyte Dp
I2cwbyte M 'Minute
I2cwbyte Dp 'WStatus (2.Paketbyte)
I2cwbyte Ff 'Cursor zurück auf Anfang
I2cwbyte Lf 'und Zeilenvorschub
I2cstop

End Sub

Sub Lese
I2cinit
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cstart
I2cwbyte &HA3
I2crbyte X , Nack
I2cstop
End Sub


End

Michael
18.10.2005, 08:46
Hallo Xeus,

an a0 meines eeproms liegt +5V und an A1 GND an.
was liegt an A2?


I2cwbyte &HA0 'write address
Hier sprichst du den EEprom an, als ob alle Adressen auf GND liegen?

Gruß, Michael

Xeus
18.10.2005, 08:53
also, lesen und löschen funzt schon ganz gut, aber das mit dem schreiben will einfach nicht funktionieren.



S1 = 111
I2cinit
I2cstart
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cwbyte S1
'und Zeilenvorschub
I2cstop

End Sub

Xeus
18.10.2005, 08:54
ich hab bei meinem eeprom keinen a2

Michael
18.10.2005, 09:10
Hallo Xeus,

ich hab bei meinem eeprom keinen a2
Was ist mit Pin3?


aber das mit dem schreiben will einfach nicht funktionieren.
ahh, sehe gerade, daß du noch einen Clock-Baustein dranhängen hast.
Du solltest zum Lesen das entsprechende R/W Bit auch auf 1 setzen.

Gruß, Michael

Xeus
18.10.2005, 09:13
Also
im datenblatt steht bei pin 3 'NC' (not connect)

der rtc funktioniert wunderbar lesen und auch schreiben.

beim eeprom klapt das lesen und das löschen, nur das schreiben haut nicht hin

Xeus
18.10.2005, 09:16
Hier der komplette code:


$regfile "m16def.dat" ' use the byte lib since we do not need longs
$crystal = 20000000
$baud = 19200
'declare used subs



Declare Sub Settime
Declare Sub Gettime()
Declare Sub Schreibe
Declare Sub Lese
Declare Sub Löschen

'Declare variables
Dim Tm(5) As Byte At &H60
Dim I As Byte , Temp As Byte

'These are pointers to tm() for simple handling.
Dim S As Byte At &H60 Overlay
Dim M As Byte At &H61 Overlay
Dim H1 As Byte At &H62 Overlay
Dim D As Byte At &H63 Overlay
Dim Month As Byte At &H64 Overlay
Dim X As Byte
Dim Adrcount As Word
Const Ff = &H0C
Const Lf = &H0A
Const Pu = &H2E
Const Dp = &H3A
Const Le = &H20
Const Ko = &H2C
Const Adr = &HA0
'Time Setup
Dim A As Byte
Dim S1 As Byte
Dim Tag As Byte
Dim Monat As Byte
Dim Stunde As Byte
Dim Minute As Byte

Dim B As Word
Dim C As Integer

'configure the used port pin for I2C
Config I2cdelay = 5 ' default slow mode
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
Cls
Lcd "test"
' not needed since the pins are in the right state
'I2cinit
Print Chr(27) ; "[2J"; 'clear screen
Print "PCF8583 Clock Sample"
Do
Call Gettime
'since the values are stored in BCD format we can use Hex() to display them
Print Chr(27) ; "[2;2f"; ' VT100 emulation set pos to 2,2
Print Hex(h1) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " Err:" ; Err
Wait 1


If Pind.2 = 1 Then
Cls
Print "Schreibe"
Locate 1 , 1
Lcd "Schreibe"
Call Schreibe
Print "Schreiben beendet ERR" ; Err
Locate 2 , 1
Lcd "Schreiben beendet ERR" ; Err

End If

If Pind.4 = 1 Then
Cls
Print "Lese"
Locate 1 , 1
Lcd "Lese"
Call Lese
Locate 2 , 1
Lcd Str(x)
Locate 3 , 1
Lcd "Lesen beendet ERR" ; Err
Print "Lesen beendet ERR" ; Err

End If

If Usr.rxc = 1 Then 'Wenn Byte empfangen...
I = Udr 'Byte aus UART auslesen
Select Case I
Case "l"

Call Löschen
End Select
End If

Loop





Sub Gettime()
'there are 2 ways to get the time. With low level i2c calls or with a high level call
'first the high level call
Tm(1) = 2 ' point to second register

I2creceive &HA0 , Tm(1) , 1 , 5 ' write the second address and get 5 bytes back
End Sub


Sub Settime '
'values are stored as BCD values so convert the values first


Tm(1) = Makebcd(s) 'seconds
Tm(2) = Makebcd(m) 'minutes
Tm(3) = Makebcd(h1) 'hours
Tm(4) = Makebcd(d) 'days
Tm(5) = Makebcd(month) 'months
I2cinit
I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte &H00 'select control register
I2cwbyte &H08 'set year and day bit for masking
I2cstart 'repeated start
I2cwbyte &HA0 'write mode
I2cwbyte 2 'select seconds Register
For I = 1 To 5
I2cwbyte Tm(i)
Next 'write seconds
I2cstop
End Sub

Sub Schreibe(byval Adressh As Byte , Adressl As Byte)
Call Gettime
Tag = Makebcd(tm(4))
Monat = Makebcd(tm(5))
Minute = Makebcd(tm(2))
Stunde = Makebcd(tm(3))
S1 = 111
I2cinit
I2cstart
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cwbyte S1

I2cstop

End Sub
'I2cwbyte D 'Tag
'I2cwbyte Pu
'I2cwbyte Month 'Monat
'I2cwbyte Le
'I2cwbyte H1 'Stunde
'I2cwbyte Dp
'I2cwbyte M 'Minute
'I2cwbyte Dp 'Wechselrichter Status (2.Paketbyte)
'I2cwbyte Ff 'Cursor zurück auf Anfang
'I2cwbyte Lf
Sub Lese
I2cinit
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cstart
I2cwbyte &HA3
I2crbyte X , Nack
I2cstop
End Sub

Sub Löschen
Disable Interrupts
For B = 0 To 32768 Step 256
I2cstart
I2cwbyte &HA2
I2cwbyte &HA3
I2cwbyte &HA2

For C = 1 To 256
I2cwbyte 255
Next C
I2cstop
Waitms 100
Next B
Enable Interrupts
End Sub

End 'end program

Michael
18.10.2005, 09:26
Hallo Xeus,

im datenblatt steht bei pin 3 'NC' (not connect)
in dem, das ich gefunden habe, wird Pin 3 benutzt:
http://www.issi.com/pdf/24c256.pdf
Oder hast du die 14 pin-Version?


Sub Schreibe...
I2cstart
I2cwbyte &HA2
.
.
.
Sub Lese
I2cinit
I2cwbyte &HA2
Hast du jetzt mal nach dem R/W Bit geschaut?



beim eeprom klapt das lesen und das löschen, nur das schreiben haut nicht hin
woher weißt du daß es klappt?
Lösch doch mal mit Nullen?

Gruß, Michael

Xeus
18.10.2005, 09:34
also lesen und löschen hab ich überprüft, und mit 000 gelöscht. einwandfrei.

das mit r/w bit versteh ich nicht, weil das löschen ist doch nichts anderes als schreiben und da verwend ich doch die selben adressen

vor mir liegt das orginal datenblatt von atmel, da steht das so drinn.

gruß

xeus

Michael
18.10.2005, 09:47
Hallo Xeus,

also lesen und löschen hab ich überprüft, und mit 000 gelöscht. einwandfrei.
wie hast du festgestellt, daß wirklich 000 im EEprom steht?


das mit r/w bit versteh ich nicht, weil das löschen ist doch nichts anderes als schreiben und da verwend ich doch die selben adressen
stimmt, und wie hast du jetzt geprüft, was im EEprom drinsteht??


vor mir liegt das orginal datenblatt von atmel,
ein Link wäre schön gewesen.
In dem Datenblatt, das ich gepostet habe, wird Pin3 (A2) benutzt.

Gruß, Michael

Xeus
18.10.2005, 09:53
Lesen:


Cls
Print "Lese"
Locate 1 , 1
Lcd "Lese"
Call Lese
Locate 2 , 1
Lcd Str(x)
Locate 3 , 1
Lcd "Lesen beendet ERR" ; Err
Print "Lesen beendet ERR" ; Err



Sub Lese
I2cinit
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cstart
I2cwbyte &HA3
I2crbyte X , Nack
I2cstop
End Sub



das datenblatt befindet sich im anhang

gruß

xeus

albundy
18.10.2005, 09:59
Hallo,
Du machst da einen Fehler beim schreiben.

S1 = 111
I2cinit
I2cstart
I2cwbyte &HA2
I2cwbyte &HA3 'Speicherstelle im EEPROM
I2cwbyte &HA2
I2cwbyte S1

I2cstop


Versuche das mal:
I2cstart
I2cwbyte &HA2 'Adresse des Eeprom zum schreiben
I2cwbyte $Hxx 'Speicherstelle H Byte im Eeprom
I2cwbyte $Hxx 'Speicherstelle L Byte im Eeprom
'Da ja 0-7FFF möglich ist, muß ein Word geschrieben werden.
I2cwbyte value 'den eigentlichen Wert schreiben
I2cstop

Xeus
18.10.2005, 10:01
wie läuft das denn mit dem high and low woher bekomme ich iese werte?

albundy
18.10.2005, 10:09
wie läuft das denn mit dem high and low woher bekomme ich iese werte
Ganz einfach
1. Speicherstelle ist 0000 (also H Byte und L Byte =0)
letzte Speicherstelle ist 07FF (also H Byte =07 und L Byte =FF)

Xeus
18.10.2005, 10:15
ist es möglich eine routine dafür zu machen, das ich 4 bytes schreib, und das sich danach l und h erhöt?

hrei
18.10.2005, 10:17
Hallo!

@Xeus
Schau Dir mal mein Beispielprogramm an:

http://www.henrik-reimers.de/control/avr/software.htm#eeprom

Da wird das mit Overlay und überlappenden Variablen (Byte/Word) aufgedröselt.

Grüße
Henrik

albundy
18.10.2005, 10:25
ist es möglich eine routine dafür zu machen, das ich 4 bytes schreib, und das sich danach l und h erhöt?

Wenn ich mich nicht irre, wird nach dem schreiben, die Speicherstelle automatisch erhöht.

I2cwstart
i2cwbyte $HA2
i2cwbyte $H00
i2cwbyte $H00 '1. Speicherstelle im Eeprom
for i=1 to 4
i2cwbyte value 'Wert 1-4 in Speicherstelle 0000-0003 vom Eeprom
next
i2cstop

Xeus
18.10.2005, 11:24
kann sich bitte mal jemand den code anschauen was daran falsch ist



$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

Xeus
18.10.2005, 11:33
habs jetzt hingekriegt.

Xeus
18.10.2005, 11:39
nun würd ich gern den speicher auslesen und übers uart senden.

da ich die werte in dieser form speichere



datum,zeit,var1,var2:

tt.mm.jj;hh:mm;1byte;1byte;


1) kann ich die werte auch wieder in dieser form auslesen

2) Angenommen ich habe 10 solcher datensätze auf dem eeprom gespeichert. nun unterbreche ich die stromzufuhr meiner schaltung, dann würde er doch wieder bei speicherstelle 0 beginnen und alles überschreiben. kann man das irgendwie verhindern?



$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 Lesen
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

Adrcount = 0

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Uhr Variablen setzen
S = 0
m = 0
h = 0
d = 1
Month = 1
Wm = 1
Yd = 1
ddrd = &B00010000
Cls
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

' Program start
Call Settime





Do
If Pind.2 = 1 Then
Call Speichern
End If

If Pind.4 = 1 Then
Call Lesen
End If
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

If Adrcount < &H07FF Then Adrcount = Adrcount + 10 Else Adrcount = 0
End Sub Speichern