PDA

View Full Version : Storing data in Pic



Tomexx
- 24th November 2004, 15:19
I'd like to store data in my pic F877A (during RUN MODE) so that after power off it would still be there.

What is the best way (fast,reliable) to accomplish this?
(I hear about EEPROM, FLASH... what are my options)

Thanks,
Tom

mister_e
- 24th November 2004, 16:59
16F877 have an internal eeprom alowing you to store your data.
to write to internal eeprom. Use WRITE and READ instructions from PICBASIC.

If you have a lot of data let's say more than internal F877 one, you can use external EEPROM like 93c46, 24C04, 24LC64 and others.

F877 has internal EEPROM 2K (or 256 * 8bit) lets say 256 allocations space for a BYTE size variable... not too bad

regards¸

Tomexx
- 24th November 2004, 17:18
Thanks mister_e,
One more:
What locations should I be writing too?
For example if I want to store 5 bytes, how would I write that?

mister_e
- 24th November 2004, 17:49
What locations should I be writing too?
For example if I want to store 5 bytes, how would I write that?
you can store at whatever adress you want to ....
let's say you want to store these var

First=1
Second=2
Third=3
Fouth=4
Fifth=5

Usually i start write to address 0
WRITE 0,First
WRITE 1,Second
WRITE 2,Third
WRITE 3,Fourth
WRITE 4,Fifth

when you want to read them back...

READ 0,First
READ 1,Second
READ 2,Third
READ 3,Fourth
READ 4,Fifth

that's it!!

Tomexx
- 24th November 2004, 21:48
Great, it's simple then.

So I guess if you read an address at which nothing was previously stored you should get 0 then, right?

mister_e
- 25th November 2004, 04:29
Usually you will get FF as blank value.

Tomexx
- 25th November 2004, 19:24
Is there a way to check if a memory location has been written?

I want my user to be able to store his program settings in the EEPROM and be able to retrieve them next time the pic powers up.
Example, he stores his password and the program will remember it after power is down. Then on bootup program will check the password, etc.

If FF is the default and you want your program to store some variables (which might happen to be FF) in some memory location then later on there's no way of knowing if the FF at the memory location is an actual data that your program stored or the default that has always been there.

That could get problematic.

I guess you can just store numbers from 0 to FE and check for FF to tell you that a particular location hasn't been written too.

Not a nice way to program but might work. Except for, like you said the FF might be programmer dependant and if you use another programmer which defaults to 0s then you're program's logic has to be changed.

There's gotta be a better way... Please help.

mister_e
- 25th November 2004, 19:37
Hi tomexx,
Usually all programmer must blank with FFs. case not... will not be considered as blank. FF is a safe way to test blank.

BUT be sure your programmer erase EEPROM memory when programming.

To test a password... you can have a maximum lenght of character. when you write it to eeprom use always a fix sized. others unused character in password can be filled with 0s or FF or if you want an special character to gives you the end point of your password. This allows to test password lenght while entering.

regards