i am working on following project. & its showing me some errors... & i am unable to remove them... please help me out...
program:-
/*HEADER FILES*/ #include<reg51.h> #include<string.h>
/*LCD PIN CONNECTIONS*/ #define lcd P0 sbit rs=P0^1; sbit en=P0^3;
/*LCD FUNCTIONS DECLARATIONS*/ void init_lcd(void); void cmd_lcd(unsigned char); void data_lcd(unsigned char); void str_lcd(unsigned char *); void Delay_ms(unsigned int);
/*KEYPAD PIN CONNECTIONS*/ sbit row0=P2^3; sbit row1=P2^5; sbit row2=P2^6; sbit row3=P2^0; sbit col0=P2^4; sbit col1=P2^2; sbit col2=P2^1;
/*MOTOR PIN CONNECTIONS*/ sbit M1=P1^0; sbit M2=P1^5;
/*BUZZER PIN CONNECTION*/ sbit BUZZER=P1^2;
/*VARIABLES DECLARATION*/ unsigned char i,j; unsigned char colval,rowval,pwdchange;
unsigned char pwd[15],temp[],str1[]="12345";
unsigned char keypad[4][3]={'1','2','3','4','5','6','7','8','9','*','0','#',}; /*PASSWORD FUNCTION DECLARATION*/ void password(void);
/*KEYPAD FUNCTION DECLARATION*/ unsigned char key(void);
/*MAIN FUNCTION*/ main() { unsigned char k=0; BUZZER=0; //BUZZER OFF M1=M2=0; //MOTOR OFF
init_lcd(); //LCD INITIALIZATION FUNCTION CALLING str_lcd("ENTER PASSWORD:"); //DISPLAY STRING ON LCD while(1) { cmd_lcd(0xc0); //2ND LINE DISPLAY password(); //PASSWORD FUNCTION CALLING if(pwdchange) { pwdchange=0; continue; } if(!strcmp(str1,pwd)) //COMPARING WITH 1ST PASSWORD { BUZZER=0; //BUZZER OFF cmd_lcd(0xc0); str_lcd("DOOR OPEN");
M1=0; //MOTOR RUNS IN FORWARD DIRECTION M2=1; Delay_ms(30); //30 MILLISECONDS DELAY cmd_lcd(0xc0); str_lcd(" "); M1=0; //MOTOR OFF M2=0; Delay_ms(1500);
cmd_lcd(0xc0); str_lcd("DOOR CLOSE");
M1=1; M2=0; Delay_ms(30); cmd_lcd(0xc0); str_lcd(" "); M1=0; //MOTOR OFF M2=0; k=0;
} else {
strcpy(temp,pwd); cmd_lcd(0x01); str_lcd("Confirm Password"); cmd_lcd(0xc0); password(); if(!strcmp(temp,pwd)) { strcpy(str1,temp); cmd_lcd(0x01); str_lcd("Password'Changed"); Delay_ms(1000); cmd_lcd(0x01); str_lcd("Enter Password"); cmd_lcd(0xc0); pwdchange=1; return; } else { cmd_lcd(0x01); str_lcd("Password Error"); Delay_ms(1000); cmd_lcd(0x01); str_lcd("Enter Password"); cmd_lcd(0xc0); pwdchange=1; return; } } else { cmd_lcd(0x01); str_lcd("Password Error"); Delay_ms(1000); cmd_lcd(0x01); str_lcd("Enter Password"); cmd_lcd(0xc0); pwdchange=1; return; } } else {goto label;
} else { goto label; }
else { label:pwd[i++]=j; data_lcd('*'); }
pwd[i]='\0'; }
//its showing 4 syntax error near else...
/*HEADER FILES*/ #include<reg51.h> #include<string.h> /*LCD PIN CONNECTIONS*/ #define lcd P0 sbit rs=P0^1; sbit en=P0^3; /*LCD FUNCTIONS DECLARATIONS*/ void init_lcd(void); void cmd_lcd(unsigned char); void data_lcd(unsigned char); void str_lcd(unsigned char *); void Delay_ms(unsigned int); /*KEYPAD PIN CONNECTIONS*/ sbit row0=P2^3; sbit row1=P2^5; sbit row2=P2^6; sbit row3=P2^0; sbit col0=P2^4; sbit col1=P2^2; sbit col2=P2^1; /*MOTOR PIN CONNECTIONS*/ sbit M1=P1^0; sbit M2=P1^5; /*BUZZER PIN CONNECTION*/ sbit BUZZER=P1^2; /*VARIABLES DECLARATION*/ unsigned char i,j; unsigned char colval,rowval,pwdchange; unsigned char pwd[15],temp[],str1[]="12345"; unsigned char keypad[4][3]={'1','2','3','4','5','6','7','8','9','*','0','#',}; /*PASSWORD FUNCTION DECLARATION*/ void password(void); /*KEYPAD FUNCTION DECLARATION*/ unsigned char key(void); /*MAIN FUNCTION*/ main() { unsigned char k=0; BUZZER=0; //BUZZER OFF M1=M2=0; //MOTOR OFF init_lcd(); //LCD INITIALIZATION FUNCTION CALLING str_lcd("ENTER PASSWORD:"); //DISPLAY STRING ON LCD while(1) { cmd_lcd(0xc0); //2ND LINE DISPLAY password(); //PASSWORD FUNCTION CALLING if(pwdchange) { pwdchange=0; continue; } if(!strcmp(str1,pwd)) //COMPARING WITH 1ST PASSWORD { BUZZER=0; //BUZZER OFF cmd_lcd(0xc0); str_lcd("DOOR OPEN"); M1=0; //MOTOR RUNS IN FORWARD DIRECTION M2=1; Delay_ms(30); //30 MILLISECONDS DELAY cmd_lcd(0xc0); str_lcd(" "); M1=0; //MOTOR OFF M2=0; Delay_ms(1500); cmd_lcd(0xc0); str_lcd("DOOR CLOSE"); M1=1; M2=0; Delay_ms(30); cmd_lcd(0xc0); str_lcd(" "); M1=0; //MOTOR OFF M2=0; k=0; } else { strcpy(temp,pwd); cmd_lcd(0x01); str_lcd("Confirm Password"); cmd_lcd(0xc0); password(); if(!strcmp(temp,pwd)) { strcpy(str1,temp); cmd_lcd(0x01); str_lcd("Password'Changed"); Delay_ms(1000); cmd_lcd(0x01); str_lcd("Enter Password"); cmd_lcd(0xc0); pwdchange=1; return; } else { cmd_lcd(0x01); str_lcd("Password Error"); Delay_ms(1000); cmd_lcd(0x01); str_lcd("Enter Password"); cmd_lcd(0xc0); pwdchange=1; return; } } else { cmd_lcd(0x01); str_lcd("Password Error"); Delay_ms(1000); cmd_lcd(0x01); str_lcd("Enter Password"); cmd_lcd(0xc0); pwdchange=1; return; } } else {goto label; } else { goto label; } else { label:pwd[i++]=j; data_lcd('*'); } pwd[i]='\0'; }
1) What was the reason you did not specifically mark the source code lines you got compilation errors from? Or did you expect every reader of this thread to create a new Keil uVision project (trying to figure out what settings that may be relevant) and compile the code?
2) Skip using goto. Try Google and note the common view on the use of goto as a method to structure a C/C++ program. There could potentially exist one situation where a goto could help structurally. That is to do the job of a multi-level break statement. But even then, it is very easy to rewrite the code to not need any goto. In short - a goto is a developers failure to structure the code properly.
3) You have managed a huge number of return in your code. That doesn't always help the readability. But it becomes even more interesting when you have code like:
if (xx) { ... return; } else { goto xx; }
Note that the "return" statement makes that "else" statement meaningless, since the logic is the same as:
if (xx) { ... return; } goto xx;
But then that "goto" suddenly don't happen in a way that makes it meaningful anymore, since the decision to do that goto can be pushed further down/later.
In the end, that kind of code can often be rewritten as:
if (xx) { do_something(); } else if (yy) { do_something_else(); } else if (zz) { do_something_yet_different(); } else { see_got_here_with_zero_goto_in_source(); }
... he has lots of time on his hands.
I, however, do not have any intention of going through 100s of lines of code for free
post an extraction (or a small sample program) that show the problem
Erik
Per Westermark:-
i am jst in second year... and i don't know many things... thank you for your advice...
can you please do me a favour??
can you please post this program by correcting all its errors??? please..........................
i"ll b greatfull to you......
can you please post this program by correcting all its errors???
can I help?
here is the corrected version of your code:
/*MAIN FUNCTION*/ main() { }
hope it help.
View all questions in Keil forum