#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;
}
#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;
}
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
#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;
}
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.
#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;
}
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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?