Shop OBEX P1 Docs P2 Docs Learn Events
Confused as Usual — Parallax Forums

Confused as Usual

GuidoGuido Posts: 195
edited 2004-10-12 11:45 in BASIC Stamp
I am having some real trouble with read and write. I know how to do it with a numberic varable, but have no·idea where to start here. I am trying to save the current time from this statement. I would appreciate a sample program of this, as I do learn from them.

DEBUG DEC2 12-(24-(Hours.HIGHNIB*10+Hours.LOWNIB)//12),":",HEX2 Minutes,":",HEX2 Seconds LOOKUP Hours/$12,[noparse][[/noparse]AM,PM],Idx

Thank You

Guido

·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-08 13:19
    That statement is sending the time to the DEBUG screen in 12 hour format. If you simply want to save the time to EEPROM with WRITE, you can do this:

    · WRITE Location, hours, minutes, seconds

    Later, you can read the values back like this:

    · READ Location, hours, minutes, seconds

    Location can be a constant or variable -- but needs to be the same for the two lines of code above. And note that you must specify PBASIC 2.5 syntax to WRITE or READ multiple values.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • GuidoGuido Posts: 195
    edited 2004-10-08 17:04
    Jon,
    Thank You for your information. Still working on it. I do have one more question for you. I have for the first time downloaded and using ver. 2.5. I can run the program on any other version and work on the debug scree, but when I use 2.5
    nothing, like it is not communicating????
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-08 21:17
    Now you have me confused -- PBASIC 2.5 adds features, it doesn't take them away. Any code written for PBASIC 2.0 (that doesn't use 2.5 keywords as labels) will run fine when using PBASIC 2.5.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • GuidoGuido Posts: 195
    edited 2004-10-09 01:46
    Jon,

    You are never CONFUSED!!! Just me. I found out the problem....simple after about an hour or so......I changed the Do and loop per new 2.5, but I did not include the exit statement....Even though·it tokenized ok, there was no debug...! see who really is confused.

    Getting back to my original question, looks simple but I still don't have success as of yet. I think part of my problem is that the hours,minutes,seconds etc are displayed in hex format, and is a variable byte.·I have tried changing the debug function to dec, but it seems strange numbers...matter of fact I tried everything I could come up with including saving as a hex, but you can not read as a hex. won't take the command.·Any Ideas.....
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-09 07:08
    You're getting wrapped around the axle on a simple thing, let me see if I can help. The HEX notation is used to exploit the BCD format used in many timekeeping devices. If you haven't heard of it, BCD stores a value as two nibbles, the 10's digit of a value in the upper nibble of a byte, the 1's digit in the lower nibble of a byte. The hex format is also nibble oriented -- that's why it's used.

    In the end, though, a number is a number to any microcontroller. If you now that a number is in BCD, you can convert it to decimal like this:

    decValue = (hexValue.NIB1 * 10) + hexValue.NIB0

    Now, when you want to send information back to an RTC or other device that uses BCD numbers, here's the formula to go back:

    hexValue = (decValue / 10 << 4) + (decValue // 10)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • GuidoGuido Posts: 195
    edited 2004-10-09 12:21
    Jon,

    I really do appreciate your help. Dang don't you ever go to sleep? I am going to take a couple of days off playing with this, so my wife won't divorce me. I will be back on it monday and hope I can find some kind of results....

    Thank You Again for helping newbee's like me. It shows a lot of class as I want to learn, but hard without examples

    Guido
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-09 14:59
    We have lots of examples in the form of books that you can download from our web site. Once you're square again with your wife you might want to have a poke around our site for all kinds of goodies.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • GuidoGuido Posts: 195
    edited 2004-10-11 22:30
    Jon,
    Between me and you I have downloaded and read more Basic Stamp information then you could imagine! Does it makes sense? some of it. Can you look at this short program and figure out what the heck I am doing wrong....
    Thanks Again
    Guido
  • GuidoGuido Posts: 195
    edited 2004-10-11 22:36
    Sorry, forgot the attachment!
    Jon,
    Between me and you I have downloaded and read more Basic Stamp information then you could imagine! Does it makes sense? some of it. Can you look at this short program and figure out what the heck I am doing wrong....
    Thanks Again
    Guido
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-12 11:45
    I'm really thrashed for time right now, so how about I give you a working DS1302 program for _you_ to look at?· It's an old program, but I know it works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.