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.

AT89C52 Port0 got problem!!

Status
Not open for further replies.

Help

Advanced Member level 2
Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
Hi,

Anyone can help me the code below:

Code:
#include <reg52.h>

#define countNum P0

xdata unsigned char a[40];//'xdata'will couse the P0 problem.Why?? If P1 OK!

void Deley(unsigned int Dly)
{
	int i, j , k; 
	for( i=0; i<255; i++)
	{
		for( j=0; j<Dly; j++)
		{
			for( k=0; k<1; k++);
		}
	}
} 

void Run(void)
{
	static unsigned char count;

	if(count<16)
	{
		countNum = count;
		a[count] = 1;
		count++;
	}
	if(count>15)
	{
		count = 0;
	}
}

void main()
{
	while(1)
	{
		Run();
		Deley(100);
	}
	return;
}

I am using AT89C52 microcontroller.

Why after i declare the array a as 'xdata' the Port 0 will not functioning. After remove the 'xdata' then the Port 0 will working fine. It functioning on Keil Simulation but on practically it doesn't work but it can functioning on Port 1. Why? Is it anything wrong on my code? Anything i can do? Anyone can help me and test it?

Thank You.
 

P0 is used for external data , when you declare xdata it take P0 for comunication with external data source.
Try to declare with "code" not "xdata" it mus work the code declaration will plase variables in flash memory, data -> Ram , Xdata ->external memory

regards :)
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

After i changed it to
Code:
code unsigned char a[40];
, and after compile it show the error:unmodifiable lvalue. :cry:

What can i do?

Thank You
 

"static unsigned char count;"

remove static
 

    Help

    Points: 2
    Helpful Answer Positive Rating
@Help,

your code can not work as P0 is used as data/address bus for external ram when you declare your variables as xdata.

Try to declare your array as data or idata ...

data unsigned char a[40];
idata unsigned char a[40];

Also see the 8051 manual for details:
Port 0 is an 8-bit open drain bi-directional I/O port. As an
output port, each pin can sink eight TTL inputs. When 1s
are written to port 0 pins, the pins can be used as high-impedance
inputs.
Port 0 can also be configured to be the multiplexed low-order
address/data bus during accesses to external
program and data memory. In this mode, P0 has internal
pull-ups.
Port 0 also receives the code bytes during Flash program-ming
and outputs the code bytes during program verifica-tion.
External pull-ups are required during program
verification.

best regards
 

    Help

    Points: 2
    Helpful Answer Positive Rating
yes i think with data will work, code is unwritalble. He can you some pointers to flash
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

Thank for your help.

If let say my array size is 250 ( a[250] ), i need to shift the data to xdata other wise my data will full! I am using AT89C52, what can i do? and the I/O for P1, P2, P3 already fully used.

Thank You
 

you can put external eeprom and write tha data there, but this is a little slowly. you can use P0 with external pullups. if you want to use P0 as output just put in the beging of program simple functio:

void Port_Init(void)
{
P0 = 0x00;
}

it mus work

regards
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

Do you mean that?

Code:
#include <reg52.h> 

#define countNum P0 
xdata unsigned char a[250]={0};

void Deley(unsigned int Dly) 
{ 
   int i, j , k; 
   for( i=0; i<255; i++) 
   { 
      for( j=0; j<Dly; j++) 
      { 
         for( k=0; k<1; k++); 
      } 
   } 
} 

void Run(void) 
{ 
   unsigned char count; 

   if(count<16) 
   { 
      countNum = count; 
      a[count] = 1; 
      count++; 
   } 
   if(count>15) 
   { 
      count = 0; 
   } 
} 

void Port_Init(void) 
{ 
	countNum = 0x00; 
} 


void main() 
{ 
	Port_Init();

	while(1) 
	{ 
		Run(); 
		Deley(100); 
	} 
	return; 
}

Thank You.
 

Help said:
Hi,

Thank for your help.

If let say my array size is 250 ( a[250] ), i need to shift the data to xdata other wise my data will full! I am using AT89C52, what can i do? and the I/O for P1, P2, P3 already fully used.

Thank You

You can try using an 8051 derivate with for example 1k internal xdata ram like Philips 89C51RA2 to 89C51RD2.

It is fully pin compatible and as long as you do not need more then 1K of xdata space you can use all 4 ports :D

best regards
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

I will try to use syrax method.
Actually what is the xdata size for the AT89C52.

Without changing my AT89C52 is it any alternative way to solve this problem?


Thank You.
 

another way is to use structure of variables but i am newby in this :))) i only know oyu can declare a unio structure of data

and manage it by pointers this is inly what i know. ask someone to explane you thsi type of data i have a PDF if you want i will send you there is a samples with this type of data declaration
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Add external pullup resistors ( 8 x 10kΩ will do ) - without them you can't use PORT0's pins as general purpose I/Os, as there is nothing to give you a "1" ..

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

Ya, i already connected pullup resistor which is 8 x 10kOhm but the array i declare as 'xdata' will make the PORT0 problem (use LED to simulate the output result, the 8xLED blinking at the same time but not a actual result that we want!!).

After remove the xdata then function well already but my data already full!

and i already try syrax method add

void Port_Init(void)
{
P0 = 0x00;
}

but still not functioning!

Thank You
 

Hi

Try putting a[count]=1 above countNum=count. Like code below, and the compile result is:

data =10.0 xdata=40 code=107, compiled under demo version of Keil C 7.09

Code:
#include <reg52.h> 

#define countNum P0 

xdata unsigned char a[40];//'xdata'will couse the P0 problem.Why?? If P1 OK! 

