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.
TechToys said:
Hi Help
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.
John

The answer is a simple NO

You can not use xdata if you do not have ram physically in xdata space.

I wrote earlier that you can use a derivate which has a little bit of xdata ram internally for example 1K.

So again if your cpu does not have external ram you can NOT use xdata.

hope this helps
 

    Help

    Points: 2
    Helpful Answer Positive Rating
C-Man said:
So again if your cpu does not have external ram you can NOT use xdata.

Got abit confuse, which mean the AT89C52 don't have external ram. So that we cant use xdata on our code right?

But we still can get the practical result :!:

Thank You
 

I think the compiler has no way to know if there is a hardware xRAM or not. The declaration xdata unsigned char a[50] is correct in terms of its syntax, but it doesn't mean to give the result as expected. So does the result of simulation.

John
 

    Help

    Points: 2
    Helpful Answer Positive Rating
i think when you use xdata, MCU use P0 and try to control external RAM and you can't use P0, if have a opportunity use another port for leds. usualy i use P2 for leds , when have more leds i make a simple module with 74hc595 for shifting.
my last project was with 80 groups of led:))
89x51 have 128 bytes internal RAM,
89x52 have 256 bytes internal RAM.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

Any conclusion? with xdata without xdata what were happen in practically? My LED still working fine! Only we need to play around the core!

Anyone can make me clear? Me got abit blur :|

Thank You.
 

What I meant in previous messages is that, even though it is possible to declare xdata variables like :

xdata unsigned char a[], the code

a = 1; would not allocate the value of 1 to a because a doesn't exist (no x RAM for the hardware).

LED still flashes (via code 'countNum = count')doesn't imply value allocation by the code a is successful. LED flashes since the code executed anyway when the line executed

countNum = count => P0 = count.

John
 

Hi,

According what we discuss early. The P0 is used for addressing when xdata =1 executed so we exclude the a and put it behind of P0=count to flash the LED.

TechToys said:
a = 1; would not allocate the value of 1 to a because a doesn't exist (no x RAM for the hardware).


I am using AT89C52 it doesn't have x RAM! So, if i declare the a[] as

xdata unsigned char a[];

Is it any problem on that? Got any issue on that, what will happen if i run my code in practically? Is it i can't get the a[] data?

Thank You
 

I am using AT89C52 it doesn't have x RAM! So, if i declare the a[] as

xdata unsigned char a[];

Is it any problem on that?

The code above is like firing an empty gun. You still can pull trigger on a gun without bullet. Yes, it triggers, but there is nothing coming out of the gun. The gun have no way to know if you have loaded it or not.

Know what I mean?

John
 

Haha...you mean my xdata declaration still can work on my code and the code still working fine but on my controller don't have this data on memory?

Mean will loose some function when i run my uController, do you mean that?

Thank You
 

Haha...you mean my xdata declaration still can work on my code and the code still working fine but on my controller don't have this data on memory?

Yes. The program compiled just because the compiler has no way to tell if you have wired an xRam with the mcu. So, the code a=10 won't store the value of 10 to the array a because there is no physical ram space for that array.

However, when the code a=10 executed, it does change P0 so as to enable addressing for that code line in order to execute the code for a=10. That means, if you had an actual physical external ram wired to Port 0 together with proper RD/WR signal, you could have written a value of 10 to that array inside that piece of RAM (can be a dip 28 IC, say). That is also the reason why when this code is placed just below the code for LED flashing, no LED flashes as expected because it changed P0 structure right away.

Therefore, if you want to continue using the same code with declaration xdata unsigned char a[], and use that array for other functions or tasks, those functions would not do what you want.

Say, if you write :

if(a[10]==10)
//LED blinks at a rate of 100Hz.

The code above will not run even though it is correct in terms of its syntax(grammer correct). and complied

By the way, are U sure only necesary data placed in RAM? Sometimes we may use keyword code for storing unchanged data.

John
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

Actually i got 30 input signal, each input state i need to record either '0' or '1' in the array and then compare it. While i need to do comparison i need 2 array 1st is NewArray[30] another is OldArray[30]. if(NewArray[1] == OldArray[1]) is true then i need to do some function.

I think my data will always changing and my data show in compiler is nearly full and the total array size i need is 60. This will bring a problem to me :cry:

