Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to store values in code memory of 8051 and secure it with password?

Status
Not open for further replies.

Th3r4p1sT

Junior Member level 1
Joined
Dec 20, 2010
Messages
15
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Activity points
1,410
i m working on a project with 8051.

my problem is how to store some datas in memory...

a passwoed for example,
i store a defult value for the password when i programming.
and i want the user can change the password.
but if the user shuts down the device or if the electricity goes.
then the user works the device again, the password will take the default value again.

how can i solve this?
im using C language with keil.

i cant store any values in code memory. can the data memory remember the value?

Where is the 8051's static memory?

i want to select an address an store the password there. and i wont use a default value.
But the problem is which memory of 8051 should i use, and how can i use it.
 

Re: using 8051 help plss

Witch manufacturer 8051 core are you using ?
Some types have internal static EEPROM DATA memory that allow save this.

For example, AT89C51RD2 ( from ATMEL ) is an excelent choice to work.

+++
 

Re: using 8051 help plss

24c02 eeprom interfacing with 89c51 will solve your problem
i think AT89C51RD2 costly than 89c51+24c02 choice is yours
 

Re: using 8051 help plss

you can use _AT_ command in C to store the data in required memory location, not where the compiler wants it to be stored.

type [memory_space] variable_name _at_ constant;

As is normal for Keil C, if the memory space specifier is missing the default memory space as determined by the selected memory model is used. Thus if you are compiling using the small memory model the variable will be allocated in the DATA segment.

unsigned char data byteval _at_ 0x32;
 
Re: using 8051 help plss

you can use _AT_ command in C to store the data in required memory location, not where the compiler wants it to be stored.

type [memory_space] variable_name _at_ constant;

As is normal for Keil C, if the memory space specifier is missing the default memory space as determined by the selected memory model is used. Thus if you are compiling using the small memory model the variable will be allocated in the DATA segment.

unsigned char data byteval _at_ 0x32;

Thanks for helping..
i tried ur code but the following error occured:
BISIKLET.C(14): error C274: 'byteval': absolute specifier illegal

i used some other codes.

DBYTE [0x0002] = 5; // write/read 5 in data segment into 0002h address
Oku = CBYTE [0x0002]; // read from 0002h address from code segment

as seen i cant store a value into code segment. i dont know how to.
another point i dont know is;
Can data segment save this value permanently? because i can both write and read any address from there.
The data that i dont want to forget are not more than 20-30 bytes

İf data segment save those permanent i will use it.

---------- Post added at 10:31 ---------- Previous post was at 10:24 ----------

i forget to say DBYTE,CBYTE,XBYTE and PBYTE codes are defined in a header file.

absacc.h
#define CBYTE ((unsigned char volatile code *) 0)
#define DBYTE ((unsigned char volatile data *) 0)
#define PBYTE ((unsigned char volatile pdata *) 0)
#define XBYTE ((unsigned char volatile xdata *) 0)

#define CWORD ((unsigned int volatile code *) 0)
#define DWORD ((unsigned int volatile data *) 0)
#define PWORD ((unsigned int volatile pdata *) 0)
#define XWORD ((unsigned int volatile xdata *) 0)
 

Re: using 8051 help plss

that is for storing in RAM,
If you want to store in code memory then the keyword is CODE

eg unsigned int code unit_id[2]=1234;

unsigned char data byteval _at_ 0x32; data ( memory location), byteval - any variable name followed by a space then _at_ try this

For any help refer the help in keil it has all information.
The best option is to download the BIBLE BOOK "FINAL WORD ON 8051" from google
 

Re: using 8051 help plss

eg unsigned int code unit_id[2]=1234;
i did this. it can store 1234 to code segment. but i dont now its address. and every start up the address of unit_id[] will change.
And if i use this code, program will change the value with 1234 while starting up.
i wanna select an address and when program starting up i will check that address, if there is no value, i will store 1234 value into there as password. when user wants to change the password i will change the value thats in that address.

well can i select an address in code segment and can i store a value into there? eg.
i wanna store a byte to FFF0 address in code segment. is it possible?

unsigned char data byteval _at_ 0x32; data ( memory location), byteval - any variable name followed by a space then _at_ try this

For any help refer the help in keil it has all information.
The best option is to download the BIBLE BOOK "FINAL WORD ON 8051" from google

