Proton Code Snippet - Read/Write to EEPROM

The EEPROM on a PIC micro is memory that can contain information even while the PIC is turned off. This is useful for storing data/passwords/key information that is changeable, but required by the program.

Reading and writing to/from the PIC's EEPROM is very simple with a higher programming language such as Proton+, and is as simple as the following;

Variable = EREAD Address 
EWRITE Address , [Variable, Variable]


The type of variable being save will determine the amount of EEPROM memory that will be written too. For example:

Dim Large_Variable As DWord
EWRITE 00, [Large_Variable]


The above example will write Large_Variable to address 00 of the PIC's EEPROM. But because DWord's contain 4 bytes of information, addresses 00, 01, 02, 03 will be written too. You must take things like this into account. Other examples are Words take 2 Bytes, or Floats take 4 Bytes etc.

Reading from the EEPROM is just as easy, and a quick look at the Proton Help file will guide you in the right direction.

Note: PIC's, like other EEPROMS, can only be written too 1,000,000 times by the datasheet. In reality, this value can be as low as 100,000. Do not write to the EEPROM in a continues loop - use it sparingly. There is no limit on reading EEPROM data however.

Here's a small program displaying an EEPROM read and write:

Device = 16F877
Xtal = 4
Dim DWord_Var as DWord
Dim Word_Var as Word
Dim Temp_DWord as DWord
Dim Temp_Word as Word
All_Digital = True
Delayms 150
DWord_Var = 1000000
Word_Var = 1000
 EWrite 00, [DWord_Var, Word_Var]
 Temp_DWord = ERead 00
 Temp_Word = ERead 04
 Print At 1, 1, DEC7 Temp_DWord
 Print At 2, 1, DEC5 Temp_Word
 Inc DWord_Var
 Inc Word_Var
 DelaymS 1000
 Goto Main 


Forum Activity

  • No posts to display.

Member Access