Shop OBEX P1 Docs P2 Docs Learn Events
I2c Variables DS1307 — Parallax Forums

I2c Variables DS1307

Dave-WDave-W Posts: 94
edited 2009-09-15 03:26 in BASIC Stamp
Hello All,
Tracy was trying to explain this to me but I have missed something. I still do not understand this code. It still seems like magic to me.
I have done as much research on this as I can but I do not see any docs on it. Here is my problem and code that works, by the way.
HOW DOES THE 8 variables get into the string "· secs\8· " at the end ????

What is magic about the varaible "SECS" ?

·········································· define varables
secs··········· VAR···· Byte··················· ' DS1307 time registers
mins··········· VAR···· Byte
hrs············· VAR···· Byte··················· '
day············ VAR···· Byte··················· ' weekday
date··········· VAR···· Byte··················· ' day in month, 1 - 31
month··········VAR···· Byte··················· ' month 1 - 12
year··········· VAR···· Byte··················· ' year 00 to 99
control········ VAR···· Byte··················· ' SQW I/O control
btns············ VAR···· Nib···················· ' debounced button inputs
btnBack········VAR···· btns.BIT3·············· ' roll back
btnDay·········VAR···· btns.BIT2·············· ' +/- day
btnHr··········· VAR···· btns.BIT1·············· ' +/- hours
btnMn·········· VAR···· btns.BIT0·············· ' +/- minutes
idx··············· VAR···· Nib···················· ' loop control
pntr············ ·VAR···· Byte··················· ' ee pointer
char············ ·VAR···· Byte··················· ' character for display
rawTime········ VAR···· Word··················· ' 0 - 1439
Reset_Clock:··································································· This is only·exicuted on power up or reset with two buttons held down.
· GOSUB Get_Buttons···························· ' scan buttons
· idx = btns & %0011··························· ' isolate hrs & mins
· btns = %0011
· idx = btns
· IF (idx = %11) THEN·························· ' if both pressed, reset
··· secs = $00································· ' set seconds to zero to start clock chip· Clock will not start until seconds are set to ZERO ?
··· mins = $00································· ' set minutes to zero
··· hrs = $06·································· ' 6:00 AM
··· day = $08·································· ' Sunday
··· date = $0F································· ' 15th
··· month = $05································ ' May
··· year = $09································· ' 2009
··· control = 16······························· ' enable SQW output for 1Hz
··· GOSUB Set_Clock···························· ' block write clock regs
· ENDIF

MAIN:
.....
....
....
GOTO Main

Set_Clock:
· I2COUT SDA, DS1307, 0, [noparse][[/noparse]STR secs\8]·········· ' update clock registers·· What·tells the varaible "secs" to contain the 8·varaibles including control ? that I am having problems with.
· RETURN


From above:
secs··········· VAR···· Byte··················· ' DS1307 time registers··········· This tells me it is only a single Byte not Eight·bytes ?

.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-09-13 13:34
    Hi Dave , the formatter STR transmits or receives an array of bytes , the array of bytes are in consecutive locations of the Stamps EEPROM memory.

    Even though you have not declared secs as an array when you use STR secs\8 the Stamp will transmit secs plus the following 7 locations of memory .

    The thing that·determines what those 7 bytes are is the order in which you type them when you declare them.

    For example in your program you have declared

    secs Var byte

    mins Var byte

    hrs Var byte

    etc etc.

    so the memory location immediately following secs contains the variable mins and the memory location following mins contains the variable hrs

    You have an array of bytes without actually declaring an array , nice don't you think.

    Jeff T.
  • Dave-WDave-W Posts: 94
    edited 2009-09-15 03:26
    Hello Jeff,

    Thanks so much for your post and very clear response. Now I know why. I would have never thought the variable would have gotten past he·compiler without a error.

    You said..

    You have an array of bytes without actually declaring an array , nice don't you think.

    Yes, it is nice and very cool. But I would think there would be an error or some description in a warning when you declare a variable·longer than it really is when called on. Oh well. It does work and when you know about it.. it does come in handy. However, it requires you to use the parts of your·brain you seldom have to use. [noparse][[/noparse] Depends on the person ]..

    I could only guess what problems it would cause if used without thinking about it. Order 10 rolls of bathroom·paper and you get 10,000. rolls instead.....

    Dave W.

    Thanks again...





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave W.
Sign In or Register to comment.