Shop OBEX P1 Docs P2 Docs Learn Events
@ Chris Savage or other DS1302 knowledge gurus basic timer — Parallax Forums

@ Chris Savage or other DS1302 knowledge gurus basic timer

palmtreepalmtree Posts: 4
edited 2007-06-01 19:48 in BASIC Stamp
Hi Chris or other DS1302 knowledge gurus. I have a homework board basic stamp and need it to check to see if two input variables match the outputted Hours and Minute variables from the DS1302. If you search down to the subroutine LOOPY you will see what I am trying to do.

Basically I have two input variables: mincounter and hourcounter
The DS1302 has two output variables: Hours and Minutes
I want to test if these are the same and if they are go to the subroutine crack.

My guess is that the variables are in different formats i.e. hexadecimal and integer

How can I get this program to test if these two variables are the same. Any help would be greatly appreciated.

p.s. I tried taking a look at the basic timer in another post but could not figure out the syntax.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-06-01 17:56
    Hello,

    The format stored on the DS1302 is BCD, but if you specify your values in HEX it will work. You’re comparing to decimal digits, so that’s where the compare problem is. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-06-01 17:58
    One other problem you may encounter is that you’re incrementing the decimal counter. If you increment in HEX you will get values incompatible with the BCD format. So work with the values in decimal and when you want to compare convert the value to HEX for the compare. I will see if I have some example code for this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • palmtreepalmtree Posts: 4
    edited 2007-06-01 18:06
    i figured it was something to do with the format of the variables. any example code would be great.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-06-01 19:34
    Here's a couple of simple routines that directly convert a variable between DEC/HEX...
    [size=2][code]
    BCD_Decimal:
      counter = (counter.NIB1 * 10) + counter.NIB0
      RETURN
                                    ' Convert BCD To Decimal
    Decimal_BCD:
      counter = (counter / 10 << 4) + (counter // 10)
      RETURN 
    


    [/code][/size]
    Where counter is the source and destination...If you want these converted into a separate variable then just replace the first instance of counter with the new target variable name.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • palmtreepalmtree Posts: 4
    edited 2007-06-01 19:48
    works perfectly thanks so much
Sign In or Register to comment.