unsigned char data th3r4p1st _at_ 0x34;
char: the type of variable th3r4p1st.
data: the data segment of 89c51rd2
_at_ : keil dont know this so ' 0x34 ' isnt knew by keil.
but this code dont work. :( always says the same error. BISIKLET.C(14): error C274: 'th3r4p1st': absolute specifier illegal

i just the book u said. hope it can help me :D thanks.

---------- Post added at 13:26 ---------- Previous post was at 13:16 ----------

i searched the error in google. and i solve it. i must define the variable outside of main :D it dont error now.
i wrote code char th3r4p1st _at_ 0xF0; outside main and it compiled.

And i wrote th3r4p1st = 0x12;
well another error says me i cant do this: BISIKLET.C(13): error C183: unmodifiable lvalue
 

Re: using 8051 help plss

follow this

struct link {
struct link idata *next;
char code *test;
};

struct link idata list _at_ 0x40; /* list at idata 0x40 */
char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */
int xdata i1 _at_ 0x8000; /* int at xdata 0x8000 */
char far ftext[256] _at_ 0x02E000; /* array at xdata 0x03E000 */

void main ( void ) {
link.next = (void *) 0;
i1 = 0x1234;
text [0] = 'a';
ftext[0] = 'f';
}

and refer this it will surely help you

Cx51 User's Guide: The _at_ Keyword
 

Re: using 8051 help plss

follow this

struct link {
struct link idata *next;
char code *test;
};

struct link idata list _at_ 0x40; /* list at idata 0x40 */
char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */
int xdata i1 _at_ 0x8000; /* int at xdata 0x8000 */
char far ftext[256] _at_ 0x02E000; /* array at xdata 0x03E000 */

void main ( void ) {
link.next = (void *) 0;
i1 = 0x1234;
text [0] = 'a';
ftext[0] = 'f';
}

and refer this it will surely help you

Cx51 User's Guide: The _at_ Keyword

this explains me the _at_ keyword also i knew .d
there are some errors course

i havent try my codes on a real at89c51rd2 chip. just in proteus up to now.
tomorrow i will try some codes at faculty's lab. on real chip. and i will shut down chip. then i will start and see. will the memory forget my value .

i will do a counter, with a button i will send signals to chip. and will save the last value into data segment.
after a while it counted how many times i pushed button. i will shut down and start again. i will try this for all memory segment.
After all, i will see which memory segment will remember the last value.

Also i will ask my problem to keil soon.
 

Re: using 8051 help plss

i was trying for a week. but no step i took.
i saw many sources. and i found some helps.

Keil clears all memory spaces with the file "STARTUP.A51" when start up the device.
Somebodies told that if i modify this file as i want, keil will not clear the memory while starting up.

But nobody told how to do it. :D
which changings should i do? if anybody knows, please helpp...
 

When you create a new project, it will ask you add new if you want to add the startup code, where we say no usually( add the startup code) open it and modify it. but be careful . you should have a very good knowledge of the architecture to change it.
 

When you create a new project, it will ask you add new if you want to add the startup code, where we say no usually( add the startup code) open it and modify it. but be careful . you should have a very good knowledge of the architecture to change it.

:) But i dont have knowledge about changing it.
i copy the STARTUP.A51 file under C51/LIB. and paste under my project directory. And i add that file to my source group. i want to modify it.
my problem is: Which changings should i do.
 

I'm under the impression, that there are some misunderstandings involved. The startup code will never clear data stored in flash or eeprom memory area. So you definitely don't need to modify the startup code.

I understood, that you intend to assign the non-volatile storage to xdata at 0xE000, but it would refer to external RAM, not flash memory. The 89C51RD2 EEPROM can be in contrast mapped to xdata using control bits in EECON SFR. The method is desribed in chapter 23 of the datasheet.
 

I'm under the impression, that there are some misunderstandings involved. The startup code will never clear data stored in flash or eeprom memory area. So you definitely don't need to modify the startup code.

I understood, that you intend to assign the non-volatile storage to xdata at 0xE000, but it would refer to external RAM, not flash memory. The 89C51RD2 EEPROM can be in contrast mapped to xdata using control bits in EECON SFR. The method is desribed in chapter 23 of the datasheet.

i looked at chapter 23 in datasheet. but, it describes; how to write or read external eeprom.
It dont help me about removing the power :D
if i remove power, all my data loses.
Thanks for helping. if u have any idea, please share.
 

i looked at chapter 23 in datasheet. but, it describes; how to write or read external eeprom.
It's actually talking about the internal EEPROM of AT89C51RD2
It dont help me about removing the power :D
There are apparently more misunderstandings. Referring to your original questions.
i cant store any values in code memory. can the data memory remember the value?
Where is the 8051's static memory?
The data memory (=RAM) is volatile unless you provide a power supply with a backup battery. As an alternative, various contributors suggested to use 8051 internal flash or EEPROM, which requires a processor, that has either self-rewritetable flash or internal EEPROM. AT89C51RD2 has both types of non-volatile memory. But either of them can't be written as easy as regular data memory, they require special code to interface it.
 

It's actually talking about the internal EEPROM of AT89C51RD2

There are apparently more misunderstandings. Referring to your original questions.

The data memory (=RAM) is volatile unless you provide a power supply with a backup battery. As an alternative, various contributors suggested to use 8051 internal flash or EEPROM, which requires a processor, that has either self-rewritetable flash or internal EEPROM. AT89C51RD2 has both types of non-volatile memory. But either of them can't be written as easy as regular data memory, they require special code to interface it.

First i was looking for how to store values to code memory. But i learned that writing to code memory is limited.
Than im searching how to keep my data when the power removed.
So now it is not imported for me that which memory spaces i store into.
the impoerted thing is, can the device keep a few of my data when power removed.
if any memory segment can, i will use. or i will place a non-volatile memory device on to my ocb.
 

So now it is not imported for me that which memory spaces i store into.
Quite reasonable. With AT89C51RD2 and many other recent 8051 variants, internal EEPROM is most convenient way, the said chapter tells how to. A classical 8051 chip would need external EEPROM and some code to drive it.
 

Quite reasonable. With AT89C51RD2 and many other recent 8051 variants, internal EEPROM is most convenient way, the said chapter tells how to. A classical 8051 chip would need external EEPROM and some code to drive it.

i dont know how to use that eeprom.
i did many tryings during to datasheet sayings. but any of them didnt work. or i couldnt.

is there anybody help me about codes?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top