Binary Coded Decimal


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    hey,

    yer that is an old topic i kinda give up some time ago on the rtc.

    But i tought i would pick it back up and finally get my head around it

    when i posted that topic i didn't even no what bcd was... so as you can imagine i didn't get any were near as far as i have now.


    i am watching the value of the seconds register and it is incrementing correctly from 0-59 and the minutes are incrementing when the seconds reaches 0

    i'll look in to the voltage low bit in the seconds register and see if that is the cause of my problem, i'll let you know how i get on.

    and yes ive tried another one of these rtc and get the same error

    thanks for taking the time to help me



    Quote Originally Posted by sinoteq View Post
    I am sorry I don't have that RTC here so I can test code for you yet.

    There are some things in your code that are inconsistent with the datasheet so you should start with fixing this.

    Please look at http://www.datasheetcatalog.org/data...s/PCF8563P.pdf Table 5. As you see the Seconds register is only 7 bits wide and not 8, the 8th bit is VL. So start by making sure that bit is not included in you conversion and setting of the RTC.

    Are you sure you chip is healty? Have you tested this on more than one RTC?
    Please forgive me for asking, but is this related to this previous 2007 posting?http://www.picbasic.co.uk/forum/arch...hp/t-7567.html
    In that case I can only say you have had this problem for some time and then it is really time to solve this.

    I will swing by the market some day and pick up a chip so I can help you better.
    Last edited by -Dan-; - 23rd May 2009 at 12:53.

  2. #2
    Join Date
    Jul 2007
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    I've directly given the registers the bcd values and monitored the bcd value of the register as it changes but it still increase's the tens of the hours by 4 when seconds=40, i have not addressed the unused bits in the registers, so i cannot see it being that.

    i am lost for ideas



    Code:
     @ device  pic16f870,WDT_OFF            'Watch Dog Timer Disabled
     @ device  pic16f870,PROTECT_OFF        'Code Protect Off
     @ device  pic16f870,XT_OSC             'Using External Oscillator
     @ device  pic16f870,BOD_OFF            'Brown Out Timer Disabled 
     @ device  pic16f870,PWRT_OFF           'Power On Timer Disabled
     @ device  pic16f870,LVP_OFF            'Low Voltage Programmed Disabled
     
    DEFINE OSC 4
    ADCON0.0=0
    ADCON1=7 ' ALL PINS SET TO DIGITAL
    TRISB = %00000000
    TRISA = %00000000
    TRISC.0=0
    
    
     
     
     'rtc pins
    
    clk_pin var portc.5 
    data_pin var portc.6
    
    number var  word
    display VAR PORTB
    segment var PORTA
    seg_number var byte
    digit var byte
    delay var word
    
    
    
    
    'register address's 
    
     reg_seconds        CON  $02
     reg_minutes        con  $03
     reg_hours          con  $04
     reg_days           con  $05
     reg_weekdays       con  $06
     reg_months_century con  $07
     reg_years          con  $08
     reg_minute_alarm   con  $09
     reg_hour_alarm     con  $0A
     reg_day_alarm      con  $0B
     reg_weekday_alarm  con  $0C
     
     rtc_write var byte 
     rtc_read  var byte
     
     rtc_write=$a2
     rtc_read=$a3 
     
     
     
     'time variables
     
     bcdseconds var BYTE
     bcdminutes var BYTE
     bcdhours  var BYTE
     bcddays  var BYTE
     bcdyears var BYTE
      
     
     seconds var BYTE
     minutes var BYTE
     hours var BYTE
     days var BYTE
     years var BYTE
     
      
      
     '-----------------------------------------------------
      'initial time variable values
      
      seconds=%0100011 
      minutes=%0100011
      hours=%100011
     'days=23
     'years=7 
     
    ' -------------------------------------------------------
    
    'write intial variable's to the relevant rtc registers  
    
    init:
    
    'bcd_encode:
    
    'bcdseconds=seconds dig 1
    'bcdseconds=bcdseconds<<4
    'bcdseconds=bcdseconds+seconds dig 0
    
    'bcdminutes=minutes dig 1
    'bcdminutes=bcdminutes <<4
    'bcdminutes=bcdminutes+minutes dig 0
    
    'bcdhours=hours dig 1
    'bcdhours=bcdhours<<4
    'bcdhours=bcdhours+hours dig 0
    
    
    
    pause 10  
    
    I2CWrite data_pin,clk_pin,$A2,reg_seconds,[seconds,minutes,hours]
    pause 100
    
    
    clock_read:  
    
    
    I2CRead data_pin,clk_pin,$A2,reg_seconds,[bcdseconds,bcdminutes,bcdhours]
    pause 10
    
    'bcd_decode:  'decodes bcd to decimal
    
    'seconds=(bcdseconds>>4)*10+(bcdseconds & %00001111) 
    
    'minutes=(bcdminutes>>4)*10+(bcdminutes & %00001111)
    
    'hours=(bcdhours>>4)*10+(bcdhours & %00001111)
    
    
    
    
    OUT:
    pause 20
    serout2 portc.1,16780,["(",HEX bcdhours,")","(",HEX bcdminutes,")","(",HEX bcdseconds,")"]
    PORTC.0=1
    PAUSE 100
    PORTC.0=0
    
    
    goto clock_read

  3. #3
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default

    OK this is a declaration of war I will go to the market tomorrow and get me a few of these RTC chips. Really, it has to be something simple because it almost always is but this has to be solved.

    Please post a picture of your connections so I can connect in a similar way.

Similar Threads

  1. Convert long binary number to ASCII Decimal
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th July 2009, 13:58
  2. How to convert binary to decimal?
    By Cabomba in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th October 2007, 01:27
  3. Decimal to Binary Conversion
    By schlaray in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2006, 14:58
  4. Binary to Decimal from ADC
    By RYTECH in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th July 2005, 18:51
  5. Decimal to binary conversion
    By Demon in forum Code Examples
    Replies: 9
    Last Post: - 25th February 2005, 20:05

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