Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/03/09 09:25
Read: times


 
Msg Score: -1
 -1 Answer is Wrong
#166697 - Some possible answers..Munish
Responding to: ???'s previous message
Hi Munish,
Here are the possible answers:
Munish Kumar said:

1) How to allocate 504 Bytes in RAM? I tried unsigned char image_buffer[504] but it says error C249: 'DATA': SEGMENT TOO LARGE (for any array >128 Bytes)


Remember for MCS51 using Keil:
RAM usage is totally dependant upon the number and type of variable(s) you have defined.
Stack is an important place that is initialized by Keil. Preferably at Address:0x80 for MCS51 having RAM>=256 bytes. Stack uses uses RAM:0x80~0xFF.
So 89S52 has 256 bytes of RAM, 128 are gone for Stack, that leaves 128 bytes for your variables.
"Char" takes 1 byte, "int" takes 2 bytes...etc.

Now you can think your declaration:
unsigned char image_buffer[504]
where will it be stored?...so no memory left. You have less than 128 bytes left. So that answers the error message.


Munish Kumar said:

2) The max array size of image_buffer is 112 Bytes. The corresponding build O/P is:
Program Size: data=129.0 xdata=0 code=1502
creating hex file from "nokia3310"...
"nokia3310" - 0 Error(s), 0 Warning(s).
If I try unsigned char image_buffer[113], address space overflows. So what is this 'data' & where is it stored? In RAM?

When you specify any variable as char, int long, float, double it is in RAM (also called as Data Memory) If you initialize it as "xdata char", "xdata int", etc. they are allocated a space in the XRAM. Now this XRAM can be physical external RAM mounted on the board alongwith MCS51 or some flavours of MCS51 have internal XRAM. Anyway, internal XRAM or External XRAM, variables defined with xdata are defined in XRAM area.
You can steal some memory from stack(128 bytes) by declaring the variable as "idata char",etc. But do not use more number of varibales for idata. It might cause insufficient area for stack and your product software will crash. If you are novice: Try to avoid "idata" as much as possible.



Munish Kumar said:

3) This problem is there irrespective of using 89S52 or 89V51RD2! So where is the difference in available memory if address space overflows for same array? How can I use the extra RAM of RD2?

Look into the data sheet of 89V51RD2, look at the amount of internal XRAM it has. Well you have to play within that amount of RAM. To define a variable in this XRAM, define it as "xdata unsigned char image_buffer[xxx]'. If you feel that 504 bytes will not fit, in 89V51RD2, then look out for some another flavour of MCS51 that has more amount of Internal XRAM.
I could have answered your question directly, but I want you to read the datasheet. I have shown you the way...now walk!!!






List of 14 messages in thread
TopicAuthorDate
How to use on-chip RAM for array storage in Keil?            01/01/70 00:00      
   Basics: 8052 Memory Spaces            01/01/70 00:00      
      The message doesn't exist            01/01/70 00:00      
   data, xdata            01/01/70 00:00      
      Incorrect            01/01/70 00:00      
         Getting it now....            01/01/70 00:00      
            Not quite            01/01/70 00:00      
               I got it completely now!            01/01/70 00:00      
   Some possible answers..Munish            01/01/70 00:00      
      Thanks!            01/01/70 00:00      
      "RAM" and "Data Memory" are not synonymous            01/01/70 00:00      
         Agreed            01/01/70 00:00      
      NO WAY            01/01/70 00:00      
         Thanks for correcting me            01/01/70 00:00      

Back to Subject List