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.

this is a code that i have for a stop watch using 8051 microcntroller


#include<reg51.h>
#define msec 1
unsigned int sec1,sec2;
int sec1_1,sec1_2,sec2_1,sec2_2;

unsigned int
digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
sbit dig_ctrl_1=P1^0;
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_4=P1^3;
sbit start_pin = P1^4;
sbit stop_pin = P1^5;
sbit reset_pin = P1^6;
int s,t;

void mplex_delay(unsigned int time)
{
int i,j;
for (i=0;i<=time;i++)
for(j=0;j<=50;j++);
}

void digi_out(unsigned int current_num)
{
P2=digi_val[current_num];
mplex_delay(msec);
}

void display(unsigned int dig1,unsigned int dig2)
{
sec1_2=dig1%10;
sec1_1=dig1/10;
sec2_2=dig2%10;
sec2_1=dig2/10;
TMOD=0x01;
TL0=0xFF;
TH0=0xDB;
TR0=1;
while(TF0==0)
{
dig_ctrl_1 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_1);
dig_ctrl_2 = 1;
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_2);
dig_ctrl_3 = 1;
dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;
digi_out(sec2_1);
dig_ctrl_4 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;
digi_out(sec2_2);
}
TR0=0;
TF0=0;
}

code sbit dig_ctrl_1 _at_ 0x0001;
code sbit dig_ctrl_2 _at_ 0x0002;
code sbit dig_ctr1_3 _at_ 0x0003;
code sbit dig_ctr1_4 _at_ 0x0004;

void main()
{
while(1)
{
start:
start_pin = 1;
stop_pin = 1;
reset_pin = 1;
dig_ctrl_1 = 0;
dig_ctrl_2 = 0;
dig_ctrl_3 = 0;
dig_ctrl_4 = 0;
P2 = 0xFF;
s = t = 0;
while(start_pin == 1)
{
display(0,0);
}

stopwatch:
for (sec1=s;sec1<=99;sec1++)
{
if (stop_pin == 0 )
break;
for (sec2=t;sec2<=99; sec2++)
{
if (stop_pin == 0 )
break;
t=0;
display(sec1,sec2);
}
}
stop_pin = 1;
s = sec1;
t = sec2;

while ( start_pin != 0 && reset_pin != 0 )
{
display(sec1,sec2);
}

if (start_pin == 0)
{
goto stopwatch;
}
else
{
if (reset_pin == 0 )
{
s = t = 0;
goto start;
}
}
}
}

in this the section of code:

TR0=0;
TF0=0;
}

code sbit dig_ctrl_1 _at_ 0x0001;
code sbit dig_ctrl_2 _at_ 0x0002;
code sbit dig_ctr1_3 _at_ 0x0003;
code sbit dig_ctr1_4 _at_ 0x0004;

void main()
{
while(1)

the part of storing the values in the 8051 memory starts frm code sbit..... but it shows some syntax error near sbit so if anyone can pls help, it would be greatly apprriciated!!!
 

I don't understand the purpose of this lines
code sbit dig_ctrl_1 _at_ 0x0001;
...

dig_ctrlx has been assigned to P1 bits before.

P.S.: There are no sbit objects in code memory, because code memory isn't bit addressable.
 

basically we want to store the timing values in a register and then do serial communication!

Thanks
 

so wat can we do to address it then?
 

I'm under the impression, that you've copied (and partly modified) a code without understanding it's purpose.

The dig_ctrl1..4 outputs are obviously working as digit enables of a seven-segment display, they are just fine as defined at the top of the code. The code sbit dig_ctrl_1 _at_ 0x0001; and following lines don't make sense in my opinion. If you delete them from the code, it compiles without errors in Keil. I didn't further investigate it's intended operation, but the display driver part involving dig_ctrlx seems reasonable so far.

P.S.: The extra space in this line has to be deleted as well
Code:
digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x1 0};
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top