Quick Question about addresses in memeory in spin
Brian Carpenter
Posts: 728
in Propeller 1
I am using the propeller RTC emulator program from the OBEX. it has a demo that I can program the time and then see it display in the terminal window.
It has a variable of byte TimeStamp[11]
and then uses
ser.str(@TimeStamp)
to display the time on the screen and it shows 09:14:04pm (11 characters)
I want to only display the hours which is TimeStamp[1] and TimeStamp[2]
when I tell it to
ser.str(@TimeStamp[1] thinking I was going to get just the 9, but I get 9:14:04pm
and if I use
ser.str(@TimeStamp[2] I get :14:04pm
What I really want to do is an action every hour. what I was thinking to do was to initiate my tracking variable with the current hour. add 1 to it and store it in an other variable and constantly compare the two. when they match, do my action and then add one again.
Please tell me there is an easier way.
It has a variable of byte TimeStamp[11]
and then uses
ser.str(@TimeStamp)
to display the time on the screen and it shows 09:14:04pm (11 characters)
I want to only display the hours which is TimeStamp[1] and TimeStamp[2]
when I tell it to
ser.str(@TimeStamp[1] thinking I was going to get just the 9, but I get 9:14:04pm
and if I use
ser.str(@TimeStamp[2] I get :14:04pm
What I really want to do is an action every hour. what I was thinking to do was to initiate my tracking variable with the current hour. add 1 to it and store it in an other variable and constantly compare the two. when they match, do my action and then add one again.
Please tell me there is an easier way.
Comments
You can make another variable, say
hh byte[2]
Then
hh[1] := TimeStamp[1]
hh[2] := TimeStamp[2]
You can do the same to break apart the rest.
Alternately you could replace the ":" with "nul" ($0)
hh[3] := 0
Now
Ser.str(@TimeStamp) will print the hours because the string is terminated where the : used to be.
If you just want to perform an action once an hour, and don't care what the hour is, I'd make a copy Timestamp[1] and then compare the copy to Timestamp[1]. You know the hour changed as soon as they differ, then just copy the new byte and perform your action. This saves you from having to increment the hour and perform range checks.
Chris
I suggest you add a method to your program that can print a portion of a string. For example:
This method takes the base address of a string, the first character to print, and the number of characters to print. To print hours:
The same method will let you print the minutes and seconds fields as easily.
this is the code
* Author: Beau Schwabe *
* Copyright (c) 2009 Parallax *
* See end of file for terms of use. *
************************************************
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
Clock : "PropellerRTC_Emulator"
Ser : "FullDuplexSerial"
VAR
long TimeString
byte SS,MM,HH,AP,DD,MO,YY,LY
byte DateStamp[11], TimeStamp[11]
byte hour
PUB PropellerRTC_EmulatorDemo
Ser.start(31, 30, 0, 2400) '' Initialize serial communication to the PC
Clock.Start(@TimeString) '' Initiate Prop Clock
Clock.Suspend '' Suspend Clock while being set
Clock.SetYear(16) '' 00 - 31 ... Valid from 2000 to 2031
Clock.SetMonth(08) '' 01 - 12 ... Month
Clock.SetDate(30) '' 01 - 31 ... Date
Clock.SetHour(09) '' 01 - 12 ... Hour
Clock.SetMin(44) '' 00 - 59 ... Minute
Clock.SetSec(00) '' 00 - 59 ... Second
Clock.SetAMPM(1) '' 0 = AM ; 1 = PM
Clock.Restart '' Start Clock after being set
Clock.ParseDateStamp(@DateStamp)
hour := (@datestamp[2])
repeat
Clock.ParseDateStamp(@DateStamp)
Clock.ParseTimeStamp(@TimeStamp)
ser.tx(1) '' Send the HOME code to the DEBUG terminal
ser.str(@DateStamp) '' Display Date to the DEBUG terminal
ser.str(string(" "))
ser.str(@TimeStamp) '' Display Time to the DEBUG terminal
if i add
ser.str (@timeStamp[0])
i dont just get the tens of the hour. i get the entire string just like if I write ser.str(@timeStamp)
The time is stored in the "timeStamp" array as ASCII characters. To access the individual characters in the array use the method provided by JonnyMac.
I imagine the RTC object also includes methods which would allow you to access the various components of the current time without having these values converted to ASCII characters.
I'm guessing it will display the hour.
I think the other time elements are available as variables listed here:
To access the individual values see my earlier post.