PDA

View Full Version : Using eeprom for the first time- Help please



financecatalyst
- 11th October 2009, 01:05
Hi
I am using PIC 16F690 and here is a fraction of my code. I have written this code so it stores my phone number and only enters once under this label "first:". Code does not seem to enter this label to being with - Is there somthing wrong with my code?
first:
read 230,a : read 231,b : read 232,c
if a<>"6" and b<>"8" and c<>"4"then
for c=0 to 255
write c,0
next c
write 230,"6"
write 231,"8"
write 232,"4"
pause 5000
for c=0 to 12
read c,ph[c]
next c

write 200,"+" : write 201,"4" : write 202,"4" : write 203,"7" : write 204,"8" : write 205,"3" : write 206,"2" : write 207,"2" : write 208,"2" : write 209,"5" : write 210,"1" : write 211,"7" : write 212,"4" ' this is all in one line
for c=200 to 212
read c,my[c-200]
next c
endif

Archangel
- 11th October 2009, 04:45
Hi financecatalyst,
Wow, that's one heck of an If/Then loop, I never had any success trying to cram that much into one. If it were me I would build a subroutine for all that stuff and return after. Not really experienced with Write too much and of course I am not at my bench to try it out, but might add a short pause, say 10 or 15 ms after each write.


read c,my[c-200]

So you have a 255 byte array ?
Not sure I understand this otherwise . . .
and it works with c-200 ?

aratti
- 11th October 2009, 11:32
Your code:


write 200,"+" : write 201,"4" : write 202,"4" : write 203,"7" : write 204,"8" : write 205,"3" : write 206,"2" : write 207,"2" : write 208,"2" : write 209,"5" : write 210,"1" : write 211,"7" : write 212,"4" ' this is all in one line
for c=200 to 212
read c,my[c-200]
next c

You can write eeprom only once when you program your pic with this instruction at the begining of your program:



EEPROM 200,[43,52,52,55,56,51,50,50,50,53,49,55,52]

'In your code when you need to load the number then

for c=200 to 212
read c,my[c-200]
next c




But you should avoid to use this peace of code (In red) otherwise you will erase your phone #



read 230,a : read 231,b : read 232,c
if a<>"6" and b<>"8" and c<>"4"then
for c=0 to 255
write c,0
next c
...........
...........




You should use this instead, so you will save your number.



read 230,a : read 231,b : read 232,c
if a<>"6" and b<>"8" and c<>"4"then
for c=0 to 199
write c,0
next c
..........
..........



In order to avoid holes in the eeprom you can change location to your phone # like this:




EEPROM 243,[43,52,52,55,56,51,50,50,50,53,49,55,52]

'In your code when you need to load the number then

for c=243 to 255
read c,my[c-243]
next c



In this case you could erase up to location 242 and still save you phone #.



read 230,a : read 231,b : read 232,c
if a<>"6" and b<>"8" and c<>"4"then
for c=0 to 242
write c,0
next c
..........
..........


Al.

financecatalyst
- 12th October 2009, 03:16
Hi
Thanks for the input.
I wanted to fill the whole eeprom with "0" for the first time before loading any numbers to it, and choose 3 locations which are away from phone arrays and can mark if the code should enter there (first time) or not (anytime after the first time).

I have managed to make it work. I am having problem with receiving string for my sms controller for which I have started another thread. Your input there will be appreciated.
Thanks Again