PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Programmierung des PCF8583 (Echtzeituhr)



Frank
18.02.2004, 12:54
Hat jemand mit der Programmierung des PCF8583 (Echtzeituhr) erfahrung?
Kann man da die Anzahl der Taktimpulse am OSCI Eingang irgendwo abrufen und wieder auf 0 setzen? Wie?

http://www.bbs-winsen.de/GoBlack/ETechnik/digitalt/i2c/pcf8583.gif

Hat jemand ein paar Programmierbeispiele, möglichst Bascom-Avr oder C-Programm.

Mfg
Frank

davil
18.02.2004, 13:22
Schau mal hier http://www.mcselec.com/an11.htm Aber ob man auch Taktanzahl abrufen kann, keine Ahnung

davil
18.02.2004, 21:22
Ich habe noch was gefunden, aber die Taktzahlabfrage immer noch nicht. Aber das sollte auch gehen da ich schon gelesen habe das damit auch Frequenzzähler gebaut werden



'------------------- AN 4 -----------------------------
' Copyright 1998-2002 MCS Electronics
' CLOCK.BAS
'This AN shows how to use the PCF8583 I2C clock device
'The PCF8583 is a PHILIPS device. Look at the datasheet for more details
'I have used the STK200 to test the program with a 8515
'------------------------------------------------------
$crystal = 3686400
$baud = 19200


On Int0 Onls 'Interrupt 0 verweist auf die Sub Onls
Config Int0 = Falling 'Interrupt 0 reagiert auf fallende Flanke
Enable Int0 'Interrupt 0 aktivieren
Enable Interrupts 'generell alle Interrupts aktivieren

Config Portb = Output
Portb = 63


Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portb.0 , Db7 = Portd.7 , E = Portd.5 , Rs = Portd.4
Config Lcd = 40 * 2

Declare Sub Settime(byval S1 As Byte , Byval M1 As Byte , Byval H1 As Byte , Byval D1 As Byte , Byval Month1 As Byte)
Declare Sub Gettime()
Declare Sub Setalert(byval S1 As Byte , Byval M1 As Byte , Byval H1 As Byte , Byval D1 As Byte , Byval Month1 As Byte)

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

'These are pointers to tm() for simple handling.
Dim S As Byte At &H60 Overlay
Dim M As Byte At &H61 Overlay
Dim H As Byte At &H62 Overlay
Dim D As Byte At &H63 Overlay
Dim Month As Byte At &H64 Overlay


'configure the used port pin for I2C
Config I2cdelay = 5 ' default slow mode
Config Sda = Portc.4
Config Scl = Portc.5


Cls
Lcd "PCF8583 Clock Sample"

Call Settime(0 , 30 , 12 , 1 , 8) 'set time
Call Setalert(0 , Cnt , 12 , 1 , 8)

Wait 2

Do
Call Gettime
Cls
Lcd Hex(d) ; "." ; Hex(month) ; ". - " ; Hex(h) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " Err:" ; Err
Lowerline
Lcd "alarmminute: " ; Str(cnt)
Wait 1
Loop
End




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
'i2creceive will first write 1 byte from tm(1) which is 2, and then will read 5 bytes and store it onto tm(1)-tm(5)


'and optional with low level calls
' For I = 1 To 5
' Temp = I + 1
' I2cstart
' I2cwbyte &HA0 'write addres of PCF8583
' I2cwbyte Temp 'select register
' I2cstart 'repeated start
' I2cwbyte &HA1 'write address for reading info
' I2crbyte Tm(i) , Nack 'read data
' Next
' I2cstop
End Sub


Sub Settime(s1 As Byte , M1 As Byte , H1 As Byte , D1 As Byte , Month1 As Byte)
'values are stored as BCD values so convert the values first


Tm(1) = Makebcd(s1) 'seconds
Tm(2) = Makebcd(m1) 'minutes
Tm(3) = Makebcd(h1) 'hours
Tm(4) = Makebcd(d1) 'days
Tm(5) = Makebcd(month1) 'months

I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte 0 'jmp to control/status register
I2cwbyte &B00000100 'control/status register

I2cwbyte &B00000000 'setting 100th seconds
I2cwbyte Tm(1) 'setting seconds
I2cwbyte Tm(2) 'setting minutes to 45
I2cwbyte Tm(3) 'setting hours to 14
I2cwbyte Tm(4) 'setting days
I2cwbyte Tm(5) 'setting month

I2cwbyte &B00000000 'timer ... to 0
I2cstop

End Sub

Sub Setalert(s1 As Byte , M1 As Byte , H1 As Byte , D1 As Byte , Month1 As Byte)

Tm(1) = Makebcd(s1) 'seconds
Tm(2) = Makebcd(m1) 'minutes
Tm(3) = Makebcd(h1) 'hours
Tm(4) = Makebcd(d1) 'days
Tm(5) = Makebcd(month1) 'months

'hier alarm-regiser
I2cstart
I2cwbyte &HA0 'write address
I2cwbyte 8 'jmp to control/status register

I2cwbyte &B10110000 'alarm control register

I2cwbyte &B00000000 '100tel
I2cwbyte Tm(1) 'sec
I2cwbyte Tm(2) 'min
I2cwbyte Tm(3) 'hours
I2cwbyte Tm(4) 'date
I2cwbyte Tm(5) 'month

I2cwbyte &B00000000 'alarm timer
I2cstop


End Sub

