In SX Microcontrollers, SX/B Compiler and SX-Key Tool, tdg8934 wrote: I have been working on my Real Time Clock time setting routine with little luck in getting it right. However, I think I have something that sort of works but not completely. I can get either the SetMins OR the SetHrs subroutines to work independently but when called right after eachother I beleive I am doing something wrong with the 74HC165 switches software coding. The problem is that when it goes through the SetHrs routine, the user presses the 1 pushbutton (now set to a "1" when pushed) to change the hours and it gets displayed and then when finished, the user presses the 0 pushbutton (now set to a "1" when pushed) and it should go to the SetMins routine. However, it goes out of the MENU routine and back into the actual clock scrolling MAIN program. I think this is because it still thinks that the 0 pushbutton is a "1" and perhaps does not get set back to a "0". I don't really know for sure. I have 4 pushbuttons and I also tried useing pushbuttons 0 and 1 for the SetHrs routine and pushbuttons 2 and 3 for the SetMins routine but it worked but when it got to the MAIN scrolling clock program, only the last routine (SetMins) was updated - not SetHrs. I would like to use as few of buttons as possible. It doesn't make sense why I can not use only 2 pushbuttons for each routine (SetHrs and SetMins). Eventually I will also have to set the AM/PM mode, (maybe the SetSecs) as well as setting date properties like day, month, year and date. Any ideas on what is wrong in my program? I have also attached the complete program. [code]'More coding above and below this. Start: [b]HIGH Load1[/b] ' Set up TimeDate array (this initializes the time/date to 07:40:30 AM 05/10/07 Thu) TimeDate(Secs) = $30 TimeDate(Mins) = $15 TimeDate(Hrs) = $06 ' if modeFlag is set to Hr24, TimeDate(Hrs) = $00 to $23 otherwise $00 to $11 when Hr12 is set TimeDate(Date) = $11 TimeDate(Month) = $05 TimeDate(Day) = $05 TimeDate(Year) = $07 TimeDate(Ctrl) = $00 ampmFlag = PM ' if modeFlag is set to Hr12, ampmFlag is AM or PM modeFlag = Hr12 ' set to either modeFlag = Hr12 or Hr24 For Idx = 0 to MESSAGESIZE ' Clear any previous message Message1(Idx) = " " Message2(Idx) = " " NEXT [b]Menu[/b] SetMode SetTimeAndDate Main: MESSAGESIZE = 16 DO For Color = 0 to 2 If Color = 0 THEN HIGH Green LOW Red ELSEIF Color = 1 THEN Low Green HIGH Red ELSEIF Color = 2 THEN Low Green Low Red Endif WriteTimeToLED WriteDateToLED tmpB1(2) = 1 'scroll Time and Date left tmpB1(0) = 0 'time scrolls on the top row StringWriter tmpB1(0) = 1 'date scrolls on the bottom row StringWriter tmpB1(2) = 1 'scroll 16x16 picture left Pic_Scroll PAUSE 1000 Pic_Scroll2 PAUSE 1000 Clear_Screen Next LOOP END ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- [b]Menu: [/b] HIGH Green LOW Red [b] SetHrs SetMins RETURN[/b] [b]Get_165: PULSOUT Load1, 10 ' load switch inputs SHIFTIN SerData, Clock, MSBPRE, switches ' shift them in RETURN[/b] [b]SetHrs: 'First set Hours TIMESET = TimeDate(Hrs) DO Get_165 IF switches.1 = 1 THEN tmpB4 = TIMESET & $0F IF tmpB4 > $8 THEN TIMESET = TIMESET + 7 ELSE TIMESET = TIMESET + 1 ENDIF IF TIMESET > $12 THEN TIMESET = 0 ENDIF MESSAGESIZE = 4 HEXUPDATE3 TIMESET,0 tmpB1(2) = 1 'scroll Time and Date left tmpB1(0) = 0 'time scrolls on the top row StringWriter ENDIF LOOP UNTIL switches.0 = 1 TimeDate(Hrs) = TIMESET RETURN[/b] [b][/b] [b]SetMins: 'Now set Minutes TIMESET = TimeDate(Mins) DO Get_165 IF switches.2 = 1 THEN tmpB4 = TIMESET & $0F IF tmpB4 > $8 THEN TIMESET = TIMESET + 7 ELSE TIMESET = TIMESET + 1 ENDIF IF TIMESET > $59 THEN TIMESET = 0 ENDIF MESSAGESIZE = 4 HEXUPDATE3 TIMESET,0 tmpB1(2) = 1 'scroll Time and Date left tmpB1(0) = 0 'time scrolls on the top row StringWriter ENDIF LOOP UNTIL switches.0 = 1 TimeDate(Mins) = TIMESET RETURN[/b] [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=191734 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)