8051 Microcontroller based electronic locker system

ELECTRONIC LOCKER1

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

Graphic1

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

}

Microcontroller 8051 Piano in Keil and Proteus simulator

Piano With Controller-8051

DISCRIPTION:-

The piano is a musical instrument played mainly by means of a keyboard. It is one of the most popular instruments in the world.

Today, it is one of the two parts of Indian classical music, with the other one being Carnatic music, which represents the music of South India.

he rhythmic organization is based on rhythmic patterns called Taal. The melodic foundations are called ragas. One possible classification of ragas is into “melodic modes” or “parent scales”, known as Thaats, under which most ragas can be classified based on the notes they use.
Thaats may consist of up to seven scale degrees, or swara. Hindustani musicians name these pitches using a system called Sargam, the equivalent of Western movable do solfege:
Sa (Shadaj) = Do
Re (Rishab) = Re
Ga (Gandhar) = Mi
Ma (Madhyam) = Fa
Pa (Pancham) = So
Dha (Dhaivat) = La
Ni (Nishad) = Ti
Sa (Shadaj) = Do
Both systems repeat at the octave. The difference between sargam and solfege is that re, ga, ma, dha, and ni can refer to either “Natural” (Shuddha) or altered “Flat” (Komal) or “Sharp” (Tivra) versions of their respective scale degrees. As with movable do solfege, the notes are heard relative to an arbitrary tonic that varies from performance to performance, rather than to fixed frequencies, as on a xylophone. The fine intonational differences between different instances of the same swara are called shrutis. The three primary registers of Indian classical music are Mandra (lower), Madhya (middle) and Taar (upper). Since the octave location is not fixed, it is also possible to use provenances in mid-register (such as Mandra-Madhya or Madhya-Taar) for certain ragas. A typical rendition of Hindustani raga involves two stages:

In this project we are generating the same friquencies whch are excately same as sa re ga ma pa dha ni sa by using the controller

PIANO WITH CONTROLLER-8051

CODE:-

#include<reg51.h>
sbit bu=P2^0;

