Real time clock (RTC) is widely used in many application to provide accurate time. This article explains the making of a simple digital clock using RTC DS12C887 and 8051 microcontroller (AT89C51). The output is displayed on an LCD. This clock also has a provision of setting time at any instant. The clock uses the concept of our earlier articles of interfacing RTC DS12C887 with microcontroller. The clock described here uses the method of polling for running. For further details on interfacing RTC DS12C887 with AT89C51 using polling, refer RTC interfacing. The free source code for the program is available in C.
The circuit diagram shows the connection of RTC with the microcontroller. Port P2 is used as data port for LCD; port P0 of the microcontroller is used as data port of RTC DS12C887. The pins P1^0, P1^1, P1^2, P1^3, P1^4, P1^5, P1^6 of controller AT89C51 are configured as reset, rs, rw, e, dig_hr1, dig_min1, start pins respectively.
Project Source Code
###
//Program for Digital clock using RTC DS12C887 and 8051 microcontroller (AT89C51) with time set /*24 hr clock set p3^3=0,then start=0 then set time by dig_hr1 & dig_min1, then remove p3^3 & start */ #include<reg51.h> #include<absacc.h> #define dataport P2 #define port P1 #define lcdport P3 sbit reset = port^0; sbit rs =port^1; sbit rw =port^2; sbit e = port^3; sbit dig_hr1=port^4; sbit dig_min1=port^5; sbit start=port^6; int min1=0,hr1=0; int min0=60,hr0=25; unsigned char temp=60,hr,min,sec,num[60]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0X09,0X10,0X11,0X12,0X13,0X14,0X15,0X16,0X17,0X18,0X19,0X20,0X21,0X22,0X23,0X24,0X25,0X26,0X27,0X28,0X29,0X30,0X31,0X32,0X33,0X34,0X35,0X36,0X37,0X38,0X39,0X40,0X41,0X42,0X43,0X44,0X45,0X46,0X47,0X48,0X49,0X50,0X51,0X52,0X53,0X54,0X55,0X56,0X57,0X58,0X59}; void delay(unsigned int msec ) { int i ,j ; for(i=0;i<msec;i++) for(j=0; j<1275; j++); } void lcd_cmd(unsigned char item) { dataport = item; rs= 0; rw=0; e=1; delay(1); e=0; return; } // function to send data void lcd_data(unsigned char item) { dataport = item; rs= 1; rw=0; e=1; delay(1); e=0; return; } void lcd_data_string(unsigned char *str) { int i=0; while(str[i]!='