News:

;) This forum is the property of Proton software developers

Main Menu

Write in eeprom

Started by Pepe, Apr 30, 2023, 12:55 PM

Previous topic - Next topic

Pepe

Is it possible to write data in the EEPROM to initialize it with values only at the moment of recording the pic with some instruction from the positron source program?

RGV250

Hi,
Could you write a value to say the last location in the eeprom to signify that the initial data has been written. Then when the PIC initialises it can read that location and if it is what you have programmed it does not load the initial values.

Bob

Pepe

#2
If this is how I do it but I lose a place in the Eeprom, pb3 has the EEPROM instruction that only saves it when the pic is burned

EEPROM 1,[1,3,12]
EEPROM 6,[10,32,2]


 In asm to record the ID I use this

Asm
__IDLOCS  0x200000,"I"
__IDLOCS  0x200001,"D"
__IDLOCS  0x200002," "
__IDLOCS  0x200003,"0"
__IDLOCS  0x200004,"0"
__IDLOCS  0x200005,"0"
__IDLOCS  0x200006,"0"
__IDLOCS  0x200007,"1"
EndAsm

This would be the way

Asm
__EEPROM_DATA(0, 1, 2, 3, 4, 5, 6, 7)
EndAsm

But how do I do if I only want to write in certain positions only and not consecutively.

John Drew

#3
Pepe,
Writing to a specific spot is in the edata section of the manual. I mostly allocate a symbol to the address to make its meaning clear in the code.
John
PS Positron calculates the value of the symbol for you.

Pepe

edata write every time the program starts or when the pic is burned only once?

joesaliba

Pepe,

When a PIC is burned all EEPROM address is $FF. So I do the following to load initial values only when PIC is burnt and powered up the first time: -

First we check if PIC is on first power up: -

If ERead 0 > 0 Then         ' Check if it the first time that PIC is running this code
    GoSub First_On          ' If yes, gosub First_On
 EndIf                       ' End If...Then instruction

If yes: -


'===================================================================================================
 '**************************
 '* First power-up routine *
 '**************************
 '>>>First power up<<<

 First_On:                       ' First_On label, load eeprom to default values

 ' Fill all eeprom with 255
 For Mode = 0 To 255             ' Create a loop from 0 to 255
    EWrite Mode , [255]         ' fill eeprom location Mode 0 to 255
    DelayMS 10                  ' 10ms delay; Allow time to write to eeprom
 Next                            ' next loop

 '---------------------------------------------------------------------------------------------------

 Temp_1 = 1500                   ' Load Temp_1; (Word variable)

 Mode = 1                        ' Load Mode
 EWrite 1, [Mode]                ' Write Mode value to eeprom address 1
                                ' Selected Mode

 Mode = 0                        ' Clear Mode; (Byte variable)
 EWrite 2, [Mode]                ' Write Mode value to eeprom address 2
                                ' Reverse of servos

 EWrite 3, [Temp_1]              ' Write value of Temp_1 to eeprom address 1
                                ' Set servo 1 higher limit to centre at first pic boot

 EWrite 5, [Temp_1]              ' Write value of Temp_1 to eeprom address 3
                                ' Set servo 1 lower limit to centre at first pic boot

 EWrite 7, [Temp_1]              ' Write value of Temp_1 to eeprom address 5
                                ' Set servo 2 higher limit to centre at first pic boot

 EWrite 9, [Temp_1]              ' Write value of Temp_1 to eeprom address 7
                                ' Set servo 2 lower limit to centre at first pic boot

 Temp_1 = 1000                   ' Load Temp_1; (Word variable)

 EWrite 11, [Temp_1]             ' Write value of Temp_1 to eeprom address 11
                                ' Set servo 3 higher limit at first pic boot

 Temp_1 = 2000                   ' Load Temp_1; (Word variable)

 EWrite 13, [Temp_1]             ' Write value of Temp_1 to eeprom address 13
                                ' Set servo 3 lower limit at first pic boot

 Temp_1 = 4000                   ' Load Temp_1; (Word variable)

 EWrite 15, [Temp_1]             ' Write value of Temp_1 to eeprom address 15
                                ' Set delay between door and gear of 5 seconds

 Temp_1 = 0                      ' Clear Temp_1; (Word variable)

 EWrite 17, [Temp_1]             ' Write value of Temp_1 To eeprom address 17
 EWrite 19, [Temp_1]             ' Write value of Temp_1 To eeprom address 19
                                ' Difference between close and open of servo 1 and 2

 EWrite 249, [Mode]              ' Write Mode value to eeprom address 249
                                ' Gear state value, (G_Stat); (0 = closed, 1 = opened)

 EWrite 0, [Mode]                ' Write 0 to Eeprom address 0. This wil tell the PIC
                                ' that it is not in the first startup. This is done at
                                ' the end of eeprom write to ensure that all data has
                                ' been written to the respective eeprom addresses

 GoTo R_Eeprom                   ' Return from where it was called

 '===================================================================================================

I copied part of a code I utilise this. Change as you desire, BUT leave the following: -

EWrite 0, [Mode]                ' Write 0 to Eeprom address 0. This wil tell the PIC
                                ' that it is not in the first startup. This is done at
                                ' the end of eeprom write to ensure that all data has
                                ' been written to the respective eeprom addresses

You could also write: -

EWrite 0, [0]
Note that Variable Mode is a byte so I only clear address 0.

IMPORTANT: -

ALWAYS place EWrite 0,
  • at the last, not first in this routine. Why?

Originally I had this placed in the first line of this routine. What was happening?

The programmer verify the PIC burn. On a short code this is done very fast, and as I had a long list of EEPROM to set at first start-up, half of them where still $FF, as the programmer: -

1. Burned PIC
2. Verified
3. Reset

So at verify, half of the EEPROM was loaded with my values, and so it was address 0, cleared to 0, and at next start-up it did not enter that routine as address 0 was 0.

Hopes this helps.

Joe


Pepe

Thanks for the answer but I wanted to know if it is possible to do it by just burning the pic without wasting a place in the eeprom and without adding code in the program, just that the hex contains the data to write the eeprom.

trastikata

Quote from: Pepe on Apr 30, 2023, 05:29 PMThanks for the answer but I wanted to know if it is possible to do it by just burning the pic without wasting a place in the eeprom and without adding code in the program, just that the hex contains the data to write the eeprom.

Pepe, as it has been said earlier, use Edata command - this will create the data table in the EEPROM, which will be flashed in the PIC at programming time.

Device = 18F2553
Declare Xtal = 8

START:   
    End
   
EData "ID 00001", 0     

This latter code will create the following *.HEX file:

Quote:020000040000FA
:100000000000000004EF00F000010F0EC16E070EAB
:06001000B46EFFD7FFD71C
:020000040030CA
:08000000C0FCFFEEFFFDBBFF99
:0200000400F00A    
:0A0000004944203030303031000058
:00000001FF

Notice those lines :0200000400F00A and :0A0000004944203030303031000058

:0200000400F00A   --> EEPROM Data   

:0A0000004944203030303031000058
--> 0A number of data bytes on line
--> 0000 address in bytes
--> 00 type - 00 means data
--> 49442030303030310000 hex data string in ASCII "4944203030303031" = "ID 00001"
--> 58 checksum

Pepe