1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

syntax error

Discussion in 'Programming' started by amit251291, Mar 6, 2012.

  1. amit251291

    amit251291 New Member

    Joined:
    Mar 6, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    this program is showing 4 errors.. and i am unable to remove them.. the errors are because of improper use of if-else statements...its showing syntax errors at else statements...

    code:-

    Code:
    /*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';	
    }
     
    Last edited by a moderator: Mar 6, 2012

Share This Page