DS12C887 is a real time clock (RTC) IC from Dallas Semiconductors. The RTCs provide precise time and date information. This article explains the making of a digital clock with alarm setting functionalities. RTC has been interfaced with AT89C51 to perform desired operations. This project is an improvement over Digital clock using RTC DS12C887 and 8051 microcontroller (AT89C51) with time set and has the alarm setting function also. The alarm setting function allows user to set the alarm. The clock time is displayed on the LCD. The free source code for the program is available in C.
The circuit for interfacing the RTC and 16×2 LCD with the microcontroller 8051 is shown in the circuit diagram. Port P2 is set as data port for LCD to send the data on the LCD while port P0 is set as data port for the RTC DS12C887. This is used to extract the time, date and other information from the RTC. The pins of port P1 and P3 of the controller AT89C51 are used to provide the input signals for setting the time, alarm etc. They also provide control signals for the RTC and the LCD.
Project Source Code
###
//Program for Digital Clock using RTC DS12C887 & 8051 microcontroller (AT89C51) with alarm set function /*24 hr clock set p3^3=0,then start=0 them set time by dig_hr1 & dig_min1, then remove p3^3 & start */ #include<reg51.h> #include<absacc.h> #define dataport P2 // Dataport for LCD #define port P1 #define alarm 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 digalarm_hr1=alarm^4; sbit digalarm_min1=alarm^5; sbit alarmport=alarm^0; sbit start=port^6; int min1=0,hr1=0,alarmmin1=0,alarmhr1=0; int min0=60,hr0=25; unsigned char sec0=60,min00,hr00,hr,min,sec,alarmmin,alarmhr; void delay(unsigned int msec ) { int i ,j ; for(i=0;i<msec;i++) for(j=0; j<1275; j++); } unsigned char num(int d) { switch(d) { case 0:{ return 0x00; break; } case 1:{ return 0x01; break; } case 2:{ return 0x02; break; } case 3:{ return 0x03; break; } case 4:{ return 0x04; break; } case 5:{ return 0x05; break; } case 6:{ return 0x06; break; } case 7:{ return 0x07; break; } case 8:{ return 0x08; break; } case 9:{ return 0x09; break; } case 10:{ return 0x10; break; } case 11:{ return 0x11; break; } case 12:{ return 0x12; break; } case 13:{ return 0x13; break; } case 14:{ return 0x14; break; } case 15:{ return 0x15; break; } case 16:{ return 0x16; break; } case 17:{ return 0x17; break; } case 18:{ return 0x18; break; } case 19:{ return 0x19; break; } case 20:{ return 0x20; break; } case 21:{ return 0x21; break; } case 22:{ return 0x22; break; } case 23:{ return 0x23; break; } case 24:{ return 0x24; break; } case 25:{ return 0x25; break; } case 26:{ return 0x26; break; } case 27:{ return 0x27; break; } case 28:{ return 0x28; break; } case 29:{ return 0x29; break; } case 30:{ return 0x30; break; } case 31:{ return 0x31; break; } case 32:{ return 0x32; break; } case 33:{ return 0x33; break; } case 34:{ return 0x34; break; } case 35:{ return 0x35; break; } case 36:{ return 0x36; break; } case 37:{ return 0x37; break; } case 38:{ return 0x38; break; } case 39:{ return 0x39; break; } case 40:{ return 0x40; break; } case 41:{ return 0x41; break; } case 42:{ return 0x42; break; } case 43:{ return 0x43; break; } case 44:{ return 0x44; break; } case 45:{ return 0x45; break; } case 46:{ return 0x46; break; } case 47:{ return 0x47; break; } case 48:{ return 0x48; break; } case 49:{ return 0x49; break; } case 50:{ return 0x50; break; } case 51:{ return 0x51; break; } case 52:{ return 0x52; break; } case 53:{ return 0x53; break; } case 54:{ return 0x54; break; } case 55:{ return 0x55; break; } case 56:{ return 0x56; break; } case 57:{ return 0x57; break; } case 58:{ return 0x58; break; } case 59:{ return 0x59; break; } } } 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]!='