Hello ,
If I add this function to my C program:
int key_board() { int a = 0,b = 0,c = 0,d = 0,e = 0,f = 0,g = 0,h = 0; int port = 0,r2 = 0,r3 = 0,r4 = 0,r5 = 0,r6 = 0; LED_R = 0; port = KEY_PORT; a = port & 0x03; if(a == 0) // SJMP no Key { return key = 0; } // Waite: while (b != 0) // { entprell(); port = KEY_PORT; b = port & 0x03; } //START_ZYKLUS: r4 = 0xFE; r1 = 0x00; r2 = PORT_ANZ; //Ribbon_1: while (r2 != 0) { r5 = 0x01; r3 = PORT_ANZ; c = KEY_PORT; c = c | KEY_INIT; // bitwise OR c = c & r4; KEY_PORT = c; //Ribbon_2: while (r3 != 0) { // d = r2; d = d ^ r3; // ^ exclusive OR if(d == 0) { // DIAGO f = r5; f <<= 1; // Shift bit to the left r5 = f; r3 = r3 -1; } e = KEY_PORT; e = e & r5; if (e == 0) { // --> TAZU entprell(); h = KEY_PORT; h = h & r5; if ( h != 0) { return key = 0; } if ( h == 0) { return key = 1; } } r1 = r1 +1; f = r5; f <<= 1; // Shift bit to the left r5 = f; r3 = r3 -1; } // End while(r3 !=0) g = r4; g <<= 1; // Shift bit to the left r4 = g; r2 = r2 -1; } // End while(r2 !=0) return key = 0; }
I get the error message:
*** ERROR L107: ADDRESS SPACE OVERFLOW
SPACE: DATA SEGMENT: _DATA_GROUP_ LENGTH: 001AH Program Size: data=132.0 xdata=0 code=1133
Microcontroller AT89C51RC2 with Flash 32 KB
My compiler: Keil-C with C51.exe
How should I specify the data range in my program ?
Kind Regards
Juergen B.
Dear Juergen,
as you can see in the memory summary, you try to allocate 132 bytes of data memory. An 8051 device only has 128 bytes in total and the stack and the register banks also needs to fit into this internal RAM. You need to move some of your variables into idata or xdata or pdata to free up some data memory. Please see our C compiler manual how to do that (https://developer.arm.com/documentation/101655/0961/Cx51-User-s-Guide/Language-Extensions/Memory-Types). As far as I remember, the AT89C51RC2 has some kb of on-chip xdata RAM, which needs to be enabled in the startup code.
Hans
Hello Hans,
many thanks for your response.
The next morning I also thought about using too many variables.
I actually just did that for clarity.
Based on the variables a - h, I only need the variable a = ACC (Akku), and unsigned char r2- r6.
After using only this variable I can compile my program.
“Program Size: data=115.0 xdata=0 code=932”.
But my program is not finished yet.
The background is: I want to convert assembly code into a C program.
The variables r2-r6 should be used as registers R2-R6, analogous to my assembler program.
Another question: can I also use the registers in my C program?
I will take a look at the reference to the use of the other data types.
Juergen