Is it only 2 way that i can do one is change the uC as C-MAN say Philips 89C51RA2 to 89C51RD2 another one is put xRAM?

So, is it i can't do anything on my AT89C52 already? :cry:

Help...

Thank You
 

Help,

if i understand you correct you have 30 inputs signals connected to your 8051 and want to check if some signal changed state?

You could try this simple method:
use one unsigned char variable for 8 signals (one PORT) and again one unsigned char variable for the previous state of these 8 signals.

All you need to do is an XOR operation on the two variables and you will know which signal(s) changed.

So for 30 (32) signals you would need 8 unsigned char variables instead of 60 :D

You need a little bit more code but much less variable space ...

hope this helps
 

    Help

    Points: 2
    Helpful Answer Positive Rating
The 89C52 has 256 bytes of internal RAM .. If the lower half - directly addressed - is not sufficient why can't you use the upper half (128 bytes) .. after all, as you say, you need only 60 bytes ???

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

C-Man said:
You could try this simple method:
use one unsigned char variable for 8 signals (one PORT) and again one unsigned char variable for the previous state of these 8 signals.

Not so understand. Please can explain more detail? Can you show me the design in drawing or what ever to make it clearly?

C-Man said:
All you need to do is an XOR operation on the two variables and you will know which signal(s) changed.

I get what you mean here use XOR operation to do chacking.

Thank You



Ianp said:
is not sufficient why can't you use the upper half (128 bytes) .. after all, as you say, you need only 60 bytes ???

Now my data roundly ~200bytes, after i add the array then the compiler will show OVERFLOW...

What can i do?

I haven't try yet, declare the array as xdata and try to run on practical see what result will comeout.

Thank You.
 

Array declaration like:

unsigned char a[30] allocates thirty bytes in data space.

1 byte = 8 bit of the format 0bxxxxxxxx, for example, it could be 0b10010010 (say).

If a comparison of only an open / close circuit required, it may be possible to shift in inputs for all switches, and use individual bit for each switch detect.

So, 30 switches -> 30 bits. To compare 30%30 switches, 60 bits required. For whole number of bytes, 64 bits required. That is to say, 8 bytes for comparison.

John
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

How to use individual bit for each switch?

On hardware side what can we do, i only least 1 PORT? and

the code there we can do is 0b10010010 XOR 0b10010110 =>0x92 XOR 0x96 = 0x04, so we know the bit 4 is changing state but how bout next byte and so on?

Thank You.
 

If you need to monitor 30 switches and there is only one port left, why not to add port expanders ..

There are two options: seral or parallel ..

Serial: PCF8574 - it has I2C interface, and without complicated address decoders you can connect up to 8 of these devices, each has 8 pin I/O port ..
**broken link removed**
Also, it has an interrupt, which is generated by any rising or falling edge of the
port inputs in the input mode ..

Parallel: 82C55 - this one will require 74373 address latch, but in the same time you can connect an external RAM (if you need one) ..
The 8255 has 3 x 8-bit port = 24 I/Os ..
http://www.diamondsystems.com/files/binaries/har82c55.pdf

Regards,
IanP
 

Help

can you please specify what you want to do exactly?

Do you want to check 30 switches and only have port1 available?

It would be a good idea to post your circuit diagram so others who want to help can see what you already have.

best regards
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Hi,

Actually my P1, P2, P3 already full of used! and not enough I/O!

Bellow is my temporary design. I am using 2 multiplexer to get 30 input signal.

Is there any easiest design?

The Port0 LowerBit control 1st Multiplexer and HigherBit control 2nd Multiplexer. I get the signal from Multiplexer pin1. Then do comparing 30 times.

Thank You
 

Of course you can use multiplexers and scan all inputs several times per second ..
However, the PCF8574 IC I suggested in my previous post has the interrupt output that allows you to act only upon any change and do nothing if no interrupt is generated .. no loops, no endless scanning!!!
Building a local I2C bus would have another adventage: you can have up to 8 x 8 inputs (= 64) connected to only 5 microcontroller pins: one pin as SDA (data), one pin as SCK (clock) and 3 pins as A0, A1 and A2 (address) ..
But, whether it is better for you, or not, I don't know - I am not in your shoes ..

Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top