In SX Microcontrollers, SX/B Compiler and SX-Key Tool, tdg8934 wrote: Well I am making some progress. However the DS1302 routines (e.g. "SetMode", "SetTimeAndDate" and "GetTimeAndDate") are bringing on problems with TimeDate( ). I first quickly found out that I first needed to set the Message1 array to something first like spaces otherwise nothing happened on the LED matrix display. This is noted in the program below with the FOR Idx = 0 to MESSAGESIZE section. Also if I comment out the SetMode, SetTimeAndDate and GetTimeAndDate (including the IF TimeDate(secs)<>temp1 ... ENDIF section) then I can scroll 11 59 50 as you would expect which reflects what you see in the program below. If the IF TimeDate(secs)<>temp1 .... ENDIF is not commented out then it only scrolls through once because the GetTimeAndDate is commented out and it never gets the update for TimeDate(secs) to compare with temp1. As seen in the program below, the TimeDate( ) data scrolls 11 59 50 across the display as it should. However you will see that SetMode is commented out and SetTimeAnd Date and GetTimeAndDate are commented out too. Here is where the problems occur: If I uncomment SetMode then I get B1 59 50 scrolling as it clears the TimeDate(Hrs) bit 7. However, this subroutine works as it should on the LCD program. The only difference between the LCD program and the LED matrix is commenting out the INTERRUPT to turn it off (LCD gets weird characters if the LED matrix INTERRUPT is left on). If I further uncomment SetTimeAndDate then I continue to get the B1 59 50 scrolling. So no apparent change here. However, if I further uncomment GetTimeAndDate I get 51 09 01 then 59 09 09 then 00 00 83 etc... (as you can see the seconds are changing <even though everything is wrong> and it goes into the next day (e.g. 00 00 xx, etc.) As you can see TimeDate(Hrs) which was originally 11 and then B1 is now 51 after the GetTimeAndDate call. Also TimeDate(Mins) which was originally 59 is now 09. And finally TimeDate(secs) consistently changes orginally from 50 to 01 to 09 to 83 (??) etc.. which is all wrong. I was thinking what do they have in common is the INTERRUPT routine that is required to display the LED messages but can't be on when modifying the program for LCD usage. Is there a timing issue perhaps as SetTimeAndDate uses a SHIFTOUT and GetTimeAndDate uses a SHIFTIN command. Could this be the problem I have had all along with trying to display TimeDate( ) data? I certainly could not turn off the Interrupt to verify this as then I would not see any LED's turn on and scroll. Any ideas on this?? Thank you for your help. TimeDate(Secs) = $50 TimeDate(Mins) = $59 TimeDate(Hrs) = $11 ' if modeFlag is set to Hr24, TimeDate(Hrs) = $00 to $23 otherwise $00 to $11 when Hr12 is set TimeDate(Date) = $31 TimeDate(Month) = $12 TimeDate(Day) = $01 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 Message1(Idx) = " " NEXT 'SetMode 'SetTimeAndDate temp1=0 Main: DO 'GetTimeAndDate 'IF TimeDate(Secs) <> temp1 THEN ' Subroutines to send the Time and Date to the LCD 'WriteTimeToDisplay 'WriteDateToDisplay HEXUPDATE TimeDate(Secs), PosSecs ' Updates the seconds display HEXUPDATE TimeDate(Mins), PosMins ' Updates the minutes display HEXUPDATE TimeDate(Hrs), PosHrs ' Updates the hours display ' Subroutine to set up the message DATA statement to the 16x16 LED matrix Scroll_Dir = 0 tmpB1 = 0 tmpB2 = 2 StringWriter 'ENDIF 'temp1=TimeDate(Secs) LOOP END SetMode: ' Setting clockMode to modeFlag will effectively ' set or clear BIT7 in the hrs variable. clockMode = modeFlag ' Setting ampm to ampmFlag will effectively set BIT5 in the ' hrs variable to the proper value. ' This must only be done when modeFlag is set (12 Hour Mode), ' otherwise you can destroy hours above 19 in 24 Hour Mode. IF modeFlag = Hr12 THEN ampm = ampmFlag ENDIF RETURN SetTimeAndDate: HIGH RTCCS ' start transaction SHIFTOUT Dta, Clk, LSBFIRST, BurstWrite ' write address FOR Idx = Secs TO Ctrl ' write all registers SHIFTOUT Dta, Clk, LSBFIRST, TimeDate(Idx) NEXT LOW RTCCS RETURN GetTimeAndDate: HIGH RTCCS ' start transaction SHIFTOUT Dta, Clk, LSBFIRST, BurstRead ' write address FOR Idx = Secs TO Ctrl ' read time registers SHIFTIN Dta, Clk, LSBPRE, TimeDate(Idx) NEXT LOW RTCCS RETURN [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=183305#m183588 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)