Skip to main content

Microcontroller based security system


                                                         at89c51 pin diagram

                                                                      AT89C51

 




                                                            8051 development board



                                                             Proteus simulation




MicroController Based Security System

                  1. AT89C51 Microcontroller IC
                   2. 16x2 LCD
                   3. 4x4 Matrix Keyboard
                   4. 2 different colored LED
                   5. Wires
                   6. SP200S Programmer

                                     (or)

                  8051 Development Board with Programmer

First let us see the Pin Diagram of AT89C51 MicroController. Without knowing it or with wrong pin connections the IC will be uselessly burnt off.

The Micro controller IC is programmed in Keil uvision which is already in my site in the Softwares menu.

The program is pretty simple. We take two array pointers with alphabets. We designate specific alphabets to the numbers 1-9,0 as a,b,.....j respectively and take these alphabets in an array of size say 4 as password. Then we'll be taking another array of password size say 4. with zero initial values. Now, as each keypress denotes a certain port pin on or off condition, the same is used to print the corresponding numbers on the LCD and array values and incrementation to its next array location. When the key * is pressed we check the two arrays ( the one with already specified password to the array whose values are obtained as we enter the password ) and if both arrays are equal then we're going to display Welcome with a Green LED lighting. If they dont match then a Wrong Password message is displayed in the LCD with a Red LED Lighting.

The program Code for the above project is given below with a simulated Proteus Output:

Code:

#include <reg51.h>
#include <lcd.h>
#include<string.h>
sbit RS = P0^0;
sbit RW = P0^1;
sbit EN = P0^2;
sbit D0 = P2^0;
sbit D1 = P2^1;
sbit D2 = P2^2;
sbit D3 = P2^3;
sbit D4 = P2^4;
sbit D5 = P2^5;
sbit D6 = P2^6;
sbit D7 = P2^7;
sbit ra=P1^4;
sbit rb=P1^3;
sbit rc=P1^6;
sbit rd=P1^7;
sbit c1=P1^0;
sbit c2=P1^1;
sbit c3=P1^2;
sbit gl = P3^0;
sbit rl = P3^1;
void delay(int a)
{int i,j;
for(i=0;i<a;i++)
{for(j=0;j<100;j++)
{}}}
void key()
{
int a; char p[10];char t[10]="efid";int c=-1;
ln1:Lcd8_Write_String("Password:");
for(a=0;a<10000000;a++){
rb=rc=rd=c1=c2=c3=1;ra=0;
{if(!ra&!c1){Lcd8_Write_Char('1');delay(1000);c=c+1;p[c]='a';}}
{if(!ra&!c2){Lcd8_Write_Char('2');delay(1000);c=c+1;p[c]='b';}}
{if(!ra&!c3){Lcd8_Write_Char('3');delay(1000);c=c+1;p[c]='c';}}
ra=rc=rd=c1=c2=c3=1;rb=0;
{if(!rb&!c1){Lcd8_Write_Char('4');delay(1000);c=c+1;p[c]='d';}}
{if(!rb&!c2){Lcd8_Write_Char('5');delay(1000);c=c+1;p[c]='e';}}
{if(!rb&!c3){Lcd8_Write_Char('6');delay(1000);c=c+1;p[c]='f';}}
rb=ra=rd=c1=c2=c3=1;rc=0;
{if(!rc&!c1){Lcd8_Write_Char('7');delay(1000);c=c+1;p[c]='g';}}
{if(!rc&!c2){Lcd8_Write_Char('8');delay(1000);c=c+1;p[c]='h';}}
{if(!rc&!c3){Lcd8_Write_Char('9');delay(1000);c=c+1;p[c]='i';}}
rb=rc=ra=c1=c2=c3=1;rd=0;
{if(!rd&!c1)
{if(strcmp(p,t)==0){Lcd8_Set_Cursor(2,0);Lcd8_Write_String("Done");gl=1;delay(2000);
Lcd8_Clear();Lcd8_Set_Cursor(1,4);Lcd8_Write_String("WELCOME!!!");}
else{Lcd8_Set_Cursor(2,0);Lcd8_Write_String("Wrong Password");rl=1;}}}
{if(!rd&!c2){Lcd8_Write_Char('0');delay(1000);p[9]='j';c=c+1;}}
{if(!rd&!c3){Lcd8_Clear();p==0;c=-1;gl=rl=0;goto ln1;}}}}
void main()
{RW=0;
rl=gl=0;
Lcd8_Init();
key();
}

Note: copy and paste the header file "lcd.h" to "C:\Keil\C51\INC"

Or else add the below code in the program or simply create lcd.h file using notepad in "C:\keil\c51\INC\" and paste the code in lcd.h

//LCD Module Connections
extern bit RS;                                                                 
extern bit EN;                         
extern bit D0;
extern bit D1;
extern bit D2;
extern bit D3;
extern bit D4;
extern bit D5;
extern bit D6;
extern bit D7;
//End LCD Module Connections

