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.
Previous article:Using GSM SMS remote control module to make home security alarm
Next article:Let rescue vehicles detect and move metal
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- N32WB452 asked: Does N32WB452 have a basically complete ported RT-Thread development kit?
- IoT Gateways – A Simple Guide to the Internet of Things
- [Bluesun AB32VG1 RISC-V evaluation board] IDE installation and use
- It's New Year's Eve soon. I wish you all a happy New Year.
- Using Ginkgo USB-ADC and heart rate sensor to implement a heart rate tester with Android APP source code
- 【DIY Creative LED】Add touch button and install it on LED lamp
- [RISC-V MCU CH32V103 Review] - 2: Making an LED flash is not easy
- SensorTile.box uses air pressure sensors to analyze environmental changes
- When using an oscilloscope probe to measure the AC waveform between the two ends of a component, how should the probe ground wire be connected?
- 【ST NUCLEO-H743ZI Review】(2)Ethernet Test