- 3D-Druck Einstieg und Tipps         
Ergebnis 1 bis 5 von 5

Thema: Programmierung des PCF8583 (Echtzeituhr)

  1. #1
    Administrator Robotik Visionär Avatar von Frank
    Registriert seit
    30.10.2003
    Beiträge
    5.116
    Blog-Einträge
    1

    Programmierung des PCF8583 (Echtzeituhr)

    Anzeige

    LiFePo4 Akku selber bauen - Video
    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?

    Bild hier  

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

    Mfg
    Frank

  2. #2
    Neuer Benutzer Öfters hier
    Registriert seit
    07.11.2003
    Beiträge
    26
    Schau mal hier http://www.mcselec.com/an11.htm Aber ob man auch Taktanzahl abrufen kann, keine Ahnung

  3. #3
    Neuer Benutzer Öfters hier
    Registriert seit
    07.11.2003
    Beiträge
    26
    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

    Code:
    '------------------- 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

  4. #4
    Gast
    Mich würde auch interessieren ob man Taktimpulse abrufen kann. Währe ein günstiger Frequenzzähler.

  5. #5
    Gast
    Zitat Zitat von davil
    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

    Code:
    '------------------- 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

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

12V Akku bauen