This article is an improved version of LCD based clock using RTC DS12C887 and 8051 microcontroller (AT89C51) using update interrupt. DS12C887 has two modes of operation i.e., 12 hour and 24 hour mode. In our earlier articles we explained how to use 24 hour mode. This article explores how we can use the 12 hour mode of RTC. This is done by making a clock using RTC and 8051 microcontroller (AT89C51) with 12 hour mode operation. The clock time is displayed on a 16x2 LCD interface. 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 while port P0 of the microcontroller AT89C51 is used as data port for the RTC DS12C887. The pins P1^0 – P1^7 of the microcontroller are configured as reset, rs, rw, e, dig_hr1, dig_min1, start, setmode, am_pm pins respectively.
Project Source Code
###
//Program for Digital clock using DS12C887 & 8051 microcontroller (AT89C51) in 12 hour mode /*12hr clock set p3^3=0,then start=0 them set time by dig_hr1 & dig_min1, then remove p3^3 & start am:p1^7=0 pm:p1^7=1*/ #include<reg51.h> #include<absacc.h> #define dataport P2 #define port P1 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; sbit setmodeam_pm=port^7; int hr1=0; int min1=0; int modeam_pm=0,q,am_pm; unsigned char numhr[12]={0x81,0X82,0X83,0X84,0X85,0X86,0X87,0X88,0X89,0X90,0X91,0X92}; unsigned char temp,hr,min,sec,nummin[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; } // DATA SENDING FUNCTION 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]!='