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
You are absolutely right.. :-) this is my mistake to put 9 for "row" ..
Thanks. akif
for (k=1; k<=8; k++) { for (row=0;row<8;row++) { sdeger=gonder[row]; sdeger=sdeger<<n;
this is my mistake to put 9 for 'row'
This is why so-called "magic numbers" are a bad thing!
Rather than use a literal number, it would be far safer to use some symbolic constant (eg, #define or enum) so that it will automatically be right