Tuesday, 14 May 2013

DIGITAL CLOCK WITH 8051

Here is a LCD based Digital Clock project using only 8051. This digital clock is configured in a 12 hour mode and switches are given for set the hours, minutes, and AM/PM.

Note :-
              Use push on - push off switches here do not use toggle switches for set the hours, minute, am/pm and start. For reset of microcontroller use toggle switch.

Circuit Diagram :-
                   

 download and zoom in the photo so you can clearly all the connections.

Pink lines - 12 volt
Red lines - 5 volts
Black lines - ground
Blue lines - data


Components Required :-

7805 IC - 1
1N4007 diode - 1
330 0HM RESISTANCE - 2
10K OHM RESISTANCE - 2
10K OHM VARIABLE RESISTANCE - 1
33PF CAPACITOR - 2
10UF CAPACITOR - 1
1000UF CAPACITOR - 1
11.0592 MHZ CRYSTAL OSCILLATOR - 1
GREEN LED - 1
RED LED - 116X2 LCD - 1
12 volt battery upto 1.5 amp. -1
P89V51RD2 MICROCONTROLLER - 1
TOGGLE BUTTON - 1
PUSH ON-OFF SWITCH - 1
16x2 LCD - 1
MALE AND FEMALE CONNECTORS LINES
CONNECTING WIRES.



Process to set Time :-

Start button - 1st button
hour set - 2nd button
minute set - 3rd button
am-pm set - 4th button


  • push the start button. (start button off and clock do not start)
  • now push the hour or minute buttons according to set time (do no push repeatedly push only one time).
  • Now Push off the hour and minute buttons for stopping the time increasing.
  • Push the am-pm button according to the am-pm
  • Now push on the start button now for starting the clock. 


Code :-

----------------------------------------------------------------------------------------------------------------------------------

// Program to make a digital clock using LCD

#include<reg51.h> 
#define m_sec 10
sbit rs = P3^0;
sbit rw = P3^1;
sbit en = P3^2;
sbit hrs=P1^1;
sbit mns=P1^2;
sbit start=P1^0;
sbit am_pm=P1^3;
int hr ,hr1=0;
int min,min1=0;
int sec,sec1=0,ampm=0;

void delay(unsigned int msec)   // Time delay funtion
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0;j<1275;j++);
}

                
void lcd_cmd(unsigned char item)   // Function to send command on LCD
{
P2 = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item)  // Function to send data on LCD
{
P2 = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str)  // Function to send string on LCD
{
  int i=0;
  while(str[i]!='\0')
{
    lcd_data(str[i]);
    i++;
    delay(1);
}
return;
}

lcd_data_int(int time_val)   // Function to send number on LCD
{
int int_amt;
int_amt=time_val/10;
lcd_data(int_amt+48);
int_amt=time_val%10; 
lcd_data(int_amt+48);
}

void lcd(unsigned char str1[10])  // Function to initialize LCD
{
lcd_cmd(0x38);  //2 LINE, 5X7 MATRIX
lcd_cmd(0x0e);  //DISPLAY ON, CURSOR BLINKING
delay(m_sec);
lcd_data_string(str1);
}

void set_hr1()  // Function to set hour
{
hr1++;
if(hr1>11)
hr1=0;
lcd_cmd(0xc3);
lcd_data_int(hr1);
lcd_data(':');
}

void set_min1()  // Function to set minute
{
min1++;
if(min1>59)
min1=0;
lcd_cmd(0xc6);
lcd_data_int(min1);
}

void main()
{
int k;
start=1;
hrs=1;
mns=1;
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd("SET TIMING");
lcd_cmd(0xc3);
lcd_data_int(hr1);
lcd_data(':');
lcd_data_int(min1);
while(start==0)
{
  delay(200);
  if(hrs==0)
  set_hr1();
  if(mns==0)
  set_min1(); 
}

if(am_pm==0)
{
  lcd_cmd(0xc8);
  lcd_data_string("am");
  ampm=0;
}

if(am_pm==1)
{
  lcd_cmd(0xc8);
  lcd_data_string("pm");
  ampm=1;
}
delay(200);
lcd_cmd(0x01);
while(1)
{
  for(k=0;k<2;k++)
  {
   for(hr=hr1;hr<12;hr++)
   {
    for(min=min1;min<60;min++)
     {
      for(sec=0;sec<60;sec++)
      {
       lcd_cmd(0x82);
       delay(1);
       lcd_data_int(hr);
       lcd_data(':');
       lcd_data_int(min);
       lcd_data(':');
       lcd_data_int(sec);
       if(ampm==0)
       {
        lcd("am");
       }
       else
       {
        lcd("pm");
       }
       lcd_data_string("    ");
       delay(100);
      }
     }
    min1=0;
    }
  if(ampm==0)
  ampm=1;
  else
  ampm=0;
  hr1=0;
  }
}
}



 ---------------------------------------------------------------------------------------------------------------------------------
Calculations in this program are standard.

Pictures :-



                   

Video :-



Proteus video :-




IF YOU HAVE ANY QUERY THAN CONTACT US OR GIVE YOUR QUERY IN THE QUERY OPTION.      
                                                            GOOD LUCK

More embedded projects >>....                                                More MAT LAB projects>>...