8051 Microcontroller based electronic locker system

CIRCUIT DIAGRAM
LOCKER1

CIRCUIT DESCRIPTION

Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible.The issue of security is very paramount at home doors and safe. An access control for doors formsvital.link
in a security chain. Therefore we intend to aid in security at home by bringing in an electronic code lock system that involves an individual to enter the password before getting an access to some items, a particular room or building.This code lock system is not just the normal single user code lock system that required a user to insert an already programmed code to gain access to a room or safe; it is a code lock system that has password and enable multiple user access.

The microcontroller based Door locker is an access control system that allows only authorized persons to access a restricted area. The system is fully controlled by the 8 bit microcontroller AT89C2051 which has a 2Kbytes of ROM for the program memory. The system has a Keypad by which the password can be entered through it. When the entered password equals with the password stored in the memory then the door is opened. If we entered a wrong password for more than three times then the Alarm is switched on.

The data pins of LCD are connected to P1 port & RS,R/W,E pins are connected to P0.2,P0.3,P0.4. L293D is used to rotate motor bidirectionaly to open & close the locker. A 4*3 keypad is used to enter the numbers 0 to 9 & ‘*’, ‘#’. There is a system menu, contains three buttons for open locker, reset password & close the locker.

PROJECT CODE

#include< reg51.h >
#define col P2
#define row P3

sbit m1=P3^4;
sbit m2=P3^5;
sbit bu=P0^1;
sbit rs=P0^2;
sbit rw=P0^3;
sbit en=P0^4;
sbit start=P0^5;
sbit rst=P0^6;
sbit mp=P0^7;
sfr lcddata=0x90;

