October 20, 2011

Password protect your microcontroller

Untitled Document
Hello friends, a good idea of privileging the execution of main program of microcontroller came in my mind after watching a Si-Fi movie……and I did it………

Password protecting your microcontroller is one of the coolest things you can do with it……


I created a routine that reads 5 keystrokes and then checks weather the inserted password is right or not.
the micro controller here used is  Atmega 8535
 Not discussing much more about logic, here is the program
----------------------------------------------------------------------------------------------
void main()

{
  unsigned char a,b,c,d,e;           
  DDRA=0x00;
  PORTA=0xff;
                               //ask for password

 while(1)
 {
  lcd_init();
  lcd_string("Enter a 5 digit");
  lcd_gotoxy(1,0);
  lcd_string("Password:");
                                             //read password
  while(PINA==0xff);                    //if all keys open stay here
  a=PINA;
  delayms(200);
    lcd_gotoxy(1,0);
            lcd_string("Password:*");
            while((PINA&0xf0)!=0xf0);      //wait to release the key
 while(PINA==0xff);        
             b=PINA;
  delayms(200);
    lcd_gotoxy(1,0);
            lcd_string("Password:**");
            while((PINA&0xf0)!=0xf0);     //wait to release the key
 while(PINA==0xff);        
             c=PINA;
  delayms(200);
    lcd_gotoxy(1,0);
            lcd_string("Password:***");
             while((PINA&0xf0)!=0xf0);   //wait to release the key
 while(PINA==0xff);        
 d=PINA;
  delayms(200);
    lcd_gotoxy(1,0);
            lcd_string("Password:****");
            while((PINA&0xf0)!=0xf0);   //wait to release the key
 while(PINA==0xff);        
             e=PINA;
  delayms(200);
    lcd_gotoxy(1,0);
            lcd_string("Password:*****");   //wait to release the key
              


                                   //checking the password
  if(a==0xef)
  {
  if(b==0xdf)
            {
            if(c==0xbf)
               {if(d==0x7f)
                        {
                                    if(e==0xef)
                                    {
                                    lcd_init();
                                    lcd_string("Welcome");
                                    goto wait;
                                    }
                                    else
                                    {
                                                            lcd_init();
                                                            lcd_string("Invalid password!!");
                                                            delayms(2000);
                                    }
                        }
                        else
                        {
                                                lcd_init();
                                                lcd_string("Invalid password!!");
                                                delayms(2000);
                        }

            }
            else
            {
            lcd_init();
            lcd_string("Invalid password!!");
            delayms(2000);
            }
            }
   else
  {
  lcd_init();
  lcd_string("Invalid password!!");
  delayms(2000);
  }
  }
 else
  {
  lcd_init();
  lcd_string("Invalid password!!");

  delayms(2000);

  }
  }
  wait:while(1);                      
            }

----------------------------------------------------------------------------------------------






and no post is completed without a video,




leave a comment if you want to ask any thing related to programming.

:)

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...