Greetings all,
Well... another total PIC newbie here...
I've dabbled in electronics for a few decades and can generally navigate my way around hardware pretty well.
But I'm *totally* new to PIC's and programming in general, so please be gentle with me...
I'm attempting to build a project that requires an RTC with battery backup and an LCD display that displays (among other things).. the real time.
The problem I'm having is setting the clock.
I'm using a 16F690, a DS1302, and a standard 16x2 LCD (in 4-bit mode). Compiler is PICBASIC PRO and programmer is a PICkit2.
I've got the DS1302 and LCD up and running just fine. The clock keeps (and displays) time just fine. I also have no trouble detecting the set buttons.
The problem is SETTING the clock. I think I'm either math challenged and/or just generally clueless here.
The sample program I started with sets the initial time manually when you load the PIC, but what I need of course is to set it with buttons. That's where my troubles begin.
Here's some snippets of my code, so you've got an idea where I'm at: (just the relevant bits I think)
'**This is what I want to do away with and replace with buttons:Code:' Allocate variables rtcyear var byte rtcday var byte rtcmonth var byte rtcdate var byte rtchr var byte rtcmin var byte rtcsec var byte rtccontrol var byte
Code:' Set initial time rtcyear = $09 'Set Year rtcday = $05 'Set Day rtcmonth = $1 'Set Month rtcdate = $1 'Set Date of month rtchr = $21 'Set Hour rtcmin = $03 'Set Minutes rtcsec = $20 'Set Seconds Gosub settime ' DO IT! - Set the time
'**This is the main goods:
Code:' Subroutine to write time to RTC settime: RST = 1 ' Ready for transfer Shiftout IO, SCLK, LSBFIRST, [$8e, 0] ' Enable write RST = 0 ' Reset RTC RST = 1 ' Ready for transfer ' Write all 8 RTC registers in burst mode Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0] RST = 0 ' Reset RTC Return ' Subroutine to read time from RTC gettime: RST = 1 ' Ready for transfer ' Read all 8 RTC registers in burst mode Shiftout IO, SCLK, LSBFIRST, [$bf] Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol] RST = 0 ' Reset RTC Return ' Main program loop - updates the LCD with the time mainloop: Gosub gettime ' Read the time from the RTC ' Display time on LCD Lcdout $fe, 1, $fe, 2, hex2 rtchr, ":", Hex2 rtcmin, ":", Hex2 rtcsec,_ $fe,$C0, " ", Hex2 rtcmonth, "/", Hex2 rtcdate, "/" , Hex2 rtcyear Pause 100 ' slow things down a bit to keep the LCD from freaking out gosub checkbuttons Goto mainloop ' repeat until nauseated...
When a button is detected I call a subroutine that's supposed to increment the minutes (or hours) to set the clock. This is where I'm tOO sTOoPid:
---------Code:increminute: rtcmin= rtcmin + 1 if rtcmin >= 60 then rtcmin = 0 endif gosub settime return
Even that part works... to a degree. It does set the time on the clock. THE PROBLEM is that it sets the minutes on the LCD in HEX!
if I start at 03 minutes (as shown on the LCD) and increment with the set button, it works fine until I get past 09... then it goes to 0A, OB, OE, etc. instead of continuing at 10, 11, 12, etc.
Clearly, this will not do!
Can someone please help me out of the darkness here? Or at least give me a shove in the right direction? I've searched about a million websites and forum posts, but....
Thanks very much,
Steve



"rtchr = 21 " will put 21 in hours so delete all the $ signs to use decimal numbers for the init.
Sorry, but it just struck me as funny . . . 



Bookmarks