void Deley(unsigned int Dly) 
{ 
   int i, j , k; 
   for( i=0; i<255; i++) 
   { 
      for( j=0; j<Dly; j++) 
      { 
         for( k=0; k<1; k++); 
      } 
   } 
} 

void Run(void) 
{ 
   static unsigned char count; 

   if(count<16) 
   { 
      a[count] = 1; 
      countNum = count; 
      count++; 
   } 
   if(count>15) 
   { 
      count = 0; 
   } 
} 

void main() 
{ 
   while(1) 
   { 
      Run(); 
      Deley(100); 
   } 
   return; 
}

I did use a demo board to see the result! It runs. The LEDs flash as a binary counter, right?

Though it runs, I do have some question out of curoisity:

Are U using external RAM? If not, why to declare xdata? xdata uses port 0 for addressing. If you are not using external RAM, it seems wired for a[count]=1 statement.

John

8051 boards, ARM boards, and much more at
www.TechToys.com.hk
 

    Help

    Points: 2
    Helpful Answer Positive Rating
TechToys said:
I did use a demo board to see the result! It runs. The LEDs flash as a binary counter, right?
Are U using external RAM? If not, why to declare xdata? xdata uses port 0 for addressing. If you are not using external RAM, it seems wired for a[count]=1 statement.

Hi,

Thank you for SOLVED my problem.
Ya, the LEDs flash as a binary counter.
I not using any hardware external RAM. I just want to use PORT0 as normal I/O. Because of my data already full nearly around ~200 so, if i not shift the array to xdata then i might got memory problem right?

Why we need to put the Array in front of PORT0 then it will work, do you got any idea?

and i try to play around the Array again, i think roughly this problem also.

Code:
#include <reg52.h> 
#define countNum P0 
xdata unsigned char a1[50],a2[50];//'xdata'will couse the P0 problem.Why?? If P1 OK! 
void Deley(unsigned int Dly) 
{ 
   int i, j , k; 
   for( i=0; i<255; i++) 
   { 
      for( j=0; j<Dly; j++) 
      { 
         for( k=0; k<1; k++); 
      } 
   } 
} 

void uBuf(unsigned char B)
{
	unsigned char Buffer[32];

			Buffer[B] = 1;
}

void Run(void) 
{ 
   static unsigned char count1, count2, count; 

/********** Test A *****************/
    if(a1[count] != a2[count]) // compare the array and store in the new elements
	{
		uBuf(count);
		a2[count] = a1[count];
	}
/***********************************/
    if(count1<16) 
    { 
       a1[count1] = 1; 
       countNum = count1; 
       count = count1++; 
    } 
    else if(count2<16) 
    { 
       a1[count2] = 1; 
	   countNum = count2<<4; 
       count = count2++; 
    }// end else if 

/***** If Test-A put after the end else-if then same problem comeout again *****/

    if(count2>15) 
    { 
       count1 = 0; 
	   count2 = 0;
    } 
} 

void main() 
{ 
   while(1) 
   { 
      Run(); 
      Deley(100); 
   } 
   return; 
}

If the Test-A put after else-if got problem, in front of if(count1<16) will working fine! :!:

Thank You.
 

I not using any hardware external RAM. I just want to use PORT0 as normal I/O.

If you are not using a piece of silicon as an external RAM, only using the keyword xdata is useless for data storage. If there is only 256 byte RAM, using xdata cannot make it 512byte RAM, right?

P0 is used for addressing when xdata =1 executed. That means P0 will output the address in order to execute the code xdata=1. It seems that if you place this line just below the line countNum = count, you are changing P0 for xdata=1 right after you have put variable 'count' to P0 which you want to see the LED lites in a certain pattern.

That is what I see for the problem.

Pls comment.

John

8051 boards, ARM boards, and much more at
www.TechToys.com.hk
 

i will repeat all in one place :))

1.Xdata is declaration for external memory !!!!
2.You MUST put pullup resistor on P0 becouse it haven't internal pullups like other ports
3.You must put 0 on P0 in the begining to work like output

when this 3 rules are OK -> your circuit will work normal

if you had problems post you circuit and tell what it must do :)) and then we will make a program together :))

REGARDS
 

Hi,

If you are not using a piece of silicon as an external RAM, only using the keyword xdata is useless for data storage. If there is only 256 byte RAM, using xdata cannot make it 512byte RAM, right?

Just now i already tried the xdata max can reach to 65535. Is it the propare way that i do that? shift the data to xdata!

P0 is used for addressing when xdata =1 executed. That means P0 will output the address in order to execute the code xdata=1. It seems that if you place this line just below the line countNum = count, you are changing P0 for xdata=1 right after you have put variable 'count' to P0 which you want to see the LED lites in a certain pattern.

Thank for your explanation. I think i understand what you going to tell me but i still new in microcontroller and i not deeply play around the memory part yet. Thank for your good infor.

But just now i posted the code "Test-A" do you got any idea?

Thank You

Added after 26 minutes:

Hi,

My design nothing much, output just connect with 8 LEDs only. Thank for your support.

Thank You.
 

Hi Help

Yes, I used the same schematic to test out your program this morning. Using 470 ohm resistors for current limiting, pullup Port0, then connect cathode of the LEDs to P0-P3.

Sorry, I didn't take much attention to code "Test A" because I think, there was a concept unclear.

The question is:

Do we get data RAM larger than 256Mbyte by declaring data to be xdata alone?

Data sheet on 89S52 states that there is 256MB RAM on-chip. Without external RAM chip, do we get data ram more than that by declaring

xdata unsigned char a[50]?

If we can answer this question, we would solve the problem, I think.


We all learn at the end.

John
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top