Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to store password in array from user input and compare with pre savd paswrd array

Status
Not open for further replies.

numair_noor

New Member
i need to know how to save user input in array using at89c51/52, i am using mikroc software for 8051.
this is my code so far:
(please help me urgent)
Code:
//numair registeration # is 782
              //saeed registeration # is 287
             //numair password is 456
             //saeed passwords is 123

//char nreg[3]={'7','8','2'};
//char ncreg[3];
//int strcmp(char *s1,char *s2);
///unsigned int npass[3]={4,5,6};
///unsigned int ch[3];
unsigned int f,digit[3]={0,0,0},nreg[3]={7,8,2};
unsigned char i=0,j=0;
void reg();
void pass();
void check();
void Lcd_Init();
//void display(char p,char v);





// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;

sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
// End Lcd module connections




void main() {

//P1=0x00;  //PORT 1 is at sink
//P3=0x00;  //PORT 3 is at sink
//S:
p1=0x00;
p3=0x00;


Lcd_Init();                              // Initialize Lcd
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
LCD_OUT(1,1,"ENTER REG. #");

  while(1)
          {
          Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
LCD_OUT(1,1,"ENTER REG. #");

////////push buttons FUNCTIONS START////////////////
reg();//ENTER REGISTERATION NUMBER

//check();
          }

}

void reg()         //function for registeration number
{

         for(i=0;i<3;i++)
         {
         while( p1.b0!=1 && p1.b1!=1 && p1.b2!=1 && p1.b3!=1 && p1.b4!=1 && p1.b5!=1 && p1.b6!=1 && p1.b7!=1 && p3.b0!=1 && p3.b1!=1 && p3.b2!=1 && p3.b3!=1 && p3.b4!=1 && p3.b5!=1 && p3.b6!=1 && p3.b7!=1); //wait for any key to be pressed
          if(p1.b0==1)
                 {
                 //f=0;
                 digit[i]=0;       //put 0 in digit[i]
                 Lcd_Out(2,i+1,"0"); //LCD OUT =0
                 while(p1.b0!=0);
                 }

          else if(p1.b1==1)
                 {
                 //f=1;
                 digit[i]=1;    //put 1 in digit[i]
                 LCD_OUT(2,i+1,"1");  //LCD OUT =1
                 while(p1.b1!=0);
                 //f=0;
                 }

          else if(p1.b2==1)
                 {
                 //f=2;
                 digit[i]=2;     //put 2 in digit[i]
                 LCD_OUT(2,i+1,"2");  //LCD OUT =2
                 while(p1.b2!=0);
                 //f=0;
                 //ncreg[i]=2;
                 }

          else if(p1.b3==1)
                 {
                 //f=3;
                 digit[i]=3;        //put 3 in digit[i]
                 LCD_OUT(2,i+1,"3");//LCD OUT =3
                 while(p1.b3!=0);
                 //f=0;
                 }

          else if(p1.b4==1)
                 {
                 //f=4;
                 digit[i]=4; //put 4 in digit[i]
                 LCD_OUT(2,i+1,"4");//LCD OUT =4
                 while(p1.b4!=0);
                 ///f=0;
                 }

          else if(p1.b5==1)
                 {
                 //f=5;
                 digit[i]=5;//put 5 in digit[i]
                 LCD_OUT(2,i+1,"5");//LCD OUT =5
                 while(p1.b5!=0);
                 //f=0;
                 }

          else if(p1.b6==1)
                 {
                 //f=6;
                 digit[i]=6;  //put 6 in digit[i]
                 LCD_OUT(2,i+1,"6");//LCD OUT =6
                 while(p1.b6!=0);
                 //f=0;
                 }

          else if(p1.b7==1)
                 {
                 //f=7;
                 digit[i]=7;   //put 7 in digit[i]
                 LCD_OUT(2,i+1,"7");//LCD OUT =7
                 while(p1.b7!=0);
                }

          else if(p3.b0==1)
                 {
                 //f=8;
                 digit[i]=8;    //put 8 in digit[i]
                 LCD_OUT(2,i+1,"8");//LCD OUT =8
                 while(p3.b0!=0);
                 //f=0;
                 //ncreg[i]=8;
                 }

          else if(p3.b1==1)
                 {
                 //f=9;
                 digit[i]=9;   //put 9 in digit[i]
                 LCD_OUT(2,i+1,"9");//LCD OUT =9
                 while(p3.b1!=0);
                 //f=0;
                 }

       //   else if(p3.b2==1)
         //        {
                 //f=10;
                 //[i]='*';
           //      LCD_OUT(2,i+1,"*");//LCD OUT = * (10 for *)
             //    while(p3.b2!=0);
                 //f=0;
               //  }

         // else if(p3.b3==1)
                 {
                 //f=20;
                 //ar[i]='#';
             //    LCD_OUT(2,i+1,"#");  //LCD OUT = #
           //      while(p3.b3!=0);
                 //f=0;
               //  }
          }
//now here is problem i guess:( please help... please please
       [COLOR="#FF0000"]Lcd_Cmd(_LCD_CLEAR);
       Lcd_Out(1,1,digit[]);
       delay_ms(1000);
[/COLOR]



                          //for(j=0;j<3;j++)
                          //{        // if(nreg.toString[] == comp.toString[])
                                //if(nreg[j]=ar[j])// && (nreg[3]==comp[3]))// && //(nreg[2]==comp[3]))
                                 //{
                                // Lcd_Cmd(_LCD_CLEAR);
                                 //Lcd_Out(1,j,'ar[j]');
                                 //delay_ms(1000);
                                 //}
                                //else
                                 //{

                                //Lcd_Out(1,2,digit[2]);
                                //delay_ms(1000);
                                //Lcd_Out(1,3,digit[3]);
                                // delay_ms(1000);
                                  //}
}
}                     //}
 
Hi:

First of all, your code is too dirty.
Code:
while( p1.b0!=1 && p1.b1!=1 && p1.b2!=1 && p1.b3!=1 && p1.b4!=1 && p1.b5!=1 && p1.b6!=1 && p1.b7!=1 && p3.b0!=1 && p3.b1!=1 && p3.b2!=1 && p3.b3!=1 && p3.b4!=1 && p3.b5!=1 && p3.b6!=1 && p3.b7!=1); //wait for any key to be pressed
This can be reduced to:
Code:
while(!p1 && !p2 && !p3);

And the problem appear to be the call to lcd_out();

It appears that lcd_out() needs a position (x,y) and a char variable. You saved in digit[] the integer numbers given by the user.
You should do something like this:

Code:
for(j=0;j<3;j++)
{
  lcd_out(1,j,ar[j]+'0'); //You need to call lcd_out with a char type
}
ar[j]+'0' converts the integer value to the corresponding char value representing a number between 0 and 9. You can also use itoa();
Good luck;
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top