real time clock - PCF8583


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    angelika's Avatar
    angelika Guest


    Did you find this post helpful? Yes | No

    Default

    The pins: sda and scl as inputs or outputs to microcontoller?

    If As outputs:

    sda=1 'high the portx.y, x is the port of micr.,y is the bit of portx.
    scl=1 'high the same as previous

    DECLARE HBUS_BITRATE 100 ' and other values

    TRISC=%00000000 'as outputs

    after you try with:hbstart,hbusout,hbstop (in pic basic functions)

    if you have other problem you ask me.

    regards

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    DECLARE HBUS_BITRATE 100 ' and other values

    TRISC=%00000000 'as outputs

    after you try with:hbstart,hbusout,hbstop (in pic basic functions)
    this will never work with Melabs. In case it's working... you should have a look on that forum
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2005
    Location
    Novi Sad, Vojvodina
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Hi Maria, Lupuccio and PCF8583 users.

    Code:
    '************************************************* ***************
    ' Ime programa: RTC.BAS
    ' Opis: program ilustruje primenu sata realnog vremena PCF8583.
    ' Za povezivanje sa mikrokontrolerom se koristi I2CREAD
    ' naredba.
    '************************************************* ***************

    DEFINE LCD_DREG PORTD ' I/O port na kome se nalazi LCD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2 ' Register select pin
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 3 ' Enable pin
    DEFINE LCD_BITS 4 ' 4-bitni data bus
    DEFINE LCD_LINES 2 ' LCD ima dva reda karaktera

    symbol SCL = PORTC.3 ' I2C data pin
    symbol SDA = PORTC.5 ' I2C clock pin

    Sec var bit
    B0 var byte
    S var byte ' Sekunde
    M var byte ' Minuti
    H var byte ' Sati
    D var byte ' Dan
    Mn var byte ' Mesec
    Y var byte ' Godina

    OPTION_REG = $7f ' Omoguci PORTB pullup otpornike
    lcdout $fe,1 ' Obrisi ekran displeja
    Main:

    I2CREAD SDA,SCL,%10100001,2,[S]
    I2CREAD SDA,SCL,%10100001,3,[M]
    I2CREAD SDA,SCL,%10100001,4,[H]
    I2CREAD SDA,SCL,%10100001,5,[D]
    I2CREAD SDA,SCL,%10100001,6,[Mn]
    I2CREAD SDA,SCL,%10100001,6,[Y]



    lcdout $fe,1 ' Obrisi displej
    lcdout $fe,2 ' Prvi red prvi karakter
    lcdout "Time: ", hex(H),":", hex(M)," ", hex(S)
    lcdout $fe,$c0 ' Drugi red, prvi karakter
    lcdout "Date: ", hex(D),".", hex(Mn),".20",hex(Y)

    Pause 500
    goto Main ' Ponovi sve

    End ' Kraj programa

  4. #4
    lupuccio's Avatar
    lupuccio Guest


    Did you find this post helpful? Yes | No

    Default 8583

    Thanks to all for the answers.....
    The only problem that i have... ( a big problem ) is set hour and minutes with buttons.
    Unfortunely i haven't the code here.
    Next week i will post my code.
    and then i hope that someone can help me.
    Thanks again to all.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    That's not a problem... learning opportunuities.

    USE I2CWRITE with the same settings as I2CREAD should work

    you just need to test your pushbbuton...
    Code:
    lcdout $fe,1 ' Obrisi displej 
    lcdout $fe,2 ' Prvi red prvi karakter
    lcdout "Time: ", hex(H),":", hex(M)," ", hex(S)
    lcdout $fe,$c0 ' Drugi red, prvi karakter 
    lcdout "Date: ", hex(D),".", hex(Mn),".20",hex(Y)
                        '<== Here
    Pause 500     
    goto Main ' Ponovi sve
    but certainely better if you use something like
    Code:
    lcdout $fe,1 ' Obrisi displej 
    lcdout $fe,2 ' Prvi red prvi karakter
    lcdout "Time: ", hex(H),":", hex(M)," ", hex(S)
    lcdout $fe,$c0 ' Drugi red, prvi karakter 
    lcdout "Date: ", hex(D),".", hex(Mn),".20",hex(Y)
    
    While Delay<5000 ' Delay loop of 500 mSec
         ' Select case pushbutton and set/hour time here+I2CWRITE
         ' if there's no push button pressed Do a PAUSEUS 100 and increment
         ' Delay Variable.
         '
         ' 
         Wend
    goto Main ' Ponovi sve
    yeah just an idea. not everything on a plate and you'll have to do some homework around the above.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    The PCF8583 is very similar to DS1307.

    Melanie has written an excellent example for the DS1307.

    click here for MN1307.txt

    It should work on the PCF8583 with very small modifications.
    Last edited by NavMicroSystems; - 24th June 2005 at 23:46.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  7. #7
    lupuccio's Avatar
    lupuccio Guest


    Did you find this post helpful? Yes | No

    Default here's the code.

    part is mine and part i' have found on the net.
    with my circuit it works
    Thanks to all.
    '********************************
    device = 16f876A
    xtal = 4
    CONFIG XT_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CP_OFF , DEBUG_OFF
    LCD_DTPIN portb.4 ' dati lcd
    LCD_RSPIN portb.1 ' register select
    LCD_ENPIN portb.3 ' enable lcd 1
    LCD_INTERFACE 4 ' interfaccia lcd 4 bit
    LCD_LINES 2 ' linee lcd
    DECLARE SDA_PIN PORTC.4
    DECLARE SCL_PIN PORTC.3
    '*** variabili ************************************************** ***************
    delayms 200 'stabilizza LCD
    cls
    dim bcd_to_bin 'variable used in BCD and Binary conversion routines
    dim low_bits 'low byte for Binary to BCD routine
    dim high_bits 'high byte for Binary to BCD routine
    dim pcf8583_address 'pcf8583 internal registers address(2=seconds,3=minutes etc.)
    Dim second as byte
    Dim minute as byte
    Dim hour as byte
    dim setup as byte
    symbol clkout=%10100000 'set the 8583 to receive data
    symbol clkin=%10100001 'set the 8583 to transmit data
    Symbol button1 = portc.0
    Symbol button2 = portc.1
    Symbol button3 = portc.2
    pcf8583_address = 0
    setup = 0
    second = 0
    minute = 0
    hour = 0
    cls
    delayms 200
    ' qui inizia il programma che legge dal 8583
    C_upd:
    '*** Visualizzazione ora ************************************************** *****
    busin %10100001,2,[second,minute,hour]
    pcf8583_address = 2:gosub read_time 'read seconds data from 8583
    second=bcd_to_bin 'convert to binary
    pcf8583_address = 3:gosub read_time 'read minute data from 8583
    minute=bcd_to_bin 'convert to binary
    pcf8583_address = 4:gosub read_time 'read hour data from 8583
    hour=bcd_to_bin 'convert to binary
    print at 1,5, dec2 hour,":",dec2 minute,":",dec2 second
    '*** menu start
    if button1 = 0 then inc setup
    if setup = 1 then goto set_min
    if setup = 2 then goto set_hour
    if setup > 2 then
    print at 2,1," "
    setup = 0
    endif
    goto C_upd

    '************************************************* ******************************
    set_min:
    print at 2,5,"Set Min "
    if button2 =0 then
    busin clkin,3,[bcd_to_bin] 'leggi i minuti
    gosub conv_to_bin ' li converte in binario
    inc bcd_to_bin
    if bcd_to_bin > 59 then bcd_to_bin = 0
    delayms 100
    gosub convert_to_bcd
    busout clkout,3,[bcd_to_bin]
    delayms 10
    endif
    goto c_upd
    '************************************************* ******************************
    set_hour:
    print at 2,5,"Set Hour"
    if button2 =0 then
    busin clkin,4,[bcd_to_bin] 'leggi le ore
    gosub conv_to_bin ' li converte in binario
    inc bcd_to_bin
    if bcd_to_bin > 23 then bcd_to_bin = 0
    delayms 100
    gosub convert_to_bcd
    busout clkout,4,[bcd_to_bin]
    delayms 10
    endif
    goto c_upd
    '*** antirimbalzo ************************************************** ************
    'Debounce: DELAYMS 200
    ' Update=1
    ' goto c_upd
    '************************************************* ******************************
    ' legge il dato dall'indirizzo puntato da "pcf8583_address"
    ' il dato viene memorizzato nella variabile "bcd_to_bin"
    read_time:
    busin clkin,pcf8583_address,[bcd_to_bin]
    gosub conv_to_bin
    return
    '************************************************* ******************************
    ' Questa routine converte il byte da binario a decimale e lo carica nella
    ' variabile "bcd_to_bin" e lo ritorna nella stessa variabile "bcd_to_bin"
    ' Se il valore è "9" o meno, non fa nulla perche in BCD o BIN sono uguali.
    conv_to_bin:
    select bcd_to_bin
    case 16 to 25
    bcd_to_bin=bcd_to_bin-6
    case 32 to 41
    bcd_to_bin=bcd_to_bin-12
    case 48 to 57
    bcd_to_bin=bcd_to_bin-18
    case 64 to 73
    bcd_to_bin=bcd_to_bin-24
    case 80 to 89
    bcd_to_bin=bcd_to_bin-30
    case 96 to 105
    bcd_to_bin=bcd_to_bin-36
    case 112 to 121
    bcd_to_bin=bcd_to_bin-42
    case 128 to 137
    bcd_to_bin=bcd_to_bin-48
    case 144 to 153
    bcd_to_bin=bcd_to_bin-54
    endselect
    return
    '************************************************* ******************************
    ' Conversione da binario a BCD
    ' Il byte convertito viene caricato nella variabile bcd_to_bin
    ' e viene restituito nella stessa variabile bcd_to_bin
    convert_to_bcd:
    low_bits=bcd_to_bin//10 'get lsb,same for Bin and BCD
    high_bits=bcd_to_bin/10 'get msb
    bcd_to_bin=high_bits*16 'convert msb to BCD
    bcd_to_bin=bcd_to_bin+low_bits 'add BCD msb and lsb together
    return

Similar Threads

  1. real time clock
    By maria in forum Code Examples
    Replies: 44
    Last Post: - 1st March 2022, 13:13
  2. Real Time Clock
    By in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd June 2012, 05:52
  3. Real time clock ICs
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 66
    Last Post: - 20th October 2008, 17:05
  4. Real Time Clock
    By savnik in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th December 2006, 03:02
  5. Real time clock... what a headache!
    By Eng4444 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 8th June 2006, 22:56

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts