Using DS12887 to make a clock that can still run without power

Publisher:shengjuLatest update time:2011-02-21 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

At first glance at the title, readers may wonder, what is this strange thing, and it can work without power? In fact, the author is just keeping it a secret here. What I mean is that it can run normally without an external power supply, not that the entire circuit does not need power when it is working. In other words, this clock does not need power when not in use. After you add power, it can display the time and it is still correct. It is like some mobile phones that are turned off and the power board is removed. When you turn it on next time, it can display the correct time again. In fact, these mobile phones all have backup batteries, that is, the small circuit of the clock is powered by the backup battery. If the backup battery is out of power, problems will arise after removing the power board. This is why some mobile phones that have been used for a long time will have the wrong time after removing the power board and installing it again. But the clock mentioned in this article does not need an external backup battery, so how does it do this? Please listen to me slowly.

Let's first understand the basic characteristics of the "protagonist". DS12887 is a real-time clock chip launched by Dallas Semiconductor. It integrates a quartz crystal, a lithium battery and other supporting circuits inside the chip. It can keep accurate time for 10 years without external power supply. It can count hours, minutes, seconds, years, months, days and weeks, and leap year compensation is valid until 2100. The internal alarm register is used to save the alarm time. When the real time is equal to the alarm time, the DS12887 IRQ ( ———— ) The pin outputs a low level, and the microcontroller can use this signal as an alarm signal. The author soldered the circuit with a multi-purpose board, and the actual picture is shown in Figure 1. The following will introduce how to use DS12887 to make this clock.

Chip Pins

After understanding the basic characteristics of the "protagonist", let's take a look at its pins. The pins of a chip can be regarded as a channel for "communication" with the outside world. If you understand the usage of the pins, you will know how to connect to the microcontroller. The chip pins are shown in Figure 2. The naming of some pins is different from the official data sheet. The original data sheet uses the naming method of Motorala bus timing. Here, for the sake of convenience, the naming method of Intel bus timing is used, because the 51 microcontroller used in this article is Intel timing. These two bus timings were originally used in chips produced by Motorala and Intel respectively. Interested friends can find more detailed information in the data sheet of DS12887. Pin MOT is the bus mode selection. DS12887 can have two timings: when MOT is connected to VCC, the Motorala bus timing is selected; when MOT is grounded or suspended, the Intel bus timing is selected. This article uses AT89S52 as the controller. As a typical 51 microcontroller, AT89S52 naturally uses Intel bus timing.

AD0~AD7 are address and data multiplexing lines, similar to the P0 port of the standard 51 microcontroller. They are used as address lines or data lines in the two time periods before and after a read/write cycle. They can be directly connected to the P0 port of AT89S52.

ALE is the address latch signal. Because the DS12887 data address line uses time-division multiplexing, ALE is needed as the address latch signal. In a read/write cycle, the first signal on the AD0~AD7 pins indicates the address, which is latched into the address register of the DS12887 through the falling edge of ALE. The signal on the AD0~AD7 pins later indicates the data written or read from the DS12887. ALE can be directly connected to the ALE pin of AT89S52.

RD ( ——— ) , WR ( ——— ) Read and write control signal pins, connected to AT89S52 RD ( ——— ) (P3.7), WR ( ——— ) (P3.6) pin. CS ( —— ) It is the chip select signal. When it is at a low level, the chip is selected. It can be connected to the P2.7 pin of AT89S52, so that the read and write base address of DS12887 can be formed: 0x0000.

IRQ ( ———— ) The pin is an interrupt output signal. When the DS12887 generates an interrupt, IRQ ( ———— ) The pin outputs a valid low level. This pin is an open-drain output and requires an external pull-up resistor. The reset function is not used in this design. RST ( ———— ) Can be directly connected to high level.

On-chip resources

