RTC Interfacing With 8051 Microcontroller and Programming
RTC Interfacing With 8051 Microcontroller and Programming
The various kinds of RTC chips are available in the real time embedded world, which are
based on various criteria such as package type, supply voltage and pin configuration etc. A
of RTC devices are;
First, we need to select type of RTC device by category based on requirement like I2C Bus
Bus RTC or other, which suitsfor interfacingwith respective microcontroller. Then we
features of RTC device depending on requirement of application such as battery lif
package and clock frequency. Let us consider two-wire interfacing RTC with 8051 micr
such as DS1307.
RTC stands for real time clock which provides years, months, weeks, days, hours, m
seconds based on crystal frequency. RTC consists of inbuilt RAM memory for data storage
backup will be provided in case of failure of main power supply by connecting a batt
device.
VCC and GND: VCC and GND are power supply and ground pins respectively. This devic
with 1.8V to 5.5V range.
VBT: VBT is a battery power supply pin. Battery power source must be held between 2V to
SCL: SCL is a serial clock pin and it is used to synchronize data on serial interface.
SDL: It is a serial input and output pin. It is used to transmit and receive the data on serial i
OSC0 and OSC1: These are crystal oscillator pins which are used to provide the clock sig
RTC device. The standard quartz crystal frequency is 22.768KHzs.
Device Addressing:
I2C bus protocol allows many slave devices at a time. Every slave device must cons
address to represent on it. The master device communicates with particular slave de
address. RTC device address is “0xA2” wherein “1010” is given by manufacturer and A0,
user define address, which is used to communicate eight RTC devices on the I2C bus proto
Device Addresing
R/W bit is used to perform read and write operations in RTC. If R/W=0, write operation is
and R/W=1 for read operation.
RTC registers are located in address locations from 00h to 0Fh and RAM memory re
located in address locations from 08h to3Fh as shown in figure. RTC registers are used
calendar functionality and drive time of day and to display the weekends.
Control/Status Registers:
Control/Status Register2:
=1 Alarm match
RTC can be interfaced to microcontroller by using different serial bus protocols such as I2
protocols that provide communication link between them. The figure shows, real
interfacing with 8051 microcontroller using I2C bus protocol. I2C is a bi-directional seri
which consist of two wires such as SCL and SDA to transfer data between devices connec
8051 microcontroller has no inbuilt RTC device therefore we have connected externally
serial communication for ensuring the consisting data.
I2C devices have open drain outputs therefore, a pull-up resistors must be connected to th
line with a voltage source. If the resistors are not connected to the SCL and SDL lines, the b
work.
Since RTC interfacing with8051 microcontroller uses I2C bus therefore the data transf
form of bytes or packets and each byte is followed by an acknowledgement.
Start: Primarily, the data transfer sequence initiated by the master generating the start con
7-bit Address: After that the master sends the slave address in two 8-bit formats instead
16-bit address.
Control/Status Register Address: The control/status register address is to allow the contr
registers.
Control/Status Register1: The control status register1 used to enable the RTC device
R/W: If read and write bit is low, then the write operation is performed.
ACK: If write operation is performed in the slave device, then the receiver sends 1-bit ACK
microcontroller.
Stop: After completion of write operation in the slave device, microcontroller sends stop c
the slave device.
7-bit Address: After that the master sends slave address in two 8-bit formats instead of a
bit address.
Control/Status Register1: The control status register1 used to enable the RTC device
R/W: If read and write bit is high, then the read operation is performed.
ACK: If write operation is performed in the slave device, then the receiver sends 1-
microcontroller.
Stop: After completion of write operation in the slave device, microcontroller sends stop c
the slave device.
#include<reg51.h>
sbit SCL=P2^5;
sbit SDA=P2^6;
void start();
delay(unsigned char);
void main()
start();
write(0x02);//hours value//
}
void start()
delay(100);
delay(100);
for(k=0;k<8;k++)
SDA=(d&j);
J=j>>1;
SCL=1;
delay(4);
SCL=0;
SDA=1;
SCL=1;
delay(2);
c=SDA;
delay(2);
SCL=0;
void delay(int p)
unsignedinta,b;
For(b=0;b<p;b++);
#include<reg51.h>
sbit SCL=P2^5;
sbit SDA=P2^6;
void start();
void read();
void ack();
void main()
start();
read();
ack();
sec=value;
void start()
delay(100);
delay(100);
for(k=0;k<8;k++)
SDA=(d&j);
J=j>>1;
SCL=1;
delay(4);
SCL=0;
SDA=1;
SCL=1;
delay(2);
c=SDA;
delay(2);
SCL=0;
void delay(int p)
unsignedinta,b;
For(b=0;b<p;b++);
Void read ()
SDA=1;
for(j=0;j<8;j++)
SCL=1;
delay(100);
flag=SDA;
if(flag==1)
z=(z|q);
q=q>>1;
delay (100);
SCL=0;
void ack()
delay(100);
SCL=0;
These are the necessary steps for RTC interfacing with 8051 microcontroller. In addition
steps, data frames used for transferring and receiving the data is also discussed in this
user understanding with appropriate programming. For further any help regarding this co
can leave a comment below.
‹ PREVIOUS
RELATED CONTENT
What is Non-Inverting Op-Amp : What is an Absolute Encoder : What is a Rotameter : Working & What is Ro
Working & Its Applications Working & Its Applications Its Applications Working &
3 Comments
Afnas Says:
at
i need complete program to interface 8051 with RTC. can you please help me
RANJITH P Says:
at
Hello sir,I am getting warnings if i put the codes in keil software.can you please help out
Sravanthi Says:
at
I need the complete code for interfacing the rtc ds1307 with 8051 and display it on the lcd
Add Comment
Comment:
Name *
Email *
Website
Post Comment