• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reading writing to eeprom

Visitor

Active Member
It's actually brilliant and very flexible. There is a free version you can try. It's very much like VB6.

Mike.
I absolutely agree, wholeheartedly.

Don't let MrDEB's posts suggest anything negative about Swordfish. It is a fantastic, easy-to-use programming language. The free version of Swordfish is extremely generous, with many people never springing for the paid version (which kind of stinks in my opinion).
 

be80be

Well-Known Member
How could this be hard
Code:
Example Code

// import modules...

include "USART.bas"

include "EEPROM.bas"

include "Convert.bas"

 

// working variables...

dim Value as byte

dim Str as string

 

// write data to EEPROM...

EE.Write(0,"EEPROM TEST, Value = ", 123)

 

// read data and display...

USART.SetBaudrate(br19200)

EE.Read(0, Str, Value)

USART.Write(Str, DecToStr(Value), 13, 10)
 

MrDEB

Well-Known Member
My logic went south as I failed to insert the present low score into the first sub route. Only writing to the eeprom.
yes it compares prevscore to last score but it is basically in limbo.
the present score is extracted from s=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000))
this should have currentscore = s
going to do a rewrite and see what happens. Still currious as to where the score of 6553 comes from??
 

MrDEB

Well-Known Member
big question-- how to get this to write to the eeprom
s=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000))
I tried Currentscore = s
Currentscore= s=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000))
I realize s is a a string but??
 

Visitor

Active Member
Here's what I would do, and in fact have done in the past when I wanted to see how this worked.

¤ store a number at an EEPROM address:

EE.Write(1,42) // stores the value 42 at location 1

¤ read the EEPROM value back, into a variable dimensiomed as BYTE:

EE.Read(1,X)

¤ display the value just read:

LCD.WriteAt (1, 1, DecToStr(x))

Three steps to test if what you saved is what you got back. If it works, build from there. If not, stop and figure out why.

Note that you must use the DecToStr() function. Do your homework and figure out why.

This is a first baby step. Make this work, then figure out how to do this for a WORD instead of a BYTE. Part of this learning process is figuring out WHY you need to use a WORD.

Regarding your last post, save the millisecond number. Do the conversion after you read the number back.
 

MrDEB

Well-Known Member
will try your suggestion
found this weather it is correct?
EE.Write(0,str,s) //this becomes lowest score written to eeprom
I have your instructions printed out and hopefully I can get things sorted out
thanks
 

MrDEB

Well-Known Member
well post#46 worked but now what?
trying out small chunks of code but getting nowhere. All I get on the lcd is "
Code:
// working variables...
Dim Value As Byte
Dim Str As String
Dim x As Byte
Dim sw As PORTA.0
Dim ms As Word
Dim s As String
Dim time As Word
 Dim LastLOWScore As Byte
 Dim Prev_score As Word
Value=45
Prev_score=123
LastLOWScore=34
// working variables...
'Dim Value As Byte
'Dim Str As String
While true
// write data to EEPROM...
  'Sub Present_Score()
EE.Write(1,Str,(LastLOWScore))
EE.Read(1,Str,(LastLOWScore))
WriteAt(1,1,LastLOWScore)
 

MrDEB

Well-Known Member
oups grabbed this one works
Code:
'Dim Str As String
While true
// write data to EEPROM...
  'Sub Present_Score()
EE.Write(1,LastLOWScore)
EE.Read(1,LastLOWScore)
WriteAt(1,1,dectostr(LastLOWScore))   
 

    
Wend
the wrong code
 

Visitor

Active Member
Baby steps. Will the score or the time ever be larger than 255? What happens if you try saving and recalling 747?

Why?

How so you fix it?
 

MrDEB

Well-Known Member
lastlowscore needs to be a WORD
refereeing to your suggestion about saving the milliseconds.
which one? s=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000)) //players current score
or both?
or can't I just save "s" ???
tried lastlowscore=s dosen't compile
 

MrDEB

Well-Known Member
I discovered what the ms equals but now I am getting a contempile error that the special edition se won't allow so many variables.
going through and cleaning out stuff not needed.
so after I get it to compile, just write the value of ms THEN do the conversion?
 

Visitor

Active Member
Baby steps. Will the score or the time ever be larger than 255? What happens if you try saving and recalling 747?

Why?

How so you fix it?
I thought this was the problem you were stuck on. If you take some effort you may actually learn something.

Additional help from me is contingent on this step.

As far as actually purchasing Swordfish? You probably should since you've been using it for years. The trial edition edition is meant to try it out to decide if it's useful to you. David Barker, the creator of Swordfish, I'm sure would appreciate some remuneration for the work he put into creating Swordfish Basic.
 

MrDEB

Well-Known Member
can't believe I went over on variable allocation.
where or does the compiler show variables used?
tried searching but?
$100 is a significant amt of money but well worth it.
 

tumbleweed

Active Member
A few suggestions...
- don't put any 'EE.Write' calls inside of a 'while... wend' loop. You'll wear out the eeprom pretty quick that way.
- don't write any string variables or 'DecToStr()' to the eeprom. If you limit it to bytes and words it'll work out a lot better.
- you only need to use strings and DecToStr() when you want to see the results, like outputting to the LCD.
(that's what's eating up all your ram)

The reason you see '6553' is you're not printing out enough digits to see that it's really '65535', which is the largest value that a WORD can hold.

65535 = $FFFF in hex, which also happens to be the erased state of the eeprom.
 

MrDEB

Well-Known Member
Thank you Tumbleweed, your a God send to pic programming.
I purchased the paid version of Swordfish so now I cancontinue.
Will look over my code and make corrections to eeprom writings etc.
Thanks to "visitor" I now realize a better understanding of byte, word etc.
 

Visitor

Active Member
Thanks to "visitor" I now realize a better understanding of byte, word etc.
I've tried to help you. Perhaps if you actually do the exercises I suggested in posts #46 and #50, you will gain some understanding. Understanding that carries through to the next time you do the same thing.
 

Latest threads

EE World Online Articles

Loading

 
Top