A hint, when you detect that no score has been stored (location 0 <> 0x77) then you write zero as the lowest score, how can anyone get lower than zero?
Mike.
Edit, at least that's what I think the code is doing.
Reading and writing to the EEPROM in the first subroutine looks ok:
Code:
EE.Read(1,LastLOWScore) //read the eeprom
If Prev_score < LastLOWscore Then //COMPARE LOW AND PRESENT SCORE ON EEPROM
EE.Write(1,Prev_score)
cls //write previous lowscore to eeprom
writeat(1,1,"last score",Prev_score) //susposed to show what Prev_score is (write to eeprom
delayms(2000)
EndIf
But what the heck are you trying to do in the second subroutine?!???
I assume the $77 value is just a flag to say a valid score exist in the next two bytes.
The EE.Write(0,$77,LastLOWScore) I assume writes $77 to location 0 and LastLOWScore to locations 1 & 2. However it sets LastLOWScore to zero before writing it.
I was going to suggest writing the value circular. The first location that is $ffff is the first free location so the one before must be the last written location. A simple search will find the lowest score as it will be the lowest value in the EEPROM and it will reduce wear as it uses all locations but I didn't want to confuse matters.
I assume the $77 value is just a flag to say a valid score exist in the next two bytes.
The EE.Write(0,$77,LastLOWScore) I assume writes $77 to location 0 and LastLOWScore to locations 1 & 2.
That whole approach is flawed. You might as well just read EE.Read(1, LastLOWScore) and if it's $FFFF then the data has never been initialized (which you could easily set in code when the device is first programmed).
The 'tmpbyte at 0 = $77' doesn't get you anything... all of that code for eeprom location 0 could be removed and it would be just as reliable.
Which is to say it isn't.
EE.Read(1,LastLOWScore) //read the eeprom
If Prev_score < LastLOWscore Then //COMPARE LOW AND PRESENT SCORE ON EEPROM
EE.Write(1,Prev_score)
cls //write previous lowscore to eeprom
writeat(1,1,"last score",Prev_score) //susposed to show what Prev_score is (write to eeprom
delayms(2000)
EndIf
maybe thats why the first run through it says my score is 6553
will try setting it to 0
looking at what is going on after the first run, thinking shouldn't lastLOWscore be equal to Prev_score?? after they are compared
I am LOST
been looking at the help files and other examples trying to figure out what is going on and why.
taking a break, back at it later as I am really lost with what is going on
You have two subroutines that both read and write to the EEPROM. My replied stated that the first subroutine does this the right way and the second is rubbish.
Follow the exact same form reading and reading to the EEPROM that you used in the first subroutine and it will work fine.
( Mmm I didn't read how this thread was going before i had my 2 cents I will return in a year or so see how it turned out ) I used a PIC16F877 eeprom as a code bank for a music keyboard .. key scan position to actual MiDi note value, wrote the device eeprom once (or so) must have been read thousands of times with each key touched . still good after years ..
I had to read Visitor's post four times until I realised what his point was. He was not questioning lowest score, but whether this logic error is the biggest of all the logic errors.
Made me smile (once I worked it out)
EDIT: Wonder why I assume Visitor is a he not a she? Must learn not to assume Not been corrected, so must have been right by chance.
I kind of figured that problem could be figured out once he could save and retrieve the value in eeprom. On the other hand, since he's sending the numeric values directly to the LCD without converting them to ASCII (using the DecToStr function), he won't know that he's retrieving the same number he stored.
For all the positive things I can say about Swordfish Basic, I must admit the examples provided are horrible.