Onls:
Portb.1 = 0
Waitms 100
Portb.1 = 1
Waitms 100
Incr Cnt

I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte 0 'jmp to control/status register
I2cwbyte &B00000100 'control/status register
I2cstop

Call Setalert(0 , Cnt , 12 , 1 , 8)
Return

21.02.2004, 11:00
Mich würde auch interessieren ob man Taktimpulse abrufen kann. Währe ein günstiger Frequenzzähler.

08.04.2005, 16:33
Ich habe noch was gefunden, aber die Taktzahlabfrage immer noch nicht. Aber das sollte auch gehen da ich schon gelesen habe das damit auch Frequenzzähler gebaut werden



'------------------- AN 4 -----------------------------
' Copyright 1998-2002 MCS Electronics
' CLOCK.BAS
'This AN shows how to use the PCF8583 I2C clock device
'The PCF8583 is a PHILIPS device. Look at the datasheet for more details
'I have used the STK200 to test the program with a 8515
'------------------------------------------------------
$crystal = 3686400
$baud = 19200


On Int0 Onls 'Interrupt 0 verweist auf die Sub Onls
Config Int0 = Falling 'Interrupt 0 reagiert auf fallende Flanke
Enable Int0 'Interrupt 0 aktivieren
Enable Interrupts 'generell alle Interrupts aktivieren

Config Portb = Output
Portb = 63


Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portb.0 , Db7 = Portd.7 , E = Portd.5 , Rs = Portd.4
Config Lcd = 40 * 2

Declare Sub Settime(byval S1 As Byte , Byval M1 As Byte , Byval H1 As Byte , Byval D1 As Byte , Byval Month1 As Byte)
Declare Sub Gettime()
Declare Sub Setalert(byval S1 As Byte , Byval M1 As Byte , Byval H1 As Byte , Byval D1 As Byte , Byval Month1 As Byte)

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

'These are pointers to tm() for simple handling.
Dim S As Byte At &H60 Overlay
Dim M As Byte At &H61 Overlay
Dim H As Byte At &H62 Overlay
Dim D As Byte At &H63 Overlay
Dim Month As Byte At &H64 Overlay


'configure the used port pin for I2C
Config I2cdelay = 5 ' default slow mode
Config Sda = Portc.4
Config Scl = Portc.5


Cls
Lcd "PCF8583 Clock Sample"

Call Settime(0 , 30 , 12 , 1 , 8) 'set time
Call Setalert(0 , Cnt , 12 , 1 , 8)

Wait 2

Do
Call Gettime
Cls
Lcd Hex(d) ; "." ; Hex(month) ; ". - " ; Hex(h) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " Err:" ; Err
Lowerline
Lcd "alarmminute: " ; Str(cnt)
Wait 1
Loop
End




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
'i2creceive will first write 1 byte from tm(1) which is 2, and then will read 5 bytes and store it onto tm(1)-tm(5)


'and optional with low level calls
' For I = 1 To 5
' Temp = I + 1
' I2cstart
' I2cwbyte &HA0 'write addres of PCF8583
' I2cwbyte Temp 'select register
' I2cstart 'repeated start
' I2cwbyte &HA1 'write address for reading info
' I2crbyte Tm(i) , Nack 'read data
' Next
' I2cstop
End Sub


Sub Settime(s1 As Byte , M1 As Byte , H1 As Byte , D1 As Byte , Month1 As Byte)
'values are stored as BCD values so convert the values first


Tm(1) = Makebcd(s1) 'seconds
Tm(2) = Makebcd(m1) 'minutes
Tm(3) = Makebcd(h1) 'hours
Tm(4) = Makebcd(d1) 'days
Tm(5) = Makebcd(month1) 'months

I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte 0 'jmp to control/status register
I2cwbyte &B00000100 'control/status register

I2cwbyte &B00000000 'setting 100th seconds
I2cwbyte Tm(1) 'setting seconds
I2cwbyte Tm(2) 'setting minutes to 45
I2cwbyte Tm(3) 'setting hours to 14
I2cwbyte Tm(4) 'setting days
I2cwbyte Tm(5) 'setting month

I2cwbyte &B00000000 'timer ... to 0
I2cstop

End Sub

Sub Setalert(s1 As Byte , M1 As Byte , H1 As Byte , D1 As Byte , Month1 As Byte)

Tm(1) = Makebcd(s1) 'seconds
Tm(2) = Makebcd(m1) 'minutes
Tm(3) = Makebcd(h1) 'hours
Tm(4) = Makebcd(d1) 'days
Tm(5) = Makebcd(month1) 'months

'hier alarm-regiser
I2cstart
I2cwbyte &HA0 'write address
I2cwbyte 8 'jmp to control/status register

I2cwbyte &B10110000 'alarm control register

I2cwbyte &B00000000 '100tel
I2cwbyte Tm(1) 'sec
I2cwbyte Tm(2) 'min
I2cwbyte Tm(3) 'hours
I2cwbyte Tm(4) 'date
I2cwbyte Tm(5) 'month

I2cwbyte &B00000000 'alarm timer
I2cstop


End Sub

Onls:
Portb.1 = 0
Waitms 100
Portb.1 = 1
Waitms 100
Incr Cnt

I2cstart 'generate start
I2cwbyte &HA0 'write address
I2cwbyte 0 'jmp to control/status register
I2cwbyte &B00000100 'control/status register
I2cstop

Call Setalert(0 , Cnt , 12 , 1 , 8)
Return