Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 demo question — Parallax Forums

DS1302 demo question

Mikael SMikael S Posts: 60
edited 2012-02-15 13:24 in Propeller 1
Hello,
In the DS1302 demo, the time is presented in the hour, minute and seconds variable. I want to display the numbers in that variables apart, for example 12 would be 1 and 2. How can i do this?
    Debug.str( SN.decx(hour,2))
    Debug.str( string(":"))
    Debug.str( SN.decx(minute,2) )
    Debug.str( string(":") )
    Debug.str( SN.decx(second,2))

Comments

  • idbruceidbruce Posts: 6,197
    edited 2012-02-12 12:59
    IF hour > 9
        hour_first_digit =: hour / 1
        hour_second_digit =: hour // 1
    

    OOOOPPPSSS ERROR
    IF hour > 9
        hour_first_digit =: hour / 10
        hour_second_digit =: hour // 10
    
  • idbruceidbruce Posts: 6,197
    edited 2012-02-12 13:02
    Unless of course it goes to 24 hour time, in which case:
      IF hour > 9 AND hour < 20
        hour_first_digit =: hour / 10
        hour_second_digit =: hour // 10
      IF hour > 19
        hour_first_digit =: 2
        hour_second_digit =: hour // 20
    
  • Mikael SMikael S Posts: 60
    edited 2012-02-14 13:15
    thank you Idbruce!
    Very simple, stupid me...
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-14 15:32
    Many RTCs report values in BCD (hex notation). If this is the case, you can use shifting and masking. For example, 12PM would be reported at $12.
    dig1 := hour >> 4
      dig2 := hour & $0F
    

    BCD is a compact form of reprsenting decimal values in a byte; each nibble can hold 0..99. If the code the Bruce showed you (which works for pure decimal values) returns unexpected results, you may have BCD and you can extract the digits with shifting and masking.
  • Mikael SMikael S Posts: 60
    edited 2012-02-15 13:24
    Thanks JonnyMac for your answer!
    It seems to work fine, because the ds1302 return the time in a 2 digit format when in 24-h mode.
    But i think i have the problem now, when i try do read a ds1620 and want the result in two separate digits. I have to study some shifting and masking....
Sign In or Register to comment.