Shop OBEX P1 Docs P2 Docs Learn Events
SX/B code for DS1302 — Parallax Forums

SX/B code for DS1302

MikeSMikeS Posts: 131
edited 2005-06-01 21:10 in General Discussion
Does any one have a SX/B program for the DS1302?

I have successfully combined the SX/B SEROUT example that uses the BPI-216 LCD and the SX/B Example Project that uses the DS1620 to display temperature on a serial LCD using the SX. I would like to add the ability to display time also.

In the Basic Stamp code that·I use for the DS1302 there are nibble·variables for secs., mins., and hrs. I am not sure how to handle these because· SX/B can only handle byte variables.

thanks
Mike S.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-06-01 20:41
    Are you sure the seconds and minutes are in nibble size? A nibble holds 16 different values, not enough to hold values 16-59.
  • MikeSMikeS Posts: 131
    edited 2005-06-01 20:50
    Paul,
    seconds, minutes, and hours are byte variables.
    01 secs is a low nibble of sec
    10 sec is a high nibble of sec
    01 min is a low nibble of min
    10 min is a low nibble of min
    01 hrs is a high nibble of hrs
    10 hrs is a low nibble of hrs

    Mike S.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-06-01 21:10
    Ah ok that is called Binary Coded Decimal (BCD), without looking at the docs, I would venture a guess that adjacent BCD digits are provided in the data stream (IE low nibble of seconds followed by the high nibble of seconds (or vice versa)). Treat each grouping as a byte (read the two nibbles into a single byte variable), ie the low nibble occupies bits 0-3 the high nibble occupies bits 4-7.

    I am assuming your LCD takes data in ASCII format.

    To translate the lower nibble into ASCII, make a copy of the data, AND that copy with $0F, then add $30 to the value, the result is that digit in ASCII.

    To translate the higher nibble into ASCII, make a copy of the data, perform SWAP, AND that copy with $0F, then add $30 to the value, the result is that digit in ASCII.
Sign In or Register to comment.