Welcome GuestMonday, 23/Dec/2024, 3:01 AM

Embedded Systems Lab Website


EEPROM Processes (tutorial) - Forum

[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
EEPROM Processes (tutorial)
IronManDate: Wednesday, 15/Dec/2010, 0:32 AM | Message # 1
Sergeant
Group: Former Students
Messages: 9
Status: Offline
This is a brief tutorial on how to write to EEPROM in the PIC 16 series and i'll limit this tutorial on how to write to EEPROM of PIC16F877a .

as an intro to the subject think of the EEPROM inside the PIC as a hardware storage element that saves constant values that you could use later ( in case of our project it's the tracks that we want to save inside) the following things should be considered while doing so :

-make a lookup table for the tracks and make sure it is addressed correctly .
-the (writing to EEPROM) asm file is seperated from the main project asm file ,which means that you create 2 asm files ,one for writing tracks to the EEPROM and the other is the original game and all of it playable code .
-read the datasheet very well to understand that there are 2 important SFR that you'll deal with while writing/reading to/from EEPROM :

1-the EEDATA SFR which contains the data that will be written to the EEPROM in case of writing to the EEPROM and will contain the data to be read when reading from it .
2-the EEADR which contains which address in the EEPROM we will be writing to,or reading from through our code .in the case of 16F877a we have (256 locations available)
now that we know these important SFR ,there's a standard extra lines of instructions is required (which we don't have to understand of even think of ) which are the following :

BANKSEL EECON1
bcf EECON1,EEPGD ; points to data memory
bsf EECON1,WREN ; enable write
movlw 0x55
movwf EECON2 ; init write sequence
movlw 0xAA ; using 2 instructions
movwf EECON2
bsf EECON1,WR ; write data

you use this sequence after you already put the correct value of both the address of the location in EEPROM to be used (again the address in EEADR) and the correct data itself from the lookup table (again put data in EEDATA) .
one more step which am not sure if it's a necessity but it worked with me (the main idea of it is to hold the program flow until we're sure that the data was perfectly written to the EEPROM ) :

WAIT
BTFSC EECON1,WR
GOTO WAIT

and finally disable writing to EEPROM using : bcf EECON1,WREN ; disables write
-just remember to adjust both EEADR and EEDATA each time you want to write new values to EEPROM (you could use increment procedure for both , find your way through it )
-As for reading from the EEPROM it's an easy similar sequence just remember again to adjust the value of EEADR each time you read a certain value , and the data that u had just read is located in the SFR EEDATA . this is a brief sequence :

BANKSEL EECON1
BCF EECON1,EEPGD ; Point to Data
; memory
BSF EECON1,RD ; EE Read
WAIT
BTFSC EECON1,RD ;read confirmation
GOTO WAIT
BCF STATUS,RP0 ; Bank 2
MOVF EEDATA,W ; W = EEDATA

-be always sharp and remind yourself of what BANK you're using ,because you'll be moving back and forth in the memory banks . and when you're done with EEPROM reading remember to get back to Bank 0 .

i guess this is the main procedure for both processes (writing and reading) comment if you have any problems and i'll try to help ,and correct me if i made any mistake in this tutorial .

good luck to all of you guys ...............

 
hananaDate: Saturday, 18/Dec/2010, 6:15 PM | Message # 2
Private
Group: Former Students
Messages: 2
Status: Offline
hello,,,,why do we have to put the (writing to EEPROM) asm file seperated from the main project asm file ???
thanks for the help ..
 
IronManDate: Sunday, 19/Dec/2010, 0:19 AM | Message # 3
Sergeant
Group: Former Students
Messages: 9
Status: Offline
because if you put the (writing to EEPROM) part of code in the same ASM file which contains the game , this will mean that each time you turn on the PIC it will take more time over and over again in order to write the look-up table to EEPROM each time you start the game ,that's not all , you'll have problem in the main game lookup table if use it for both EEPROM tracks and the number shapes "1,2,3" because using the PCL for the lookup table has limitation (up to 255) and then the PCL will reset and get you back to the beginning of program ,already tried it and it's missy . got the idea ?
 
hananaDate: Sunday, 19/Dec/2010, 9:18 PM | Message # 4
Private
Group: Former Students
Messages: 2
Status: Offline
yes i got it... i have faced this problem and tried to solve it by moving the look up table place ,but it's not a good solution (it messed up the hole code ), i guess your way is better,,,thanks again .
 
IronManDate: Monday, 20/Dec/2010, 9:28 PM | Message # 5
Sergeant
Group: Former Students
Messages: 9
Status: Offline
welcome anytime ;-)
 
13ayanDate: Wednesday, 29/Dec/2010, 7:08 PM | Message # 6
Private
Group: Former Students
Messages: 1
Status: Offline
Thanks a bunch for this tutorial! =]
It helped a lot with the whole "What's with the writing to the EEPROM code, what am I supposed to do nowww..bla bla" panicking phase =P
So really thank you, it's been a great help biggrin
 
IronManDate: Wednesday, 29/Dec/2010, 11:17 PM | Message # 7
Sergeant
Group: Former Students
Messages: 9
Status: Offline
welcome ;-) glad that i could help .,.
 
amykit1Date: Thursday, 22/Dec/2016, 9:54 AM | Message # 8
Private
Group: Students
Messages: 4
Status: Offline
Why do we have to put the (writing to EEPROM) asm file seperated from the main project asm file ??? 
thanks for the help ..
 
  • Page 1 of 1
  • 1
Search:

Login form
Search
Einstein Quotes
Our poll
Rate this Site
Total of answers: 579
Statistics