#### MrDEB

##### Well-Known Member
I did the suggestions in post 46 and 50
I did gain an understanding of what is happening.
now I am attempting to use the examples and get my project to maybe advance further..
trying to abide by the suggestions Tumbleweed made in post 58
after I finish writing a short code snippet similar to the two sub routes in my project where the code writes and reads the scores I will post it.

#### MrDEB

##### Well-Known Member
well something must be working but? the LCD shows 123, 0, 48, 14388
I shut off power and ture it on and the lcd displays 14388. BUT ms is 45 not 48. Going to run with the
If prev_score < LastHighScore instead of If prev_score > LastHighScore
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 Word
Dim Prev_score As Word
Dim score As String
Dim tmpByte As Byte
Dim LastHighScore As Word

ms=45
Prev_score=123
LasthighScore=256
's=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000)) //players current score
while true

If tmpByte = $77 Then EE.Read(1,LastHighScore) writeat(1,1,dectostr(LastHighScore)) // Else LastHighScore = 0 EE.Write(0,$77,LastHighScore)
writeat(2,1,dectostr(prev_score))   //
EndIf
delayms(4000)
cls
'Dim LastHighScore As Word

If prev_score > LastHighScore Then
EE.Write(1,dectostr(lasthighscore))
writeat(1,1,dectostr(lasthighscore))  //
EndIf
delayms(4000)
cls

wend

#### be80be

##### Well-Known Member
You have too much gunk going on there

You write like this
Code:
EE.Write(0, 1223)
Code:
dim Value as word
EE.Read(0,Value)
You print it out to LCD
Code:
LCD.WriteAt (1, 1, DecToStr(Value))
You don't need nothing else you only want save the game value.

#### MrDEB

##### Well-Known Member
It should maybe show best game to date?

#### be80be

##### Well-Known Member
So you do a

Dim GameOld as word
GameOld = 1234
EE.Write(0, GameOld)

#### Visitor

##### Active Member
Post removed pending investigation of some screwy results.

Disregard the image for the time being.

#### Attachments

• 88.9 KB Views: 7
Last edited:

#### Pommie

##### Well-Known Member
I assume that SFB reads/writes words as you would expect (little endien) and the reading is confirmed by your code. Can you confirm that it writes words as expected?

Mike.

#### Visitor

##### Active Member
I assume that SFB reads/writes words as you would expect (little endien) and the reading is confirmed by your code. Can you confirm that it writes words as expected?

Mike.
I'm getting some screwy results that I can't explain as I go a little farther into this. I'm going to remove the post for now until I can verify my results.

It's not helping that my PC is being a pain in the butt right now too.

##### Well-Known Member
(Poking nose in ) I have a few months spare time to fill, so had a look at SF and saw this on the forum....

I use EE.Write as it seemed meant to be the 'generic' way to do things and it would automatically choose to write it as a longword. You are correct though that if I specified the data size to write it would work OK. I usually avoid this if I can as it makes changing the type prone to error.

#### Pommie

##### Well-Known Member
I have a few months spare time to fill
In the current environment, we might all have lots of spare time. I might even install SwordFish myself.

Mike.

##### Well-Known Member
I might even install SwordFish myself.
As a total linux.mint fan boy I will give it a go nested in ' wine '
Edit {done=30min} My first open of SF looks a steep learning curve for me , my basic days were with Qbasic and turbo Basic ( dos ) there seems to be a trap for ' old young players ' using all the include modules, insomuch as being able to micro control the data perhaps i am being fussy. coming from assembler ( and then C, ) my asm 'eeprom (PIC device ) write' was about 18 lines or so , EEPROM.bas has about the same subs and functions .. however i was dealing with one pic device so no #if #ifelse etc were required .. I can visualize how this would fill memory with un-used code ?

Last edited:

#### Nigel Goodwin

##### Super Moderator
EEPROM.bas has about the same subs and functions .. however i was dealing with one pic device so no #if #ifelse etc were required .. I can visualize how this would fill memory with un-used code ?
Not at all, the #if etc. are assembler directives, not part of the code so don't make the code any larger - it's simply a matter of selecting which parts of code are included, those not required aren't added.

##### Well-Known Member
Nigel thank you , is there a way to change the SF editor font size plz ?
Forget what i said its under Options Highlighter !

#### Nigel Goodwin

##### Super Moderator
Nigel thank you , is there a way to change the SF editor font size plz ?
No idea, never used it, and have no plans to ever use it

##### Well-Known Member
another 2 cents worth SF EEPROM Library Note
Quote " Important - you should disable the global interrupt flag (GIE) before making calls to an EEPROM write routine that modifies more than a single byte .."

#### be80be

##### Well-Known Member
The code mrdeb posted is writing a lot
All he needs to do is write his game value pull it out and compare it raw
If he wants to print format it from the raw value

#### Pommie

##### Well-Known Member
another 2 cents worth SF EEPROM Library Note
Quote " Important - you should disable the global interrupt flag (GIE) before making calls to an EEPROM write routine that modifies more than a single byte .."
SF is pretty good and I would expect that interrupts are disabled during the required write sequence. And, why is a single byte ok?

Mike.

#### Visitor

##### Active Member
Nigel thank you , is there a way to change the SF editor font size plz ?
Forget what i said its under Options Highlighter !
You found it. You can select any font you like, the size, font colors for different features, etc.

I recommend a mono-space font that has good differentiation zero and "oh", one and "ell", etc.

#### MrDEB

##### Well-Known Member
I think I got it figured out and ran it several times. It is not perfect but very close to desired where the Best_score is what I am after. even if current score is lower then current score becomes best score. I inserted arrays for current score and best score to avoid having to press buttons all morning.
Code:
Device = 18F43K22
Clock = 8
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3

Include "intosc.bas"
Include "setdigitalio.bas"
Include "ledmatrixREV.bas"
Include "lcd.bas"
Include "utils.bas"
Include "convert.bas"
Include "isrtimer.bas"
Include "EEPROM.bas"
Include "Convert.bas"

// 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 Word
dim z as byte
Dim score As String
Dim tmpByte As Byte
Dim LastHighScore As Word
dim current_score as word
dim Best_score as word
dim et(5)as word
dim A(5) as byte
//current scores
a(0)=125
a(1)=135
a(2)=45
a(3)=55
a(4)=75
//best scores
et(0)=50
et(1)=75
et(2)=35
et(3)=20
et(4)=300
'current_score=100
ms=45
'Prev_score=123
'Best_Score=282
's=DecToStr(ms/1000)+"."+DecToStr((ms Mod 1000)) //players current score
while true
for z = 0 to 4
current_score=A(z)
best_score=et(z)
ee.write(1,best_score)
If tmpByte = \$77 Then
end if
if current_score < best_score then
best_score = current_score  //reset BEST_SCORE if CURRENT_SCORE is lower
EE.Write(1,best_Score)  //present beast score
current_score=0
endif
cls

writeat(2,1,dectostr(current_score))      //14388
writeat(1,1,dectostr(best_score))   // 123

delayms(4000)
cls
next

wend

#### tumbleweed

##### Active Member
I would expect that interrupts are disabled during the required write sequence. And, why is a single byte ok?
It automatically disables/enables interrupts around the low level single WriteByte() routine, but larger data types make multiple calls to WriteByte() so it could always be interrupted between bytes (ie longword=4 bytes).

It's up to you to decide if that's important or not.

I can visualize how this would fill memory with un-used code ?
As Nigel pointed out, SF will automatically remove all of the unreferenced code for you, so even of the module is 32K you only get what you need.