Shop OBEX P1 Docs P2 Docs Learn Events
BS2p40 with DS1307 — Parallax Forums

BS2p40 with DS1307

NewBeeNewBee Posts: 35
edited 2010-06-10 15:26 in BASIC Stamp
Can some one help me with this piece of code.

'
[noparse][[/noparse] Variables ]
day············ VAR···· Byte··················· ' weekday
pntr··········· VAR···· Byte··················· ' ee pointer
'
[noparse][[/noparse] EEPROM Data ]
DayNames······· DATA··· "SunMonTueWedThuFriSat"

· pntr = DayNames + ((day - 1) * 3)············ ' point to 1st char
I don't understand how DayNames as a string of eprom data is being used in the formula.

Thanks,

Bob

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-06-10 15:18
    DayNames is an array of 21 letters numbered from 0 to 20. day (of week) is a variable that takes on a value from 1 to 7. The objective is to point to the beginning of the three letter string for that day. Work it out. On Sunday, (day - 1) is zero, and the pointer is exactly equal to DayNames, the "S" in "Sun". Or on Thursday, (day-1)=4, and the result is pntr=DayNames+12, the "T" in "Thu".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sumdawgysumdawgy Posts: 167
    edited 2010-06-10 15:25
    Each day name is 3 bytes/letters long.

    Daynames is being used by the compiler to track the Eeprom ADDRESS location
    Daynames ALSO contains all of the names of the weekdays in 3 letter/byte format.
    Day is deing used by YOU the user to select the day you want from inside the DAYNAMES location.

    You need the *3 to move from name to name.
    By using Daynames, you don't have to know where pntr has to point.
    the compiler will handle that for you.

    In the end, pntr ends up telling you where to read your 3 bytes/letters you specified·in·Day.
    One last thing ... since Sun is first. it's day one... (Can't use zero, don't forget the -1 )

    hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Before you criticize someone, walk a mile in his shoes. That way if he gets angry, he'll be a mile away and barefoot. - unknown

    Post Edited (sumdawgy) : 6/10/2010 3:33:18 PM GMT
  • NewBeeNewBee Posts: 35
    edited 2010-06-10 15:26
    Thank you Tracy.
Sign In or Register to comment.