RTC date problem


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default RTC read and RTC write

    Hi Bob,

    Actually, I used the PCF8563, which is virtually identical to the PCF8583 except for a few features.

    Anyway, here are the RTC read and RTC write segments that I use. Since my RTC works on a battery (a CR2032, now in its second year, expected to go on for at least a year more!), I have also extracted the low battery indiactor bit.

    'READ FRESH VALUES FROM THE RTC and convert BCD to decimal

    I2CREAD SDA,SCL,$A2,2,[S,m,h,D,W,MN,Y] 'Read all parameters from the RTC

    LOBATT = S & %10000000 ' Mask off all bits unimplemented in RTC registers
    S = S & %01111111 '
    M = M & %01111111 '
    h = H & %00111111 '
    D = D & %00111111 '
    Mn = Mn & %00011111 '

    TMP=S ' Convert BCD to decimal
    S=((tmp>>4)*10)+(tmp & $0F) '
    tmp=M '
    M=((tmp>>4)*10)+(tmp & $0F) '
    tmp=H '
    H=((tmp>>4)*10)+(tmp & $0F) '
    tmp=D '
    D=((tmp>>4)*10)+(tmp & $0F) '
    tmp=MN '
    MN=((tmp>>4)*10)+(tmp & $0F) '
    tmp=Y '
    Y=((tmp>>4)*10)+(tmp & $0F) '


    'Convert Decimal Seconds,Minutes & Hours values to BCD equivalents and write to RTC

    tmp=S
    S=(tmp dig 1<<4)+(tmp dig 0)
    tmp=M
    M=(tmp dig 1<<4)+(tmp dig 0)
    tmp=H
    H=(tmp dig 1<<4)+(tmp dig 0)
    tmp=D
    D=(tmp dig 1<<4)+(tmp dig 0)
    tmp=MN
    MN=(tmp dig 1<<4)+(tmp dig 0)
    tmp=Y
    Y=(tmp dig 1<<4)+(tmp dig 0)

    I2CWRITE SDA,SCL,$A2,2,[S,M,H,D,W,MN,Y] 'Write parameters to RTC

    Hope this helps!

    Regards,

    Anand

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Anand,

    Thank you!

    BobK

Similar Threads

  1. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 09:12
  2. PIC 16F877 I2C communications
    By sigmoideng in forum General
    Replies: 7
    Last Post: - 13th July 2007, 11:28
  3. 8583 rtc date problem
    By crazyhellos in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2007, 16:28
  4. X1226 RTC - Help
    By charudatt in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th August 2006, 18:54
  5. RTC Problem
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th March 2006, 06:13

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