After looking at the outside, go inside and take a look. The DS12887 has 10 bytes of clock (hour, minute, second), alarm (hour, minute, second) and calendar (year, month, day, week) registers and 4 control registers and 114 bytes of general RAM. The address allocation is shown in the attached table. In the design of this article, only the first 14 bytes of clock, alarm, calendar and control registers are used, and the remaining 114 bytes of RAM are not used. After adopting the circuit diagram shown in Figure 3, the 14 bytes of address allocation in the chip are from 0x0000 to 0x000D. In the program, data can be read and written to these addresses as easily as accessing external RAM. 0x0000 to 0x0009 are clock, alarm and calendar registers, which retain time information and other related content. The microcontroller can display the time information by reading these contents. BIT6 to BIT5 of register A control the shutdown of the internal crystal oscillator of DS12887. Register B controls the enablement of various interrupts. In this article, the alarm enable bit (BIT5) needs to be turned on. BIT2 determines whether the output clock data is hexadecimal or BCD code, and BIT1 determines the format of the time: 24 hours or 12 hours. Register C saves the interrupt flag bit. If multiple interrupts are used, the microcontroller can read this register to identify what kind of interrupt has occurred and enter the corresponding processing program. In this design, only the alarm interrupt is used. When the /IRQ pin outputs a low level, it can be determined that an interrupt has occurred when the alarm time has arrived. However, it is still necessary to read this register to clear the interrupt flag to avoid repeated processing of the program. Register D is a register related to whether the device is valid. This circuit does not need to process this register.

Hardware Circuit

The circuit uses a 4-bit common cathode digital tube to display clock, alarm and calendar information. The digital tube uses CD4511 for hardware decoding and 74LS06 for dynamic selection and driving circuit. The circuit diagram is shown in Figure 3. CD4511 is a decoding chip used for digital tube display. A 4-bit binary value is input into the chip input pin (D~A), and the output terminal (a~g) decodes and outputs the value required to be displayed by the common cathode digital tube. For example, if "0101" (decimal "5", D is the most significant bit data) is input into the 4 pins D~A of CD4511, then "1011011" is output from the output terminal a~g. Moreover, CD4511 has a very useful "blanking" function, that is, when the value of the input terminal D~A is greater than 9, the output terminal a~g is in a high impedance state, so that the 7-segment lights on the digital tube will be off.

74LS06 contains 6 NOT gate circuits, and only 4 of them are needed in this article. If "1" is set at the input end, the corresponding output end is "0", and one of the digital tubes is selected. For example, if "1" is input to P1.4 of AT89S52, the 4A pin of 74LS06 is "1", and the output at its corresponding output pin 4Y is "0", thus selecting the DS1 digital tube connected to s1. When soldering the circuit board, the two chips CD4511 and 74LS06 can be placed under the digital tube, so that the entire circuit board will be smaller. Because the digital tube has only 4 digits, and two of them must be used to display one time information, only two time information can be displayed at a time, for example, DS1 and DS2 display the tens and ones of the month respectively, and DS3 and DS4 display the tens and ones of the date respectively. But there are much more time information to be displayed, so the "time-sharing multiplexing" method is used to display the hour and minute, month and day, year and week in turn. In terms of time allocation, the author uses the following scheme: in each minute, the clock hour and minute are displayed in 0~9s, 20~39s, and 50~59s, the month and day are displayed in 10~19s, and the year and week are displayed in 40~49s, while the clock seconds are not displayed. Because the maximum value of the week is 7 (indicating Sunday), it can be displayed only in the ones place, and the tens place allocated for the week can be "blanked". The set alarm information does not need to be checked frequently, so the above-mentioned time-sharing display is not performed, but it is viewed by pressing the KEY4 key. The functions of the 4 buttons in the circuit diagram are assigned as follows: KEY1: value plus 1 key; KEY2: value minus 1 key; KEY3: adjustment item selection. When this key is pressed, different adjustment items can be selected, which are the clock hour, clock minute, month, date, year, week, alarm clock hour and alarm clock minute. KEY4: Select to display time (including hour, minute, month, day, year and week) or alarm. The red LED flashes, which means the digital tube currently displays the alarm hour and minute, and the green LED flashes, which means the clock hour and minute is currently displayed; the red LED flashes and the buzzer sounds, which means the alarm time has arrived and the alarm is sounded; when both LEDs are not flashing, it means the calendar information is displayed, i.e. month, day, year and week. You can distinguish whether the displayed information is month, day or year, week by whether DS3 displays data.

Software Design

The compilation environment used by the author is Keil compilation software, using C51 programming language. The entire program consists of several modules. The file mmi.c includes some functions for human-computer interaction processing, such as reading buttons, displaying time information on digital tubes, and sound processing of LEDs and buzzers; the file ds12887.c includes functions for reading, writing and initializing DS12887; the file my52.c contains delay functions; the file main.c calls the functions in these modules for comprehensive processing. The program flow chart of the main function is shown in Figure 4. Each xxx.h file contains the function declarations and global variable declarations in the corresponding xxx.c files.

Reference address:Using DS12887 to make a clock that can still run without power

Previous article:Using GSM SMS remote control module to make home security alarm
Next article:Let rescue vehicles detect and move metal

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号