void delay(int a)
{
int i,j;
for(i=0;i

How to interface LEDs with 8051 Microcontroller

CIRCUIT DIAGRAM
Graphic1

DESCRIPTION

This post is related to basic operation of 8051 microcontroller with LEDs. LEDs are connected with P2 port & 6 switches are connected with P1 port of 8051. By pressing different switches, LEDs will glow in different manners. This post may be very helpful for 8051 microcontroller beginners.

CODE

#include < reg51.h >

sbit switch1=P1^0;
sbit switch2=P1^1;
sbit switch3=P1^2;
sbit switch4=P1^3;
sbit switch5=P1^4;
sbit switch6=P1^5;

int i,j,l;
int n=7;

void delay(int k) //This function produces a delay in msec.
{
for(i=0;i=0;l–)
{
P2=arr[l];
delay(50);
}
}

if(switch3==0)
{
P2=0x7E;
delay(50);
P2=0xBD;
delay(50);
P2=0xDB;
delay(50);
P2=0xE7;
delay(50);
}

if(switch4==0)
{
P2=0xE7;
delay(50);
P2=0xDB;
delay(50);
P2=0xBD;
delay(50);
P2=0x7E;
delay(50);
}

if(switch5==0)
{
P2=0xAA;
delay(50);
P2=0x55;
delay(50);
}

if(switch6==0)
{
P2=0x00;
delay(50);
P2=0xFF;
delay(50);
}

}

Digital Clock With 8051 Microcontroller

Digital Clock With 8051 Microcontroller

DISCRIPTION :

This post is about to make a Digital Clock With the help of Controller 8051.

This digital clock Also Display Date, Month and Year.

We can also Adjust the Date and Time According to our convinence..

CODE:-

#include<reg51.h>                                                    // header file
sbit p=P3^0;                                                                 // to increase hours
sbit q=P3^1;                                                                 // to decrease minutes
sbit r=P3^2;                                                                 // to decrease hours
sbit l=P3^4;                                                                // to buzzer to indicate hour
sbit bu=P3^3;                                                             // to increase minutes
sbit t=P3^5;                                                                  // to increase date
sbit u=P3^6;                                                               // to decrease date
sbit w=P3^7;                                                              // to increase month
sbit rs=P2^1;                                                              // LCD command pin for select the resistor inside the lcd
sbit rw=P2^2;                                                           // LCD command pin for write the information on lcd
sbit en=P2^3;                                                      // LCD command pin used to latch information presented to it’s data pins
sfr lcddata=0x90; // P2= LCD data pin
/*************************************DELAY FUNCTION*************************************************/
void delay(unsigned char n)
{
unsigned char i,j;
for(i=0;i<n;i++)
for(j=0;j<125;j++);

}
/**********************************LCD COMMAND FUNCTION*********************************************/

void command(unsigned char s)
{
lcddata=s;                                                                        //put the value on pin
rs=0;
rw=0;
en=1;                                                                                 //strobe the enable pin
delay(40);
en=0;
}
/****************************************LCD DISPLAY FUNCTION*****************************************/

void lcddisplaydata(unsigned char s)
{
lcddata=s;                                                              //put the value on pin
rs=1;
rw=0;
en=1; //strobe the enable pin
delay(40);
en=0;
}
/****************************************MAIN program*************************************************/

void main()
{
int h,m,s,y,mo,d,y1,y2,y3,y4,mo1,mo2,d1,d2,h1,h2,m1,m2,s1,s2,i,j,k;
unsigned char array[]={‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9’};
command(0x38);                              // LCD command code for 2 lines and 5*7 matrix
command(0x0c);
command(0x06);                                // LCD command code for increment cursors(shift cursor to right)
while(1)
{
y=2012;                                                 //starting from year 2012
while(y>=2012)
{
for(mo=1;mo<=12;mo++)
{
if(mo==1)                                                //condition for month january
{
d=31;
}
else if(mo==2)                                          //condition for month february
{
if((y%4)==0)                                              //condition for leap year
{
d=29;
}
else
{
d=28;
}
}
else if(mo==3)                                                //condition for month march
{
d=31;
}
else if(mo==4)                                                 //condition for month april
{
d=30;
}
else if(mo==5)                                                    //condition for month may
{
d=31;
}
else if(mo==6)                                                  //condition for month june
{
d=30;
}
else if(mo==7)                                                      //condition for month july
{
d=31;
}
else if(mo==8)                                                       //condition for month august
{
d=31;
}
else if(mo==9)                                                     //condition for month september
{
d=30;
}
else if(mo==10)                                                 //condition for month october
{
d=31;
}
else if(mo==11)                                                  //condition for month november
{
d=30;
}
else                                                                          //condition for month december
{
d=31;
}
for(i=1;i<=d;i++)
{
for(h=0;h<=23;h++)                                                           //condition for hours in a day
{
for(m=0;m<=59;m++)                                                     //condition for minutes in a hour
{
for(s=0;s<=59;s++)                                                          //condition for second in minute
{
y1=y/1000;
j=y%1000;                                                                              //code for disply year
y2=j/100;
k=j%100;
y3=k/10;
y4=k%10;
mo1=mo/10;                                                                             //code for display month
mo2=mo%10;
d1=i/10;
d2=i%10;                                                                                 //code for display day
h1=h/10;
h2=h%10;                                                                                // code for display hour
m1=m/10;                                                                              //code for display minute
m2=m%10 ;
s1=s/10;                                                                                     //code for disply second
s2=s%10;
command(0x80);                                                                // LCD command for first position of first line
lcddisplaydata(array[d1]);
lcddisplaydata(array[d2]);
command(0x84);                                                                // LCD command for fifth position of first line
lcddisplaydata(‘-‘);
command(0x86);                                                               // LCD command for seventh position of first line
lcddisplaydata(array[mo1]);
lcddisplaydata(array[mo2]);
command(0x89);                                                              // LCD command for tenth position of first line
lcddisplaydata(‘-‘);
command(0x8b);                                                             // LCD command for twelveth position of first line
lcddisplaydata(array[y1]);
lcddisplaydata(array[y2]);
lcddisplaydata(array[y3]);
lcddisplaydata(array[y4]);

command(0xc0);                                                                // LCD command for first position of second line
lcddisplaydata(array[h1]);
lcddisplaydata(array[h2]);
command(0xc4);                                                               // LCD command for fourth position of second line
lcddisplaydata(‘:’);
command(0xc6);                                                               // LCD command for sixth position of second line
lcddisplaydata(array[m1]);
lcddisplaydata(array[m2]);
command(0xca);                                                                  // LCD command for eleventh position of second line
lcddisplaydata(‘:’);
command(0xcc);                                                                // LCD command for thirteenth position of second line
lcddisplaydata(array[s1]);
lcddisplaydata(array[s2]);
delay(100);
if(p==0)                                                                                       // switch for increasing Hours
{
h++;                                                                                          // condition to set hours
s=-1;                                                                                          // second reset to Zero after release H++ switch
if(h==24)                                                                                    // if h=24 then hours is start to Zero
{
h=0;
s=-1;
}
}
else if(q==0)                                                                        // switch for decreasing Minutes
{
if(m>0)                                                                                          // if minute is greater then zero
{
m–;                                                                                                              // minute is decrease till zero
s=-1 ;                                                                                                   // after releasing minute decrease button seconds initialize from zero
}
}
else if(r==0)                                                                         // switch for decreasing hours
{
if(h>0)                                                                                            // if hour is greater than zero
{
h–;                                                                                              // hour is decrease till zero
s=-1;                                                                                             // after releasing hour decrease button seconds initialize from zero
}
}
else if(l==0)                                                                              // switch for increasing minutes
{
m++;
s=-1;
if(m>60)                                                                                     // if increased minutes are above than 60 than it again start from zero
{
m=0;
s=-1;
}
}
else if(t==0)                                                                                   // switch for increasing days
{
i++;
if(i>31)                                                                                                 // if increased days are above than 31 than it again start from zero
{
i=0;
}
}
else if(u==0)                                                                                         // switch for decreasing days
{
if(i>0)                                                                                                     // it decrease days till zero
{
i–;
}
}
else if(w==0)                                                                                   // switch for increasing months
{
mo++;
if(mo>12)                                                                                    // if increased months are above than 12 than it again start from zero
{
mo=0;
}
}
else
{
h=h;
m=m;
i=i;
mo=mo;
}
if(m==59)                                                                           // conditin for switching the buzzer
{
bu=1;                                                                                      // buzzer ON
}
else
{
bu=0;                                                                                 // buzzer OFF
}
command(0x82);                                                         // to start LCD from 3rd position of first line
command(0x06);                                                            // to set LCD in entry mode
}
}
}
}
}
}
}
}

Up-Down counter on 16*2 LCD using 8051 microcontroller

CIRCUIT DIAGRAM

DESCRIPTION

In this circuit 16*2 lcd IS used to show the value of count using 8051 microcontroller. The maximum value of count is 99 because. In this circuit we are using 8051-microcontroller, 16*2 lcd, 2 switches for up counting button & down counting button.

Data pins of LCD are connected to P1 port of the 8051 microcontroller. UP counter button is connected with P2.6 and down counter button is connected with P2.7.Whenever the UP counter button is pressed the counter increments by one and when the down counter button is pressed it gets reduced by one.

PROJECT CODE

#include< reg51.h >

sfr lcddata=0x90; //LCD DATA PINS
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;
sbit g=P2^6;
sbit h=P2^7;

int m=0;
int a,b;
unsigned char n[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};

void delay(unsigned char b)
{
unsigned char a;
for(b;b>0;b–)
{
for(a=500;a>0;a–);
}
}

void command(unsigned char dost)
{
lcddata=dost;
en=1;
rs=0;
rw=0;
delay(5);
en=0;
}

void lcddisplaydata(unsigned char n)
{
lcddata=n;
en=1;
rs=1;
rw=0;
delay(50);
en=0;
}

void main()
{
P2=0xFF;
command(0x38);
command(0x0C);
while(1)
{
if(g==0)
{
if(m==99)
{
command(0x80);
lcddisplaydata(n[9]);
command(0x81);
lcddisplaydata(n[9]);
}
else
{
m=m+1;
a=m/10;
{
command(0x80);
lcddisplaydata(n[a]);
}
b=m%10;
{
command(0x81);
lcddisplaydata(n[b]);
}
while(g==0);
}
}

if(h==0)
{
if(m==0)
{
command(0x80);
lcddisplaydata(n[0]);
command(0x81);
lcddisplaydata(n[0]);
}
else
{
m=m-1;
a=m/10;
{
command(0x80);
lcddisplaydata(n[a]);
}
b=m%10;
{
command(0x81);
lcddisplaydata(n[b]);
}
while(h==0);
}
}
}
}

2 Digit 7-Segment Up Down Counter Project using 8051 Microcontroller

DESCRIPTION

In this circuit 2 seven segment are used to show the value of count using 8051 microcontroller. The maximum value of count is 99 because 2 seven segments are used. In this circuit we are using 8051-microcontroller, 2 common cathode seven segments, 2 switches for up counting button & down counting button.

7-Segments are connected to P2 & P3 ports of the 8051 microcontroller. UP counter button is connected with P1.6 and down counter button is connected with P1.7.Whenever the UP counter button is pressed the counter increments by one and when the down counter button is pressed it gets reduced by one.

CODE

#include< reg51.h >
sbit h=P1^6; //up counter button
sbit g=P1^7; //down counter button
int m=0;
int n=0;
int a,b;
int arr[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0xFF,0x67};
void main()
{
P2=0x3F;
P3=0x3F;
while(1)
{
P1=0xFF;
if(h==0)
{
if(n==99&&m==99)
{
P2=0x67;
P3=0x67;
}
else
{
m=m+1;
n=n+1;
a=m/10;
b=n%10;
P2=arr[a];
P3=arr[b];
while(h==0);
}
}
if(g==0)
{
if(n==0&&m==0)
{
P2=0x3F;
P3=0x3F;
}
else
{
m=m-1;
n=n-1;
a=m/10;
b=n%10;
P2=arr[a];
P3=arr[b];
while(g==0);
}
}
}
}

How to interface 16*2 LCD with 8051 microcontroller

DESCRIPTION
This post is about to interface 16*2 LCD with 8051 microcontroller.The data pins of LCD is connected to P1 port of controller and the pins RS, R/W, E is connected to P3.2, P3.3, P3.4 respectively

Let’s start with connecting the LCD hardware with microcontroller (P89v51). The following table lists all pins of LCD module (JHD162A) along with their description.

Pin 1 — Vss — Ground
Pin 2 — Vdd — +5v
Pin 3 — Vee — Contrast Adjustment -2V to -5V
Pin 4 — RS — Register Select
Pin 5 — R/W — 1-Read, 0-Write
Pin 6 — E — Enable
Pin 7 — D0 — Data Line
Pin 8 — D1 — Data Line
Pin 9 — D2 — Data Line
Pin 10 — D3 — Data Line
Pin 11 — D4 — Data Line
Pin 12 — D5 — Data Line
Pin 13 — D6 — Data Line
Pin 14 — D7 — Data Line
Pin 15 — LED+ — BackLight LED +V
Pin 16 — LED- — BackLight LED -V

CODE
# include < reg51.h >
unsigned char a;
sfr lcddata=0x90; //p1 port
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;

/**********************start of program functions************************************************/
//________________________________Delay subroutine________________________________________________________________

void delay(unsigned int b)
{
unsigned int a;
for(b;b>0;b–)
for (a=75;a>0;a–);
}

/*************************LCD Routine**************************************/

void command(unsigned char dost)
{
lcddata=dost;
en=1;
rs=0; //initialise of the LCD
rw=0;
delay(5);
en=0;
}

void lcddisplaydata(unsigned char word)
{
lcddata=word;
en=1; //Data writing of the Lcd
rs=1;
rw=0;
delay(5);
en=0;
}

void displaydata(unsigned char *word)
{
int x;
for(x=0;word[x]!=0;x++) //Data writing of the LCD
{
lcddisplaydata(word[x]);
}
}
/********************************************************/

void main()
{
command(0x38);
command(0x0C);
command(0x80);
displaydata(“ELECTRONICS WORK”);
}