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

Advertisements

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);
}

}

Stack POP Operation through 8051 Microcontroller


Basic architecture of a stack:-
A typical stack, storing local data and call information for nested procedure calls (not necessarily nested procedures!). This stack grows downward from its origin. The stack pointer points to the current topmost datum on the stack. A push operation decrements the pointer and copies the data to the stack; a pop operation copies data from the stack and then increments the pointer. Each procedure called in the program stores procedure return information (in yellow) and local data (in other colors) by pushing them onto the stack. This type of stack implementation is extremely common, but it is vulnerable to buffer overflow attacks (see the text).
A typical stack is an area of computer memory with a fixed origin and a variable size. Initially the size of the stack is zero. A stack pointer, usually in the form of a hardware register, points to the most recently referenced location on the stack; when the stack has a size of zero, the stack pointer points to the origin of the stack.
The two operations applicable to all stacks are:
a push operation, in which a data item is placed at the location pointed to by the stack pointer, and the address in the stack pointer is adjusted by the size of the data item;
a pop or pull operation: a data item at the current location pointed to by the stack pointer is removed, and the stack pointer is adjusted by the size of the data item.

In computer science, a stack is a last in, first out (LIFO) abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack, or initializes the stack if it is empty. If the stack is full and does not contain enough space to accept the given item, the stack is then considered to be in an overflow state. The pop operation removes an item from the top of the stack. A pop either reveals previously concealed items, or results in an empty stack, but if the stack is empty then it goes into underflow state (It means no items are present in stack to be removed). The stack top operation gets the data from the top-most position and returns it to the user without deleting it. The same underflow state can also occur in stack top operation if stack is empty.
A stack is a restricted data structure, because only a small number of operations are performed on it. The nature of the pop and push operations also means that stack elements have a natural order. Elements are removed from the stack in the reverse order to the order of their addition: therefore, the lower elements are those that have been on the stack the longest
Microcontroller have a hardware call stack, which is used to save return addresses. The hardware stack is not software accessible on earlier devices, but this changed with the 18 series devices

Initiate
In modern computer languages, the stack is usually implemented with more operations than just “push”,”pop” and “Stack Top”. Some implementations have a function which returns the current number of items on the stack. Alternatively, some implementations have a function that just returns if the stack is empty. Another typical helper operation stack top[4] (also known as peek) can return the current top element of the stack without removing it.
Implementation
In most high level languages, a stack can be easily implemented either through an array or a linked list. What identifies the data structure as a stack in either case is not the implementation but the interface: the user is only allowed to pop or push items onto the array or linked list, with few other helper operations. The following will demonstrate both implementations, using C.

The array implementation aims to create an array where the first element (usually at the zero-offset) is the bottom. That is, array[0] is the first element pushed onto the stack and the last element popped off. The program must keep track of the size, or the length of the stack. The stack itself can therefore be effectively implemented as a two-element structure in C:

CODE:-

#include<reg51.h>
/**********************STARTING OF PROGRAM FUNCTION********************************************/

//_________________________DELAY SUBROUTINE____________________________________________/

void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
for(j=0;j<1275;j++);                                         //CREATING DELAY BY INSTRUCTION
}

/*************************** MAIN FUNCTION ***********************************************************/

void main()
{
char d=0x00,b,c;
int n=7,x;
P1=0x00;                                                                         //SET P1 PORT AS OUTPUT PORT
delay(50);                                                                       //CALL DELAY SUBROUTINE
while(1)
{
b=0x03;
b<<=n;                                                                                //SHIFTING N-TIMES OF DATA ‘b’ IN “LEFT” SIDE
for(x=n;x<7;x++)                                                       //LOOP FOR INCREASING X FROM N TO LESS THAN 7
{
d=c^b;                                                                                  //X-OR OPERATION B/W DATA ‘C & b’ and STORE RESULT IN DATA ‘d’
P1=d;                                                                                     //SET P1 PORT CORRESPONDING TO DATA ‘d’
delay(50);                                                                          //CALL DELAY SUBROUTINE
b<<=1;                                                                           //SHIFTING ONE-TIME OF DATA ‘b’ IN LEFT SIDE

c=d;                                                                              //COPY OF DATA ‘d’ INTO DATA ‘c’
}
c=d^b;                                                                         //X-OR OPERATION B/W DATA ‘b & c’ and STORE RESULT IN DATA ‘c’
P1=c;                                                                               //SET P1 PORT CORRESPONDING TO DATA ‘c’
delay(50);
n–;                                                                                    //DECREMENT IN THE VALUE OF N
}
}

VEDIO :-


}

How to Interface 14-Segment using 8051 Microcontroller

CIRCUIT DIAGRAM

DESCRIPTION

In this circuit we are using 14-segment to show characters.14-segments have 22 pins, with the help of these pins we can write characters on 14 segment. 8 pins A,B,C,D,E,F,K,M are connected to P2 port, 6 pins N,P,R,S,T,U are connected with P3 port & 8 pins are connected with P1 port.

PROJECT CODE

#include<reg51.h>

void delay()
{
TMOD=0x01;
TH0=0xF8;
TL0=0xCD;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void main()
{

P1=0x7F; //FOR FIRST CHARACTER
P2=0x9C;
P3=0x44;
delay();

P1=0xBF; //FOR SECOND CHARACTER
P2=0x9C;
P3=0x00;
delay();

P1=0xDF; //FOR THIRD CHARACTER
P2=0x00;
P3=0x00;
delay();

P1=0xEF; //FOR FORTH CHARACTER
P2=0xCC;
P3=0x64;
delay();

P1=0xF7; //FOR FIFTH CHARACTER
P2=0xFC;
P3=0x00;
delay();

P1=0xFB; //FOR SIXTH CHARACTER
P2=0x9C;
P3=0x00;
delay();

P1=0xFD; //FOR SEVENTH CHARACTER
P2=0x0C;
P3=0xA4;
delay();

P1=0xFE; //FOR EIGHTH CHARACTER
P2=0xB4;
P3=0x44;
delay();

}

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);
}
}
}
}