Shop OBEX P1 Docs P2 Docs Learn Events
Adjust RTC using pushbuttons — Parallax Forums

Adjust RTC using pushbuttons

MoskogMoskog Posts: 554
edited 2011-08-17 13:28 in BASIC Stamp
Came into a difficult problem trying to adjust a DS1302 by using switch and LCD display instead of DEBUG terminal.

Example adjusting date with DEBUGIN:
DEBUGIN HEX2 date

My code so far, that is not working: (S1 = normally open pushbutton)
GOSUB AdjDate
DO
  date = date + 1
  if date > 31 then date = 1
  GOSUB AdjDate
  PAUSE 750
LOOP UNTIL S1 = 0
 
AdjDate:
  SEROUT TX, LcdBaud, [LcdCls, LcdLine1, "Date: ",HEX2 date]
  SEROUT TX, LcdBaud, [LcdLine2, "Set: Press S1"]
RETURN

How can I count the date with HEX2 inside the loop?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-17 13:00
    If I understand what you're trying to do, you're trying to increment a day of the month value which is stored in "date" as two hexadecimal digits. One way to do this is as follows:
    date.lownib = date.lownib + 1
    if date.lownib = 10 then
       date.highnib = date.highnib + 1 : date.lownib = 0
    endif
    if date.highnib = 3 and date.lownib = 1 then
       date.highnib = 0 : date.lownib = 1
       gosub AdjDate
    endif
    
    There are faster ways to do this, but this is the most straightforward and easiest to understand. Remember that this doesn't check the day of the month to ensure that it's valid for the month. You'll need a table of days per month adjusted for leap years for that and change the 3 and 1 in the last if statement accordingly.
  • MoskogMoskog Posts: 554
    edited 2011-08-17 13:28
    Thank's Mike for always being here. Don't need any faster way and I also don't need no check if the day is valid for the month. The RTC will be set once for all by using a computer connected but this code here will be used for later time-corrections due to bad accuracy of crystal and stuff like that. I hate to bring the laptop out in the field each third month or so to adjust the weather stations RTC. Thanks again and have a nice evening!
Sign In or Register to comment.