This clock works in 12 hour mode and is configured by programming the microcontroller AT89C51. The program uses a delay function for producing a delay of 1 second.
The connections in the circuit are as following: port P2 of microcontroller is used as data input port which is connected to data pins (7-14) of LCD. P3^0, P3^1 and P3^6 pins of microcontroller are connected to control pins RS, RW and EN of LCD. P1^0, P1^1, P1^2 and P1^3 pins of microcontroller are connected to tactile switches to take manual inputs.
On reset, the LCD prompts the user to set time. Only the hour and minute components can be set by pressing the corresponding switches, repeatedly. These switches are made active low and so they provide ground to the corresponding input pins of the controller. The AM/PM mode is set by toggling the switch between ground and Vcc. Ground would set the clock in AM mode while Vcc would set it in PM mode. The clock starts when start pin is connected to Vcc by pressing the switch.
The set time is displayed on LCD screen and changes as the time passes on. Seconds are increased after every one second by making use of delay function. As second reaches 59, minute is incremented by one and second is reset to 0. Similarly, as minute reaches 59, hour is increased by one and minute is set to 0. After hour reaches 11, minute reaches 59 and second reaches 59, all of them are set to 0 and the AM/PM mode is changed accordingly.
Project Source Code
###
// Program to make a digital clock using LCD #include<reg51.h> #define cont_port P3 #define port P1 #define dataport P2 // Data port for LCD #define m_sec 10 sbit rs = cont_port^0; sbit rw = cont_port^1; sbit en = cont_port^6; sbit dig_hr1=port^0; sbit dig_min1=port^1; sbit start=port^2; sbit am_pm=port^3; int hr ,hr1=0; int min,min1=0; int sec,sec1=0,dig_am_pm=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 { dataport = item; rs= 0; rw=0; en=1; delay(1); en=0; return; } void lcd_data(unsigned char item) // Function to send data on LCD { dataport = 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]!='