In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Sparks-R-Fun wrote: T&E Engineer, As I think you already know, using a READ statement to access your time and date information is not a valid option since the READ statement can only read bytes/data (semi-)permanently stored in the program memory. (The program memory contents can only be changed by programming the SX, not while a program is actively running on the SX.) You will want to use an array. This is not as hard as it might seem. First you need to create an array. The array will exist in your variable memory. So make it as large as you need but not much larger. In the following example I created a constant called MESSAGESIZE that makes it much easier to change the size of the array(s) by changing only this value. If you make it too large you will run out of variable space and generate a compiler error.[CODE]MESSAGESIZE CON 32 Message1 VAR BYTE (MESSAGESIZE) Message2 VAR BYTE (MESSAGESIZE) [/CODE] Each location in the array(s) can hold one character. I find it helps to use graph paper or a spreadsheet to keep track of each character and its location. Let me jump right into modifying your StringWriter subroutine as follows:[CODE]StringWriter: 'For I = 0 to 255 For I = 0 to MESSAGESIZE IF tmpB1 = 0 THEN ' Read String_Data + I, DataChr DataChr = Message1(I) ELSE ' Read String_Data2 + I, DataChr DataChr = Message2(I) ENDIF[/CODE] Here the variable 'I' is just a position pointer that indicates which character in the array to return. Easy, eh? The first position is zero. The last is MESSAGESIZE-1. That might be the most confusing part! Now for the "magic!" Since the array is stored in Random Access Memory (RAM) you can change the values of each entry on the fly as your program runs. That is what you should do with the data coming from your DS1302 Real Time Clock. You currently have this DATA statement:[CODE] Data " 11:59:50 AM 12/31/07 Monday ",0 [/CODE] Suppose you want to replicate in the Message1 array the format of the data statement you provided. You begin with two leading spaces. So position 0 and position 1 of Message1 should contain the decimal value 32, which is the ASCII code for a space. You could do this, though it is not very efficient:[CODE]Message1(0) = 32 Message1(1) = 32[/CODE]Or this which is more human readable:[CODE]Message1(0) = " " Message1(1) = " "[/CODE]Either set creates the two leading spaces you had. The ten's place of the hour entry comes next and occupies position 2. (I hope you see the progression.) Skipping ahead a bit, the one's digit of the seconds entry is located at position 9. So once every second your program will be changing the value of position 9 and once every ten seconds it will be changing the value of position 8, the tens of seconds place. It is ok to update both positions every second, as I show below, if that is easier. At this point I need to stop as I have only glanced at some of your program and have not spent the time required to understand the whole of it. The fact that it is working and scrolling messages is great! But I have to question your use of hex values as either you or I do not correctly understand how they are being used. For example, you have the assignment "TimeDate(Secs) = $50". The entry $50 as a hex value is the same as having 80 (eighty) decimal seconds! I can not imagine that anyone would actually [B]count[/B] this way but perhaps you are receiving the data in this format. For the rest of this post I am going to assume that you are actually receiving hex values from the Real Time Clock. If that is the case then this next bit of code should update the appropriate values for you! First you will need to declare the subroutine along with a few convenient constants.[CODE]PosSecs CON 8 ' Start position of the seconds display PosMins CON 5 ' Start position of the minues display PosHrs CON 2 ' Start position of the hours display HEXUPDATE SUB 2, 2 ' Places a value (in hex) in Message1 starting at the position (in decimal) ' USAGE: HEXUPDATE HexValue, Message1Position ' EXAMPLE: HEXUPDATE $59, 8 [/CODE] Then you will need to define it as follows:[CODE]HEXUPDATE: ' USAGE: HEXUPDATE HexValue, Message1Position ' EXAMPLE: HEXUPDATE $59, 8 ' Updates the seconds display tmpB1 = __PARAM1 ' get hex value as first parameter tmpB3 = __PARAM2 ' get message position as second parameter tmpB2 = tmpB1 AND $F0 ' isolate 1st hex value SWAP tmpB2 ' swap the nibbles READ Hex_Digit + tmpB2, tmpB2 ' read the ASCII hex character Message1(tmpB3) = tmpB2 ' display the hex character INC tmpB3 ' increment to the next message position tmpB2 = tmpB1 AND $0F ' isolate 2nd hex value READ Hex_Digit + tmpB2, tmpB2 ' read the ASCII hex character Message1(tmpB3) = tmpB2 ' display the hex character RETURN [/CODE] Finally you can call it like this: [CODE]HEXUPDATE TimeDate(Secs), PosSecs ' Updates the seconds display HEXUPDATE TimeDate(Mins), PosMins ' Updates the minutes display HEXUPDATE TimeDate(Hrs), PosHrs ' Updates the hours display[/CODE] I think you get the idea. You will note that I added a new variable tmpB3. You will need to either create it or change its name to an appropriate temporary variable. If that helps you in any way, great! If not... keeping asking questions! - Sparks ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=183305#m183460 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)