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
LCD_DTPIN = PORTB.4
LCD_RSPIN = PORTB.2
LCD_ENPIN = PORTB.3
LCD_INTERFACE = 4
LCD_LINES = 2
LCD_TYPE = 0
All_Digital = True
Delayms 150
Cls
DWord_Var = 1000000
Word_Var = 1000
Main:
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
Click here to
watch this program in action

 | Site Tutorial Index |
|  | 16F PIC Examples |
| |  | Motors |
| |  | Thermometers |
| |  | Code Snippets |
| | |  | Internal Timers |
|  | 18F PIC Examples |
|  | Handy Tips |