Working with indivividual bytes of an array


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Question Am I missing something too ?

    Hi,

    As far as I remember the RTC holds the time in packed BCD format. That is the upper nibble is the tens and the lower nibble is the unit. So the formula to convert it would be
    Real_Hours = (10* hour_tens)+ hour_units
    In PBP this would be :
    Code:
        CLOCK_TMP1 = (HOURS >> 4) * 10              ' PROCESS 10s BCD
        HOURS    = HOURS & %00001111                 ' PROCESS 1s BCD
        HOURS    = CLOCK_TMP1+ HOURS                ' ADD BOTH TO GET BINARY
    Where CLOCK_TMP1 is a temporary variable. You can do it in one line to. I broke up the thing to make it more readable

    While working on a PCF8563 RTC chip I noticed that the unused bits in the memory map are not always "zero". Thus it is good idea to shred off the bits not used and make them zero manually. Like:
    Code:
          HOURS   = HOURS     & %00111111             ' clear unused bits
          MINUTES = MINUTES & %01111111             ' clear unused bits
    Happy New Year
    Regards

    Sougata

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    In addition to sougata's, here is a conversion from Melanie's.
    You need to convert your decimal values to HEX values and then you can write the HEX values to your RTC chip.


    Code:
    DecVal = HOUR
    GOSUB ConvertBCD
    HOUR = HEXVal
    
    'Now you set your RTC chip with this new HOUR variable (which is now in HEX).
    
    
    ConvertBCD:                            
            HEXVal = DecVal DIG 1
    	HEXVal = HEXVal <<4
    	HEXVal = HEXVal + DecVal DIG 0
    	RETURN

    ----------------

    Edit: also take a look at this post here: http://www.picbasic.co.uk/forum/showthread.php?t=110
    Last edited by sayzer; - 30th December 2006 at 10:30.

  3. #3
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    26


    Did you find this post helpful? Yes | No

    Default

    Thanks again Guy's got the clock working fine writing and reading from the RTC chip.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 05:46
  3. Array larger than 256 bytes
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th November 2005, 16:38
  4. Inverting a Word & Assigning Array To Bytes
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th August 2005, 00:44
  5. Best way to store array of bytes?
    By Deadeye in forum General
    Replies: 1
    Last Post: - 1st June 2005, 06:35

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