Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

How to Interface RTC DS12C887 with 8051 microcontroller (AT89C51)- (Part 33/45)

By Himanshu Choudhary

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.

 
The article presented here shows how RTC can be interfaced with the microcontroller AT89C51. It explores the basic operation of accessing the internal registers and extracting time from the RTC. The time is displayed on the hyper terminal using serial communication. The RTC used here is DS 12C887. 89C51 microcontroller is a very commonly used controller from the family of 8051 series of microcontroller.
 
Our forthcoming articles and projects on RTC DS12C887 and 8051 microcontroller will further explore RTC’s interrupts and help you in making applications based on RTC and microcontroller.
For more details on RTC12C887, click here.
 
 

 


 

 

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.

 
Note: This RTC is shipped with internal oscillator turned off to prevent the discharge of lithium battery. If you are interfacing the RTC for the first time i.e. the RTC is absolutely new, then you need to turn on the oscillator through your program. This is done by setting a pattern of 010 in bits 4-6 of register A. The code in this article shows how to set these bits. Once set the RTC will keep updating itself even if you are not using it and keeping it in store. Whenever you are using the RTC for the next time you need not turn on the oscillator. Hence in our future articles you will not find such steps in code. 
 
This code provides the way to interface an RTC with a microcontroller and extract data from it and send it to the computer through serial port.
 
The code uses the XBYTE macro which is defined in the header file ‘absacc.h’ to access external memory peripherals interfaced with the microcontroller. The use of macro simplifies the read and write operations of the RTC. The XBYTE macro takes care of the control signals needed to read and write data to the RTC thus making the interfacing easy for us.
 
The source code for interfacing RTC DS12C887 with 8051 microcontroller AT89C51 is written in C. First of all the clock is set, through XBYTE, with the time which we want (defined in microcontroller) to start the clock. Then the time kept in the clock is extracted through XBYTE and sent to PC’s hyper terminal through serial port.
 

 

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

Circuit-Diagram-Of-Interface-RTC-DS12C887-With-8051-Microcontroller-AT89C51

Project Components

  • AT89C51 Microcontroller
  • MAX232
  • RTC DS12C887

Project Video


Filed Under: 8051 Microcontroller
Tagged With: 8051, ds12c887, microcontroller
 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Designing Gate Driver Circuit and Switching Mechanism for Modified Sine Wave Inverter – (Part 9/17)
  • Completing Modified Sine Wave Inverter Design with Full Bridge Circuit and Step Up Transformer – (Part 10/17)
  • Designing an Offline UPS – Part (12 /17)
  • How to reduce Switching Time of a Relay – (Part 15/17)
  • Testing MOSFET – (Part 16/17)
  • Driving High Side MOSFET using Bootstrap Circuitry – (Part 17/17)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • Renesas to demonstrate first working silicon based on the Arm Cortex-M85 processor
  • STMicroelectronics releases first automotive IMU with embedded machine learning
  • Infineon offers DC-DC controller for full LED headlamps without a microcontroller
  • Vishay launches new high-precision, thin-film wraparound chip resistor
  • STMicroelectronics’ common-mode filters ensure signal integrity in serial interfaces

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Temperature sensor readout
  • Capacitive Switches
  • CSI-2 FIFO or Line buffer?
  • What is the function of the long stub?
  • Circuit Performance Exploration

RSS Electro-Tech-Online.com Discussions

  • software PWM
  • Opamp ciruit
  • Audio equalizer
  • Background of Members Here
  • SPI Questions
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering