The purpose of an RTC or a real time clock is to provide precise time and date which can be used for various applications. RTC is an electronic device in the form of an Integrated Chip (IC) available in various packaging options. It is powered by an internal lithium battery. As a result of which even if the power of the system is turned off, the RTC clock keeps running. They play a very important role in the real time systems like digital clock, attendance system, digital camera etc.
This project uses the method of polling to read the data from the RTC. In this method the data is continuously scanned and sent to hyper terminal for display. The connections of RTC DS 12C887 and serial port (RS232) with the 8051 microcontroller (AT89C51) are shown in the circuit diagram.
Project Source Code
###
//Program to interface RTC DS12C887 with 8051 microcontroller (AT89C51) #include<reg51.h> #include<absacc.h> char hr, min, sec; void delay(int time) { int i,j; for(i=0;i<time;i++) for(j=0;j<1275;j++); } serial(char x) // Function to transmit data serially using RS232 { SBUF=x; while(TI==0); TI=0; } void bcdconv(char mybyte) // Function to convert data into BCD format. { char x,y; x=mybyte&0x0F; x=x|0x30; y=mybyte&0xF0; y=y>>4; y=y|0x30; serial(y); serial(x) ; } void main() { TMOD=0x20; TH1=0xFD; SCON=0X50; TR1=1; delay(220); XBYTE[10]=0x20; delay(20); XBYTE[10]=0x30; XBYTE[11]=0x83; XBYTE[0]=0x55; XBYTE[2]=0x58; XBYTE[4]=0x16; XBYTE[7]=0x02; XBYTE[8]=0x02; XBYTE[9]=0x02; XBYTE[11]=0x03; while(1) { XBYTE[10]=0x20; delay(500); hr=XBYTE[4]; bcdconv(hr); serial(':'); min=XBYTE[2]; bcdconv(min); serial(':'); sec=XBYTE[0]; bcdconv(sec); serial(0x0D); serial(0x0A); } }
###
Circuit Diagrams
Project Components
Project Video
Filed Under: 8051 Microcontroller
Filed Under: 8051 Microcontroller
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.