void delay1on()
{
TMOD=0X01;
TH0=0Xf8;
TL0=0X80;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay2on()
{
TMOD=0X01;
TH0=0Xf9;
TL0=0X55;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay3on()
{
TMOD=0X01;
TH0=0Xfa;
TL0=0X00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay4on()
{
TMOD=0X01;
TH0=0Xfa;
TL0=0Xab;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay5on()
{
TMOD=0X01;
TH0=0XFB;
TL0=0X00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay6on()
{
TMOD=0X01;
TH0=0XFB;
TL0=0X80;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void delay7on()
{
TMOD=0X01;
TH0=0XFC;
TL0=0X00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
void delay8on()
{
TMOD=0X01;
TH0=0XFC;
TL0=0X40;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void main()
{

P2=0X00;
while(1)
{

if(P1==0xFE)
{
bu=~bu;
delay1on();

}
else if(P1==0xFD)
{
bu=~bu;
delay2on();
}
else if(P1==0XFB)
{
bu=~bu;
delay3on();

}
else if(P1==0XF7)
{
bu=~bu;
delay4on();

}
else if(P1==0XEF)
{
bu=~bu;
delay5on();

}
else if(P1==0XDF)
{
bu=~bu;
delay6on();

}
else if(P1==0XBF)
{
bu=~bu;
delay7on();

}
else if(P1==0X7F)
{
bu=~bu;
delay8on();

}
}
}

 

VEDIO:-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8051 Microcontroller based Pendulam operation

pendulam


DISCRIPTION:-

In this Project Multi-Pattern Running light is used to generate several designs of Running Lights. We use ten LED’s for display. The designs can be selected by using switches UP and DOWN. The 8 bit Microcontroller is used to control all the operations. It control the LED’s though the Ports.

The above system is monitored and controlled by the 8 bit microcontroller 8051. The Microcontroller continuously monitors the Switches and switch on/off the LED’s according to the Program. The Power for the circuit is derived from the Step down transformer and the 5V regulator IC7805. The regulator IC produces a constant 5v output.

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 PROGRAM*********************************************************/
void main()
{
int k;
start:                     //P1 PORT AS OUTPUT PORT,WITH VARIABLE K & SHIFT THE POSITION OF LED AMONG 8 PIN OF P1
while(1)
{
//______________ CODE FOR SHIFTING(LED GLOWING) IN DECREMENT ORDER ONE BY ONE ___________/

for(k=0x80;k>=0x01;k>>=1)     //LOOP FOR SHIFTING FROM 1-POSITION to LAST POSITION IN FORWARD

DIRECTION

{
P1=~k;                                                                            //LED GLOW AT P1 PORT FOR CORRESPONDIG POSITION OF K
delay(50);
if(k==0x01)                                     //CONDITION,WHEN LAST POSITION OCCUR DURING TRAVELLING IN FORWARD

DIRECTION
{
for(k=0x01;k<=0x40;k<<=1)                                                   //LOOP FOR SHIFTING IN REVERSE DIRECTION, FROM LAST

POSITION TO 2-POSITION
{
P1=~k;
delay(50);                                                                  //CALLING DELAY SUBROUTINE
if(k==0x40)                                                             //CONDITION,WHEN 2-POSITION OCCUR DURING TRAVELLING IN

REVERSE DIRECTION
{
for(k=0x40;k>=0x02;k>>=1)                                                  //LOOP FOR SHIFTING IN FORWARD DIRECTION, FROM 2-

POSITION TO 2nd LAST POSITION
{
P1=~k;
delay(50);
if(k==0x02)                                                               //CONDITION,WHEN 2nd LAST POSITION OCCUR DURING TRAVELLING IN

FORWARD DIRECTION
{
for(k=0x02;k<=0x20;k<<=1)                                                 //LOOP FOR SHIFTING IN REVERSE DIRECTION,FROM 2nd LAST

POSITION TO 3rd POSITION
{
P1=~k;
delay(50);
if(k==0x20)                                                                                     //CONDITION WHEN 3rd POSITION OCCUR DURING

TRAVELLING IN REVERSE DIRECTION
{
for(k=0x20;k>=0x04;k>>=1)                                                   //LOOP FOR SHIFTING IN FORWARD DIRECTION,FROM 3rd

POSITION TO 6th POSITION
{
P1=~k;
delay(50);
if(k==0x04)                                                                                             //CONDITION,WHEN 6th POSITION OCCUR DURING

TRAVELLING IN FORWARD DIRECTION
{
for(k=0x04;k<=0x10;k<<=1)                                                     //LOOP FOR SHIFTING IN REVERSE DIRECTION,FROM 6th

POSITION TO 4th POSITION
{
P1=~k;
delay(50);
if(k==0x10)                                                                                    //CONDITION WHEN 4th POSITION OCCUR DURING TRAVELLING

IN REVERSE DIRECTION
{
for(k=0x10;k>=0x08;k>>=1)                                                           //LOOP FOR SHIFTING IN FORWARD DIRECTION,FROM 4th

POSITION TO 5th POSITION
{
P1=~k;
delay(50);
if(k==0x08)                                                                                      //CONDITION,WHEN 5th POSITION OCCUR DURING

TRAVELLING IN FORWARD DIRECTION
{

/********CODE FOR SHIFTING(LED GLOWING) IN INCREMENT ORDER ONE BY ONE******************************/

for(k=0x08;k<=0x10;k<<=1)                                                           //LOOP FOR IN REVERSE DIRECTION,FROM 5th POSITION

TO 4th POSITION
{
P1=~k;
delay(50);
if(k==0x10)                                  //CONDITION,WHEN 4th POSITION DURING TRAVELLING IN REVERSE DIRECTION
{
for(k=0x10;k>=0x04;k>>=1)                                        //LOOP FOR SHIFTING IN FORWARD DIRECTION,FROM 4th

POSITION TO 6th POSITION
{
P1=~k;
delay(50);
if(k==0x04)                      //CONDITION,WHEN 6th POSITION OCCUR DURING TRAVELLING IN FORWARD DIRECTION
{
for(k=0x04;k<=0x20;k<<=1)                           //LOOP FOR SHIFTING IN REVERSE,FROM 6th POSITION TO 3rd POSITION
{
P1=~k;
delay(50);
if(k==0x20)                           //CONDITION,WHEN 3rd POSITION OCCUR DURING TRAVELLING IN REVERSE DIRECTION
{
for(k=0x20;k>=0x02;k>>=1)                          //LOOP FOR SHIFTING IN FORWARD,FORM 3rd POSITION TO 7th POSITION
{
P1=~k;
delay(50);
if(k==0x02)                             //CONDITION,WHEN 7th POSITION OCCUR DURING TRAVELLING IN FORWARD DIRECTION
{
for(k=0x02;k<=0x40;k<<=1)                             //LOOP FOR SHIFTING IN REVERSE,FROM 7th POSITION TO 2nd POSITION
{
P1=~k;
delay(50);
if(k==0x40)                              //CONDITION,WHEN 2nd POSITION OCCUR DURING TRAVELLING IN REVERSE DIRECTION
{
for(k=0x40;k>=0x01;k>>=1)                         //LOOP FOR SHIFTING IN FORWARD,FROM 2nd POSITION TO 8th POSITION
{
P1=~k;
delay(50);
if(k==0x01)                        //CONDITION,WHEN 8th POSITION OCCUR DURING TRAVELLING IN FORWARD DIRECTION
{
for(k=0x01;k<=0x80;k<<=1)                               //LOOP FOR SHIFTING IN REVERSE,FROM 8th POSITION TO 1st POSITION
{
P1=~k;
delay(50);
if(k==0x80)                               //CONDITION WHEN 1st POSITION OCCUR DURING TRAVELLING IN REVERSE DIRECTION
{
goto start;                       //CODE FOR REPEATING ALL ABOVE PROCESS FROM STARTING,SO JUMP TO “START” LEVEL
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

VEDIO:-

Controlling of Stepper Motor rotation in both direction using 8051 Microcontroller

STEPPER MOTOR ROTATION

DISCRIPTION:- 

Stepper motors consist of a permanent magnet rotating shaft, called the rotor, and electromagnets on the stationary portion that surrounds the motor, called the stator.  illustrates one complete rotation of a stepper motor. At position 1, we can see that the rotor is beginning at the upper electromagnet, which is currently active (has voltage applied to it). To move the rotor clockwise (CW), the upper electromagnet is deactivated and the right electromagnet is activated, causing the rotor to move 90 degrees CW, aligning itself with the active magnet. This process is repeated in the same manner at the south and west electromagnets until we once again reach the starting position

 

CIRCUIT DIAGRAM:-

CODE:-

#include<reg51.h>
sbit sw=P2^5;
void delay(unsigned int a)
{
unsigned int i,j;
for(i=0;i<a;i++)
for(j=0;j<1275;j++);
}
void main()
{
P2=0XFF;
while(1)
{
if(sw==1)
{
P1=0X66;
delay(100);
P1=0XCC;
delay(100);
P1=0X99;
delay(100);
P1=0X33;
delay(100);
}
else
{
P1=0X66;
delay(100);
P1=0X33;
delay(100);
P1=0X99;
delay(100);
P1=0XCC;
delay(100);
}
}
}

 

Stack POP Operation through 8051 Microcontroller

led pop


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 :-


}

Automatic Water Level Controller

water level indicator circuit

DISCRIPTION:-

This circuit works on the principle that water conducts electricity. Two wires connected to VCC and two other wires are dipped in tank at different levels namely top & bottom and their output are taken on pins P2.6, P2.7 via  transistor BC547. Port P1 is connected to data pins of LCD and P3.2, P3.3, P3.4 are respectively connected to RS, RW, and EN pins of LCD.

Initially when the tank is empty,motor will be on automatically & LCD will show the message Motor on. As the tank starts filling up wire at different levels get some positive voltage, due to conducting nature of water. This voltage is then fed to their corresponding pins on controller. When tank gets full,motor will be on automatically & LCD shows the message Motor Off.

CODE:-

#include<reg52.h>
sbit q=P2^6;
sbit r=P2^7;
sbit t=P2^0;
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;
sfr lcddata=0x90;
void delay(unsigned char a)
{
unsigned char i,j;
for(i=0;i

Digital Clock With 8051 Microcontroller

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

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

}