We are Apogeeweb Semiconductor Electronic

WELCOME TO OUR BLOG

Home  Product Technical Articles   DS1302 Real Time Clock Circuit

DS1302 Real Time Clock Circuit

Author: Iggy
Date: 14 Oct 2020
 664
ds1302 features

I Description

In daily life, calendar clocks are used in various places. Such as shopping malls, supermarkets, offices, homes, schools, etc. Compared with the traditional mechanical clock, the digital calendar clock has a series of advantages. Such as high precision, intuitive display, and long life. This blog introduces a calendar clock designed with a DS1302 rtc chip.

DS1302 RTC with Arduino Tutorial

Catalog

I Description

II System Hardware Design

2.1 Overall Structure

2.2 DS1302 Clock Module

2.3 LCD1602 LCD Module

III System Software Design

3.1 Design of DS1302 Clock Subprogram

3.2 LCD 1602 Liquid Crystal Display Subprogram Design

IV Conclusion

FAQ

Ordering & Quantity

II System Hardware Design

2.1 Overall Structure

Take AT89C51 single-chip microcomputer as the main controller, and use DS1302 clock chip to design calendar clock. Its overall structure is shown in Figure 1.

ds1302 real time clock system

Figure 1. Overall Structure of System

The designed calendar clock must not only display hours, minutes and seconds, but also display years, months, days and weeks. The core of the system is the AT89C51 microcontroller. Through the single-chip computer control DS1302 display calendar and time. And the output result is displayed on LCD1602 liquid crystal screen.

2.2 DS1302 Clock Module

The DS1302 clock chip has the characteristics of low power consumption and high performance. It can communicate with the microcontroller through a simple synchronous serial mode, and only requires three I/O lines. Namely reset (RST), I/O data line and serial clock (SCLK)

2.2.1 DS1302 Pins and Structure

Figure 2 shows the external pins and functions of DS1302.

ds1302 pinoutFigure 2. DS1302 Pinout

  • VCC2-main power supply pin; X1, X2-32.768kHz crystal oscillator pin; GND-ground;
  • VCC1-battery pin; SCLK-serial clock; I/O-data input/output; RST-reset.

The internal structure of DS1302 is shown in Figure 3, which is mainly composed of the following parts: real-time clock, data memory RAM, oscillator circuit and frequency divider, input shift register, command and control logic and so on.

2.2.2 DS1302 Registers and control commands

The DS1302 clock chip has 7 registers related to the calendar clock, as shown in Table 1.

The communication signal between DS1302 and single-chip microcomputer is realized through simple synchronous serial communication.

According to the working timing requirements of DS1302, whether the single-chip microcomputer performs read operation communication from DS1302 or the single-chip computer performs write operation communication to DS1302, each communication is initiated by the single-chip computer first.

In other words, before executing the corresponding read or write operation, the microcontroller must write a byte of command word to DS1302. The eight-bit data of the byte command word is shown in Figure 4.

command word structure of ds1302

Figure 4. Command word structure of DS1302

2.3 LCD1602 LCD Module

The LCD1602 screen can display two lines of characters, 16 characters per line, for a total of 32 characters. There is an 80*8-bit display data memory DDRAM buffer in LCD1602. See Table 2 for the correspondence between character display bits and DDRAM address.

The address on the first line of DDRAM starts at 00H and ends at 27H. The addresses on the second line start at 40H and end at 67H, with 40 addresses per line. And LCD1602 displays 16 characters per line. Therefore, when writing a program, select the first 16 addresses of DDRAM. It is important to note that the second line address starts from 40H.

If you want to display a character in a certain row and certain column of the LCD1602 screen, write the ASCII code corresponding to this character into the corresponding DDRAM address of a certain row and certain column. At this time, you will find that the character cannot be displayed normally on the LCD screen. The reason is that 80H must be added to the address.

For example, to display the symbol "V" in the second row and second column of the voltage unit volts, first add 80H to the corresponding DDRAM address 41H in the second row and second column, that is, C1H. Then write the ASCII code 0x56 corresponding to the "V" character in the C1H address. Only then can it be displayed normally. The display of other characters can be deduced by analogy and will not be repeated here.

