Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 3 pushbuttons 2x16 LCD BS2P40 — Parallax Forums

DS1302 3 pushbuttons 2x16 LCD BS2P40

LuXo12LuXo12 Posts: 31
edited 2010-05-10 03:46 in BASIC Stamp
Hi guys, I have a small problem with displaying time on my backlit 2x16 lcd (#27977), what happens is after I write time to DS1302 chip and try to display it on LCD I am getting value above 59 when I am in dec mode and values above 9 in hex


I suspect that my problem is within writing time to ds1302 chip but im not exactly where as the minutes on the lcd do change every 60 seconds but they go over their legal limits

Thanks

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-19 05:06
    ·If do not read or write to·the DS1302 in the Burst mode then you have use the one below [noparse][[/noparse] RdSecs, RdMins] and so on
    In this mode you can read and write which ever Register you want

    Set_Time:                                      ' DS1302  Write  to Seconds
      HIGH CS1302                                  ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrSecs]
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]secs]
      LOW CS1302                                   ' Deselect DS1302
      RETURN
    
    

    ····························································································································
    Get_Time:                                     ' DS1302   Read Seconds
      HIGH CS1302                                 ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdSecs]
      SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs]
       LOW CS1302                                 ' Deselect DS1302
      RETURN
    


    You· must read and write in this way when in the burst mode
    Get_Time:                                                                       ' DS1302 Burst Read
      HIGH CS1302                                                                   ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
      SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year]
      LOW CS1302                                                                    ' Deselect DS1302
      RETURN
    


      Set_Time:                                                                 ' DS1302 Burst Write
      HIGH CS1302                                                             ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrBurst]
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]secs, mins, hrs,
        date, month, day, year, 0]
      LOW CS1302                                                              ' Deselect DS1302
      RETURN
    


    ·Here is one way if you want·to save something in RAM and read from RAM
    reg = $FE
      HIGH Timer
      SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg]
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]A.HIGHBYTE,A.LOWBYTE,B.HIGHBYTE, B.LOWBYTE,C.HIGHBYTE,C.LOWBYTE ,D,E,F]
      LOW Timer
      RETURN
     
     
      ReadRam :                           'Routine to Read Data from DS1302 Time Chip
      reg = $FF
      HIGH Timer
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
      SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]A.HIGHBYTE,A.LOWBYTE,B.HIGHBYTE, B.LOWBYTE,C.HIGHBYTE,C.LOWBYTE ,D,E,F ]
      LOW Timer
      DEBUG HOME, "Product = ",DEC5  A," DEC5 B  ", DEC5 C, CR, CR,
                               DEC5   D, DEC5  E,CR
      RETURN
    
    


    This· [noparse][[/noparse]A.HIGHBYTE,A.LOWBYTE]· = a WORD
    This· [noparse][[/noparse]D] = BYTE or less

    ·I hope this help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/19/2010 5:37:29 AM GMT
  • LuXo12LuXo12 Posts: 31
    edited 2010-04-20 04:48
    Thanks Sam but I am still having problems with that chip, based on what I understand from reading the data sheet, you need to send the data it in BCD format (I am guessing HEX) but I don't know how to do it any guide lines would be appreciated
  • LuXo12LuXo12 Posts: 31
    edited 2010-04-28 00:20
    Problem solved as I suspected it was with the variables that bs2p was sending to ds1302 i was sending them in hex dec format and not BCD

    this command solved the issue


    bcdNum = (decNum / 10 << 4) + (decNum // 10) ' Decimal To BCD
    decNum = (bcdNum.NIB1 * 10) + bcdNum.NIB0 ' BCD To Decimal

    Many thanks to Chris Savage (Parallax) who posted that command
  • LuXo12LuXo12 Posts: 31
    edited 2010-05-10 03:46
    I solved one problem and another one pops up!

    Here is what happened I was testing my clock and had it running for few hours (I guess around 12) when I noticed that the LCD display froze and the time was stuck, as I unplug the debug serial cable it was working again.

    My question is do I need to pull-down the serial cable interface pins of BS2P or is my problem related to something else? I would like to mention that the clock was working for several hours before i notice this happened
Sign In or Register to comment.