Password checking system using 8051 Micro-Controller

SIMULATOR: PROTEUS 8.0

SOFTWARE: KEIL 4.0

CIRCUIT DIAGRAM:



CIRCUIT WORKING:

I have connected four rows of the keypad to p3.0 to p3.2 respectively. Three columns of the keypad are connected to p3.4 to p3.7 respectively.

Lcd data pins are connected to port 1. Lcd control signals such as RS, R/W and EN are connected to p2.0 to p2.2 respectively.

Whenever the user entered the password then that password is get checked by the microcontroller. If the password is correct then lcd displays the message of "access granted". If the password is wrong then lcd displays the message of "access denied".

PROGRAM:

Header file of LCD:

#include<reg51.h>

#include<string.h>

sbit RS = P2^0;                  // REGISTER SELECT

sbit RW = P2^1;                // READ/WRITE

sbit EN = P2^2;                   // ENABLE

void delay(int t);                           //delay function

void lcd_init(void);                       //initialization of lcd

void lcd_command(char c);          // lcd command function

void lcd_data(char d);                 //lcd data function

void str(char a[]);                       // lcd string function

 

void lcd_init(void)

{

lcd_command(0x38);                 //8 bit,2 line,5x7 dots 

lcd_command(0x01);              // clear dispay

lcd_command(0x0f);               //display on,cursor blinking

lcd_command(0x06);              // entry mode

lcd_command(0x80);              // force cursor to begining of first row   

}

 

void lcd_command(char c)

{

P1=c;                              //send command to port1

RS=0;                             //select command register to send command

RW=0;                           // write operation

EN=1;                           // send high to low pulse on enable pin of lcd

delay(5);

EN=0;

delay(5);                       // delay

}

 

void lcd_data(char d)  

{

P1=d;                          //send data to port1   

RS=1;                          //select data register to send data

RW=0;                        // write operation

EN=1;                        // send high to low pulse on enable pin of lcd

delay(5);

EN=0;

delay(5);                     // delay

}

 

void delay(int t)

{

int j;

for(j=0;j<t*1275;j++);

}

 

void str(char a[])                     

{

int j;

for(j=0;a[j]!='\0';j++)

{

lcd_data(a[j]);                                //pass string to array

}

}

 

Main program:

 

#include<reg51.h>

#include<string.h>

#include "lcd.h"

sbit r1=P3^0;

sbit r2=P3^1;

sbit r3=P3^2;

sbit r4=P3^3;

sbit c1=P3^4;

sbit c2=P3^5;

sbit c3=P3^6;

 

int i=0;

char pass[4]="1234";                    //password

char b[4];           // array for storing the data entered by the user

void keypad();

void welcome();

void main()

 

{

      lcd_init();                            //initialization of lcd

      str("welcome to the");

      lcd_command(0xc0);

      str("embedded system");

      lcd_command(0x01);

      lcd_command(0x80);

           

     

 while(1)

      {

 keypad();                              // take input from user

 

if((strncmp(pass,b,4))==0)             //check the password

{

lcd_command(0x01);                 

str("access granted");               //password is correct                                                                

lcd_command(0x01);

     

}

else                                       

{

 lcd_command(0x01);

 str("access denied");               //password is wrong

 lcd_command(0x01); 

}

}         

}

 

void keypad()   //keypad function to take input from user

{

int i;

str("enter password");

lcd_command(0xc0);

while(i<4)                                // take 4 bit password

{

r1=0;

r2=r3=r4=1;

if(c1==0)

{

lcd_data('*');

b[i]='1';                                  

i++;

}

else if(c2==0)

{

lcd_data('*');

b[i]='2';

 i++;

}

else if(c3==0)

{

lcd_data('*');

b[i]='3';

 i++;

     

}

r2=0;

r1=r3=r4=1;

if(c1==0)

{

lcd_data('*');

b[i]='4';

i++;

           

}

else if(c2==0)

{

lcd_data('*');

b[i]='5';

i++;

}

else if(c3==0)

{

lcd_data('*');

b[i]='6';

i++;

 

}

r3=0;

r2=r1=r4=1;

if(c1==0)

{

lcd_data('*');

b[i]='7';

i++;

           

}

else if(c2==0)

{

lcd_data('*');

b[i]='8';

i++;

     

}

else if(c3==0)

{

lcd_data('*');

b[i]='9';

i++;

}

r4=0;

r2=r3=r1=1;

if(c1==0)

{

lcd_data('*');

b[i]='*';

i++;

}

else if(c2==0)

{

lcd_data('*');

b[i]='0';

i++;

}

else if(c3==0)

{

lcd_data('*');

b[i]='#';

i++;

}

}

}


PROGRAM DESCRIPTION:

First I have initialized the lcd by providing the lcd initialization function. Then I have called the keypad function. The keypad function is used to take input from the user. I have stored the data entered by the user in one array.

After that, I compared this data with the stored password. If the password matched with the data entered by the user then lcd will display the message of "access granted".

If it does not get a match then lcd will display the message of "access denied". For a continuous process, I have used a while loop. For displaying the data, lcd data function is used.

VIDEO:






Comments

Popular posts from this blog

To display custom characters on the lcd using 8051 micro-controller.

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

LCD interfacing using AVR(ATMEGA 32)