We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear All,
In the below program, main function calls "yaz" function 10 times. it works fine without any problem with the global variable definition marked as "bold" "unsigned char i" altough it is not used in the program. When I ignore or delete this definition line, "yaz" function enters endless loop and never returns to main program. Any idea what the problem is about? regards. akif
#include <reg51rd2.h> unsigned char data gdeger[8]; //unsigned char i; unsigned char code rakam[10][8]= { {0x00,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00}, [..] Data lines deleted for proper format [..] }; void bekle(unsigned char j){ unsigned char i; for (i=1; i<=j; i++){ TMOD =0x01; TH0 = 0xFE; TL0 = 0x00; TF0 = 0; TR0 = 1; while (TF0 == 0); TR0 = 0; } }//bekle void yaz (unsigned char gonder[]){ unsigned char row; unsigned int col; unsigned char i; unsigned char n=7; //sola kaydırma miktarı unsigned char sdeger; unsigned char goster; for (i=1; i<=8; i++) { for (row=0;row<9;row++) { sdeger=gonder[row]; sdeger=sdeger<<n; sdeger=sdeger&0x80; gdeger[row]=gdeger[row]>>(1); gdeger[row]+=sdeger; }//for row row=0; n=n-1; for (goster =1; goster < 15; goster++) { for (col = 1 ; col < 256 ; col <<= 1){ P2 = col ; P1 = ~gdeger[row++]; bekle(1); }//for col row=0; }//for goster } //for i for (goster =1; goster < 100; goster++) { for (col = 1 ; col < 256 ; col <<= 1){ P2 = col ; P1 = ~gdeger[row++]; bekle(1); }//for col row=0; }//for goster }//yaz void main (){ unsigned int s; P1 = 0; P2 = 0; ET0 = 0; while(1){ for (s=0; s<10; s++) yaz(rakam[s]); }//while }//main
"something more important breaks up"
Since you are declaring your array in data memory, probably it is the return stack that is getting corrupted.
I agree that it is a kind of corruption on the data area with stack or something else. If I change the first line definition from: unsigned char data gdeger[8]; to "unsigned char xdata gdeger[8]; "yaz" function returns to main() and program starts working as i expected.
I am also doing some work to sort it out what "Dan hanry" says. Thanks to all. akif