Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

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

By Himanshu Choudhary September 4, 2010

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
 

Next Article

← Previous Article
Next Article →

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



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

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!


RSS EDABOARD.com Discussions

  • GanFet power switch starts burning after 20 sec
  • RF-DC rectifier impedance matching
  • Inverting OpAmp - basic circuit question
  • 12VAC to 12VDC 5A on 250ft 12AWG
  • Precision CAD Drafting Services for Architectural & Engineering Projects

RSS Electro-Tech-Online.com Discussions

  • LED circuit for 1/6 scale diorama
  • stud mount Schottky diodes
  • Hi Guys
  • using a RTC in SF basic
  • Can I use this charger in every country?

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Fischer connector system adds ratchet locking system designed for 300g shock resistance
  • Littelfuse introduces tactile switch with enhanced bracket peg design for mounting strength
  • Infineon releases GaN switch with monolithic bidirectional design
  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 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

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe