I am using AT89C51. Due to memory overflow I decided to use XDATA variables. Compilation shows no errors, but when I put the HEX files to the controller it will not work. At the stage where the XDATA variables are used, the system collapses and the giving unexpected results. I am using DS1644 time keeping Ram for external storage and for XDATA. What is the problem with my system. Is it need any internal settings or my controller is not suited for this pupose? Please give me a clue. My code is given below:
char xdata sum[12]; char xdata rtc[21];
when sum or rtc are used the system will give unexpected reults. Please help me.
inspect the memory map!
Will you please hex file for processor for programmer from internet page thank you very much
Ok. Now I modified my code like this:
volatile char xdata sum[12]; But again, this 'sum' not cleared when the program again executing. I actually want to this 'sum' for holding current data. But here the previous data also persists. Is this the problem of initilising. If yes how I can initilise a global variable like this 'sum'. I directly initilised like below, but not working.
sum[]="HELLO";
Erik
My hardware is perfectly Ok, because it is running in assembly code program without any problem. This is actually an old machine and I just took the hardware.And trying to modify and develop the firmware in C language. Now XDATA is OK but can't get initialized. My code is given below: void normalRunning(){ unsigned long int xdata act1,act2; act1+=act2; } act2 is getting from keyboard. when I enter to this function in the next time the previous value of act1 will be there and that value is getting added with the new value.Finally the limit of long int exceed and will collapse. How can I solve this problem. I initialized the variable like this: unsigned long int xdata act1=0,act2=0;
But no use. What should I do?
void normalRunning(){ unsigned long int xdata act1,act2; act1+=act2; } act2 is getting from keyboard. when I enter to this function in the next time the previous value of act1 will be there maybe, but there is no way to state that it IS so.
Please read the instructions on how to post source code: www.danlhenry.com/.../keil_code.png
Note that TABs don't work (well) - use spaces instead,
and don't forget to check it in the 'Preview'...
When you do that, it should look something like this:
void normalRunning() { unsigned long int xdata act1,act2; act1+=act2; }
Don't you get a warning about uninitialised variables here?
You need to go back to your 'C' textbook: act1, act2 are known as automatic variables - and the initial values of automatic variables are undefined.
"Undefined" means that anything can happen: so, if the values just happen to be the same as the last value from the previous call - you can't complain about that.
If you want those variables to start with some specific initial value - such as zero - then you must explicitly provide that initialisation!
This is standard ANSI 'C' - nothing to do with the 8051 or Keil!
No. That is not the problem. I initialized the variables before calling the functionlike this:
int key=0; unsigned long int xdata act1,act2; while(key==0) { act1=0;act2=0; //Here I initialized. void normalRunning() { act1+=act2; } }
THIS IS THE PART OF MY CODE But when I exit from the while loop and then again entering to that, the value of act1 is still there. And is added to the new value of act2.
But one thing I noticed is, when power off all variables are cleared. So thatI can start freshly.
int key=0; unsigned long int xdata act1,act2; while(key==0) { act1=0; act2=0; //Here I initialized. void normalRunning() { act1+=act2; } }
What????? are you declaring normalRunning() inside another function? if act1 and act2 are not define inside a function they are global. This means they will hold there value always.
"THIS IS THE PART OF MY CODE"
No, it clearly isn't - it makes no sense at all!
You need to post the smallest complete example that illustrates the problem!
Showing just a few odd lines entirely out of context gives no information at all - the problem obviously lies in something you haven't shown!
Sorry. That was a mistake when I retyped the code: Actually it was like this:
void normalRunning() { int key=1; unsigned long int xdata act1,act2; act1=0; act2=0; //Here I initialized. while(key!=0) { key=keypress();//This is function to check key //value act1+=act2; //The act2 is calculated from 'key' } }
Here if I called the normalRunning(), the previous value of act1 is still there and is added to new value of act2. What is this?
Here if I called the normalRunning(), the previous value of act1 is still there and is added to new value of act2. This code is completely a small version my code. Still I am getting the same problem.
"That was a mistake when I retyped the code"
No - the mistake was to re-type it at all!
You should never retype code - you are (almost) bound to make some little typo - always use copy-and-paste.
So, if you manually re-typed into that last post, please post again using copy-and-paste.
Anyhow, you haven't shown how act2 gets updated...
void normalRunnig() { char volatile xdata user=0,key=0; char cat,ser; char curr; int up; store cat_rate; unsigned long int volatile xdata find_rate,find_total,find_t1,t2_find,intTax; int volatile xdata k=0,item=0,catcount=1; bit once; user=mode(); if(user==0x55) { item=0; for(k=0;k<10;k++) { write(present[k],"0"); } cat=0x00; key=0x00; while(!(user==0||key==0x64||key==0x33||key==0x32||key==0x31)) { key=keypress(); user =mode(); if(user!=0x55){return;} delay(3000); now(); display(rtc,4); cat=(key&0x0f)-0x01; if(!category[cat]) {key=0x00; continue;} } clear(); display(category[cat],1); once=1; find_rate=0;find_total=0;find_t1=0;t2_find=0; while(key!=0x43) { display("Select the category ",2); display(" to issue ticket ",3); if(!once) {display("Total Rs: ",4); cat_rate=read(sum_all); place(cat_rate.mem,0xdd); } key=0x00; while(!((key&0xf0)==0x30||key==0x43)) { key=keypress(); delay(300); ser=(key&0x0f)-0x01; if(!services[ser]) {key=0x00; continue;} } cat_rate=read(present[ser]); if(atoi(cat_rate.mem)!=0&&key!=0x43) { clear(); display(" Service Already",2); display(" Selected ",3); delay(30000);delay(30000); clear(); display(category[cat],1); display("Select the category ",2); display(" to issue ticket ",3); if(!once) {display("Total Rs: ",4); cat_rate=read(sum_all); place(cat_rate.mem,0xdd); } key=0x00;continue; } if(key==0x43) continue; key=0x00; ask_rate(category[cat],services[ser],"No.of Tickets :"); write(present[ser],sav); cat_rate=read(rate_mem[ser][cat]); pntLesStr(cat_rate.mem); find_rate=atol(cat_rate.mem); t2_find=find_rate*atol(sav); find_total+=find_rate*atol(sav); find_t1=find_total; for (k=8;k>=0;k--) { show_total[k]=(find_t1%10)+0x30; find_t1=find_t1/10; } for(k=0;k<=8;k++) { if(show_total[k]==0x30){show_total[k]=0x20;} else{break;} } show_total[9]='\0'; pointStr2(show_total); write(sum_all,show_total); for (k=8;k>=0;k--) { show_total[k]=(t2_find%10)+0x30; t2_find=t2_find/10; } for(k=0;k<=8;k++) { if(show_total[k]==0x30){show_total[k]=0x20;} else{break;} } show_total[9]='\0'; pointStr2(show_total); write(tot[ser],show_total); display("Press PRINT to issue",2); display(" Ticket or OK ",3); display(" To continue ",4); key=0x00; while(!(key==0x61||key==0x43||key==0x51)) { key=keypress(); delay(300); } if(key==0x51) {clear(); find_total=0; cancel();} else if(key==0x43) continue; else if(key==0x61) {clear(); while(!(key==0x43||key==0x51||key==0x61)) { display("PRINT: To Print TKT ",1); display(" OK : To Continue ",2); display(" C : To CANCEL ",3); key=keypress(); delay(300); } } if(key==0x51) {clear(); find_total=0; cancel();} else if(key==0x43) continue; else once=0; } } else return; }
This is the complete function. Here the problem will come with the 'find_t1'. Its value is not cleared until power is off. Can I declare variables like this? or problem is in another part?(ie, concepts that unknown to me)
What is wrong with using large model. When I used that compiler shows no error.But hardware not working. I am using AT89C51 controller and external time keeping ram (DS1644)for XDATA. Also uses 27SF010(EEPROM from SST) for code storage. Also I chaned the settings of the compiler as below:
1. in startup.a51:
IDATALEN EQU 100H XDATASTART EQU 0H XDATALEN EQU 2E4FH PDATASTART EQU 0H PDATALEN EQU 100H
2. in project settings: memory model: large variables in xdata off chip xdata memory: 0x0000- 0x113F
3. Device selected:
At89C51
4. Xtal: 16.0
compiler shows 0 errors and 0 warnings. program size:data=30.2 xdata=76 code 15530
Is this need any other settings to use large model ?