Shop OBEX P1 Docs P2 Docs Learn Events
Ds1302 — Parallax Forums

Ds1302

Dave ADave A Posts: 31
edited 2012-07-22 16:25 in BASIC Stamp
I am working on building a clock program using the BS2 chip and the DS13202.
I can make the clock program used presets, but I want to build an up counter to set the time. The DS13202 uses hex and I only can build a Decimal counter. Can someone give me a suggestion on how to do this

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-22 11:08
    The DS1302 doesn't really use hex. It uses BCD (binary coded decimal) where each decimal digit is held in a 4-bit nibble. The Stamp can directly handle nibbles as described in the memory allocation portion of the Stamp Manual.

    What do you mean by "build an up counter"? If you mean a hardware up counter, you can get 4-bit decimal counters that you can hook together to make a larger up counter that will automatically carry from one digit to another (like the TI CD4510). If you mean a software decimal counter, you could do something like this:
    counter   var   nib(4)
    i         var   nib
    
    for i = 0 to 3   ' least significant digit is #0
       counter(i) = counter(i) + 1   ' carry in
       if counter(i) > 9 then   ' is there carry to next digit?
          counter(i) = 0   ' if so, wrap counter around to zero
       else
          goto exit   ' quit early because no carry
       endif
    next
    exit:
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-07-22 15:09
    You can find example code for the DS1302 here, here or here. I hope this helps.
  • hmlittle59hmlittle59 Posts: 404
    edited 2012-07-22 16:25
    Also there is some demo code www.GarageDoorValet.com. Then click on Resource/demo code.

    Howard
    www.GarageDoorValet.com
Sign In or Register to comment.