RTC interfacing
Real Time Clock (RTC) is widely used
device that provides accurate time & date
for many applications. Eg:The x86 IBM PC
come with such a chip on the
motherboard.The RTC chip in the IBM PC
provides time components of hour,minute
& second,in addition to the date/calander
components of year, month & day.The RTC
chip uses an internal battery which keeps
the time & date even when power is off.
DS 12887 RTC Chip
VCC
Pin 24 provides external supply
voltage to the chip
The external voltage source is + 5
volt.
When VCC falls below the 3 volts
level, the external source is switched
off and the internal Li battery
provides power to the RTC
GND: Pin 12 is ground
AD0-AD07: The multiplex address/ data
pins provides both addresses and data
to the chip. A simple way of connecting
DS12887 to the 8051 is shown in the
figure. AD0-AD07 are connected directly
to P0 of the 8051.
DS 12887 connection to
8051
AS (ALE) : AS( address strobe) is an i/p
pin.The AS pin is used for demultiplexing
the address & data & is connected to the
ALE pin of the 8051 chip
MOT: is an i/p pin that allows the choice
between motorola & intel microcontroller
bus timing.That means when we connect
DS12887 to the 8051, MOT=GND
DS: Data Strobe or READ is an i/p
pin.When MOD= GND for Intel
timing,the DS pin is called the RD
signal& is connected to the RD pin of
the 8051
R/W: is an i/p pin.When MOD= GND
for Intel timing, the R/W pin is called
the WR signal& is connected to the
WR pin of the 8051
CS: is an i/p pin & active low
signal.CS only works when the
external Vcc is connected.When Vcc
falls below 4.25v ,the chip select i/p
is internally forced to an inactive
level.This is called write-protected
state. When chip is in write-protected
state, all i/ps are ignored
IRQ: Interrupt Request is an o/p pin &
active low signal.To use IRQ,the interrupt
enable bits in registerB must be set high
SQW: Square Wave is an o/p pin. The
frequency of the square wave is set by
programming register A
RESET: PIN 18 is an reset pin. It is an input
and is active low pin. In most applications
the reset pin is connected to the Vcc.
The DS 12887 has total of 128 bytes of RAM
space with addresses 00-7FH.
The first 10 locations, 00-09 are set aside for
RTC values of time calendar and alarm data.
The next 4 bytes are used for the control
and status registers.
The registers are A,B,C & D and are located
at addresses 10-13(0A-0D in hex).
The addresses 0EH to 7FH are available for
data storage.
Address map
Turning on the oscillator for the first
time
For turning on oscillator bits D6-D4 of
register A must be set to value 010
Codes to Access the
DS12887
ACALL DELAY_200ms; RTC needs
200ms after
power-up
MOV R0,#10; R0=0AH, register A
address
MOV A,#20H; 010 in D6-D4 to turn on
oscillator
MOVX @R0, A; send it to Register A of
DS12887
Setting the time
When we initialize time or date, we
need to set the D7 of register B = 1.
this will prevent any update at the
middle of the initialization. after
setting the time and date we need to
make D7=0 to make sure that the
clock and time are updated. The
update occurs once per second.
The format of register B -
The following code initialize the clock at 16:58:55 using the BCD
mode and the 24 hour clock mode with day light saving time
Setting the date
When we initialize time or date, we need to set D7 of register B to 1
October 19th
2004