void Lcd_Delay(int a)
{
    int j;
    int i;
    for(i=0;i<a;i++)
    {
        for(j=0;j<100;j++)
        {
        }
    }
}
//LCD 8 Bit Interfacing Functions
void Lcd8_Port(char a)
{
    if(a & 1)
        D0 = 1;
    else
        D0 = 0;
  
    if(a & 2)
        D1 = 1;
    else
        D1 = 0;
  
    if(a & 4)
        D2 = 1;
    else
        D2 = 0;
  
    if(a & 8)
        D3 = 1;
    else
        D3 = 0;
  
    if(a & 16)
        D4 = 1;
    else
        D4 = 0;
    if(a & 32)
        D5 = 1;
    else
        D5 = 0;
  
    if(a & 64)
        D6 = 1;
    else
        D6 = 0;
  
    if(a & 128)
        D7 = 1;
    else
        D7 = 0;
}
void Lcd8_Cmd(char a)
{
  RS = 0;             // => RS = 0
  Lcd8_Port(a);             //Data transfer
  EN  = 1;             // => E = 1
  Lcd_Delay(5);
  EN  = 0;             // => E = 0
}
Lcd8_Clear()
{
      Lcd8_Cmd(1);
}
void Lcd8_Set_Cursor(char a, char b)
{
    if(a == 1)
      Lcd8_Cmd(0x80 + b);
    else if(a == 2)
        Lcd8_Cmd(0xC0 + b);
}
void Lcd8_Init()
{
    Lcd8_Port(0x00);
    RS = 0;
    Lcd_Delay(200);
    ///////////// Reset process from datasheet /////////
  Lcd8_Cmd(0x30);
    Lcd_Delay(50);
  Lcd8_Cmd(0x30);
    Lcd_Delay(110);
  Lcd8_Cmd(0x30);
  /////////////////////////////////////////////////////
  Lcd8_Cmd(0x38);    //function set
  Lcd8_Cmd(0x0C);    //display on,cursor off,blink off
  Lcd8_Cmd(0x01);    //clear display
  Lcd8_Cmd(0x06);    //entry mode, set increment
}
void Lcd8_Write_Char(char a)
{
   RS = 1;             // => RS = 1
   Lcd8_Port(a);             //Data transfer
   EN  = 1;             // => E = 1
   Lcd_Delay(5);
   EN  = 0;             // => E = 04
}
void Lcd8_Write_String(char *a)
{
    int i;
    for(i=0;a[i]!='\0';i++)
     Lcd8_Write_Char(a[i]);
}
void Lcd8_Shift_Right()
{
    Lcd8_Cmd(0x1C);
}
void Lcd8_Shift_Left()
{
    Lcd8_Cmd(0x18);
}
//End LCD 8 Bit Interfacing Functions
//LCD 4 Bit Interfacing Functions
void Lcd4_Port(char a)
{
    if(a & 1)
        D4 = 1;
    else
        D4 = 0;
  
    if(a & 2)
        D5 = 1;
    else
        D5 = 0;
  
    if(a & 4)
        D6 = 1;
    else
        D6 = 0;
  
    if(a & 8)
        D7 = 1;
    else
        D7 = 0;
}
void Lcd4_Cmd(char a)
{
    RS = 0;             // => RS = 0
    Lcd4_Port(a);
    EN  = 1;             // => E = 1
  Lcd_Delay(5);
  EN  = 0;             // => E = 0
}
Lcd4_Clear()
{
    Lcd4_Cmd(0);
    Lcd4_Cmd(1);
}
void Lcd4_Set_Cursor(char a, char b)
{
    char temp,z,y;
    if(a == 1)
    {
      temp = 0x80 + b;
        z = temp>>4;
        y = (0x80+b) & 0x0F;
        Lcd4_Cmd(z);
        Lcd4_Cmd(y);
    }
    else if(a == 2)
    {
        temp = 0xC0 + b;
        z = temp>>4;
        y = (0xC0+b) & 0x0F;
        Lcd4_Cmd(z);
        Lcd4_Cmd(y);
    }
}
void Lcd4_Init()
{
    Lcd4_Port(0x00);
    Lcd_Delay(200);
    ///////////// Reset process from datasheet /////////
  Lcd4_Cmd(0x03);
    Lcd_Delay(50);
  Lcd4_Cmd(0x03);
    Lcd_Delay(110);
  Lcd4_Cmd(0x03);
  /////////////////////////////////////////////////////
  Lcd4_Cmd(0x02);  
    Lcd4_Cmd(0x02);
  Lcd4_Cmd(0x08);   
    Lcd4_Cmd(0x00);
    Lcd4_Cmd(0x0C);   
  Lcd4_Cmd(0x00);  
  Lcd4_Cmd(0x06); 
}
void Lcd4_Write_Char(char a)
{
   char temp,y;
   temp = a&0x0F;
   y = a&0xF0;  
     RS = 1;             // => RS = 1
   Lcd4_Port(y>>4);             //Data transfer
     EN = 1;
     Lcd_Delay(5);
     EN = 0;
     Lcd4_Port(temp);
     EN = 1;
     Lcd_Delay(5);
     EN = 0;
}
void Lcd4_Write_String(char *a)
{
    int i;
    for(i=0;a[i]!='\0';i++)
     Lcd4_Write_Char(a[i]);
}
void Lcd4_Shift_Right()
{
    Lcd4_Cmd(0x01);
    Lcd4_Cmd(0x0C);
}
void Lcd4_Shift_Left()
{
    Lcd4_Cmd(0x01);
    Lcd4_Cmd(0x08);
}
//End LCD 4 Bit Interfacing Functions