III System Software Design

The software program mainly completes the functions of data reading, conversion and liquid crystal display of the calendar clock.

3.1 Design of DS1302 Clock Subprogram

  sbit RST=P1^0; // DS1302 reset port is defined in P1.0 pin

  sbit SCLK=P1^1; // The DS1302 clock output port is defined on the P1.1 pin

  sbit DATA=P1^2; // The DS1302 data output port is defined on the P1.2 pin

(1) The program that the single-chip microcomputer writes a byte of data to DS1302

  void wright1302 (unsigned char date)

  {Unsigneed char i;

  SCLK = 0; //Be prepared for the rising edge to write data

  Delaynus (2);

  for (i=0; i<8; i++) // Write eight-bit data continuously

  {DATA=date&0x01; //Write the bit0 data of date into DS1302

  Delaynus (2);

  SCLK = 1; // Write data on rising edge

  Delaynus (2);

  SCLK = 0; //

  date>>=1; // move one place to the right}}

(2) The program for the single-chip microcomputer to read a byte of data from DS1302

  unsigned char readd1302 (void)

  {Unsigned char i, date;

  Delaynus (2);

  for (i=0; i<8; i++) // Continuously read eight-bit data

  {Date>>= 1; // shift one bit to the right

  if (DATA==1) // If the data read out is 1

  date| = 0x80; // Take out 1 and write it in the highest bit of date

  SCLK = 1; // Set SCLK to a high level, read out for the falling edge

  Delaynus (2);

  SCLK = 0; // Pull down SCLK to form the falling edge of the pulse

  Delaynus (2);}

  return date; //Return the read data}

3.2 LCD 1602 Liquid Crystal Display Subprogram Design

The driver program of LCD 1602 LCD screen is relatively complicated to compile, so we must figure out the usage and meaning of each operation instruction of 1602. Mainly include the following:

  • Display mode setting
  • Display switch control
  • Input mode control
  • Read data from DDRAM
  • Write data to DDRAM
  • Clear screen, cursor home setting
  • Data address pointer setting
  • LCD's current busy work sign
  •  ...

Part of the code design is as follows:

  void Lcd _ initial () //Initialize LCD

  {E=0;

  Lcd _ writecmd (0x38); // 16*2 display, 5*7 dot matrix

  Msdelay (1);

  Lcd _ writecmd (0x08); // display off

  Msdelay (2);

  Lcd _ writecmd (0x01); // display clear screen

  Msdelay (2);

  Lcd _ writecmd (0x06); //Set the cursor, after reading and writing a character, the cursor increases by 1

  Msdelay (1);

  Lcd _ writecmd (0x0c ); // display is on, no cursor is displayed

  Msdelay (1);}

Hardware power supply diagram of DS1302 calendar clockFigure 5. Hardware power supply diagram of DS1302 calendar clock

In the Medwin V3.0 development environment, use C51 language to compile the system program, compile and debug. And load the HEX hexadecimal file generated by compiling into the MCU chip. Start the simulation and you can see the simulation running effect of the DS1302 calendar clock design system based on 1602 LCD display. For example, the current time is 11:42:25 on May 28, 2019, and the simulation result is shown in Figure 6.

Simulation results of calendar clockFigure 6. Simulation results of calendar clock

It can be seen from Figure 6 that the current date and time can be displayed on the LCD screen in real time and accurately.

IV Conclusion

Calendar clocks are everywhere in our lives. This text takes AT89C51 single-chip microcomputer as the main controller, and uses DS1302 real-time clock chip to design the calendar clock system. In addition, the hardware circuit was designed in the Proteus simulation software, and the corresponding C51 program was written in the Medwin V3.0 development environment. The joint use of these two softwares, Proteus and MedWinV3.0, greatly improves the efficiency of single-chip system design, reduces costs, and shortens the development cycle.


FAQ

  • What is DS1302?

DS1302 is a tickle-charge timekeeping chip which contains a real-time clock/calendar and 31 bytes of static RAM. DS1302 uses serial communication to interact with microcontrollers. Also, it automatically adjust the date for the month with fewer days.

  • What does an RTC do?

A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. Although the term often refers to the devices in personal computers, servers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.

  • How do you use RTC?

Wiring It Up.
5V is used to power to the RTC chip when you want to query it for the time. If there is no 5V signal, the chip goes to sleep using the coin cell for backup.
Connect GND to common power/data ground.
Connect the SCL pin to the I2C clock SCL pin on your Arduino. ...
Connect the SDA pin to the I2C data SDA pin on your Arduino.

Ordering & Quality

Photo Mfr. Part # Company Description Package PDF Qty Pricing
(USD)
DS1302 DS1302 Company:Maxim Integrated Remark:Real Time Clock (RTC) IC Clock/Calendar 31B 3-Wire Serial 8-DIP (0.300", 7.62mm) Package:8-DIP (0.300"", 7.62mm)
DataSheet
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302 DS1302 Company:Maxim Integrated Remark:Timekeeper IC, Date Time Format (Day/Date/Month/Year hh:mm:ss), 3 Wire, Serial, 2 V to 5.5 V, DIP-8 Package:PDIP-8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302N DS1302N Company:Maxim Integrated Remark:Trickle-Charge Timekeeping Chip Package:PDIP-8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302N DS1302N Company:Maxim Integrated Remark:RTC IC, Date Time Format (Day/Date/Month/Year hh:mm:ss), Serial, 2 V to 5.5 V, DIP-8 Package:PDIP-8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302S DS1302S Company:Maxim Integrated Remark:Trickle-Charge Timekeeping Chip Package:SOP8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302S DS1302S Company:Maxim Integrated Remark:RTC IC, Date Time Format (Date/Month/Year hh:mm:ss), Serial, 2 V to 5.5 V, SOIC-8 Package:SOP8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302S-T-R DS1302S-T-R Company:Maxim Integrated Remark:RTC IC, Date Time Format (Day/Date/Month/Year hh:mm:ss), Serial, 2 V to 5.5 V, WSOIC-8 Package:SOIC-8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302S-16 DS1302S-16 Company:Maxim Integrated Remark:Trickle Charge Timekeeping Chip Package:SOIC-16
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302SN DS1302SN Company:Maxim Integrated Remark:Real Time Clock Trickle-Charge Timekeeping Chip Package:SOIC-8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry
DS1302SN-T DS1302SN-T Company:Maxim Integrated Remark:Trickle Charge Timekeeping Chip Package:SOP-8
N/A
In Stock:On Order
Inquiry
Price:
Call
Inquiry

Related Articles

LP2951 Voltage Regulator: Application, Circuit, Pinout

Iggy 7 Apr 2021  503

What is LP2951? The LP2951 is a bipolar, low-dropout voltage regulator. The LP2951 regulator is usually used in applications that require a preset output voltage, which can be easily configured using...

Continue reading »

74LS00 Nand Gate: Pinout, Parameter, Specification [Video]

Mia 5 Mar 2021  2177

74LS00 contains 4 independent gates each of which performs the logic NAND function. The 74LS00 is one of the best known and most basic of a series of logic gates.   There are three gates, AND,...

Continue reading »

2N2907 Transistor: Datasheet, Equivalent, Circuit [Video]

Iggy 6 Jan 2021  1471

2N2907 is basically a PNP bipolar junction transistor (BJT) which is mainly designed for switching and low power general purpose amplification applications. It has an ability to operate at high speed ...

Continue reading »

74LS32 Dual Input OR Gate Introduction [Video]

Mia 30 Mar 2021  639

74LS32 is a Dual Input OR Gate with Quad package.    It contains four independent gates, each performing the logic OR function. Each gate has two inputs, which is why it is called Quad 2-I...

Continue reading »

UA741 Op Amp: A Basic Overview [FAQ]

Mia 5 Mar 2021  632

UA741 is a general-purpose operational amplifier featuring offset-voltage null capability.   In this blog today, we will walk you in the detailed introduction of UA741 op amp device, ...

Continue reading »

0 comment

Leave a Reply

Your email address will not be published.

 
 
   
 
Rating:

# 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z