Design of electronic timer board based on single chip microcomputer

Publisher:760802csyLatest update time:2012-01-17 Keywords:P87LPC762 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0 Introduction

With the rapid development of electronic information technology, electronic timekeeping boards have become a symbolic function of the development of electronic equipment. As the name implies, timekeeping boards are mainly used to complete the timing function, that is, to display the time of the real-time clock, which is the primary task of timekeeping boards. However, modern electronic timekeeping boards can also integrate multiple functions in one. It can not only display the current specific time in real time, but also display the year, month, day, and week. In addition, there are many special timekeeping boards, which can design safe production days, countdown days, working environment temperature, perpetual calendar, etc., which greatly expands the application scope of timekeeping boards.

1 System Design Principles

This design uses Philips' P87LPC762 as the microprocessor, the temperature sensor chip uses LM70, and the clock chip uses DS1302 chip. They all use serial communication with the single-chip microcomputer. The hardware schematic diagram of the electronic timekeeping card system is shown in Figure 1. In the figure, the serial output display of the data is divided into three parts, namely: safe days and temperature, year, month, day and week, and clock data. The system first reads the binary temperature data measured by the temperature sensor chip LM70 through the single-chip microcomputer, and then processes and calculates to obtain the corresponding BCD temperature data, and finally sends it to the digital tube display together with the safe days data through the serial port extended by the single-chip microcomputer. At the same time, the calendar clock data is read in through the communication between the single-chip microcomputer and the clock chip DS1302, and then the obtained year, month, day and week data are output to the digital tube display through another serial port extended by the single-chip microcomputer, and the clock data is sent to the display through the serial port output of the single-chip microcomputer itself. The setting and modification of data can be completed through three buttons connected to the single-chip microcomputer. The display part uses a 74HC164N serial input parallel output shift register to drive the digital tube. The second signal and weather signal are displayed by light-emitting diodes. In summary, the serial communication method used in this design can effectively save the space of hardware circuit design, making the design simpler and more practical.

2 Temperature detection

To complete the detection and display of ambient temperature, a temperature sensor is first used. This design uses the LM70 temperature sensor chip. Since LM70 uses serial communication, only three wires are needed to connect to the microcontroller to complete data reading and writing.

The function of the temperature sensor chip is to measure the external temperature value. It first sends the analog temperature sensed from the outside through the thermistor to the internal A/D converter, converts it into the corresponding digital temperature value (that is, binary temperature data) and stores it in the temperature register. The temperature measured by the temperature sensor LM70 can be finally converted into the corresponding analog data by reading the data of its temperature register, that is, converting the binary data into BCD code data and storing it in the single-chip computer.

It should be noted here that if the ambient temperature is below zero (i.e. negative temperature), then compared with the positive temperature of the corresponding temperature value, the converted temperature register data D5 to D15 is the complement of the positive temperature. Therefore, after reading the temperature register data, it is necessary to determine the sign bit of the data. If it is negative temperature data, the complement must be calculated first to finally convert it into the corresponding correct temperature value.

3 Reading calendar clock data

3.1 Write program analysis

First, let's analyze the writing program to DS1302. The initial time set in this design is 1:0:00 on Saturday, January 1, 2005, that is, the clock chip starts to run from this time after power is turned on. Then, to complete the clock initialization, the initial time should be written into the DS1302 chip. Figure 2 shows the data flow chart of writing the clock.

From the flowchart shown in Figure 2, it can be seen that if you want to write clock data into the clock chip, you must first write the address of the corresponding data. After writing a byte address, you can write a byte of corresponding data, and so on. The specific steps are to first write the clock multi-byte control register, and its command word format is as follows:

When writing to the clock chip 08EH, the command word 00H that allows the write operation must also be written. After writing these two command words, you can start writing the address of each byte of clock data and the corresponding clock data. It should be noted here that the address for writing second data is 80H, the address for minute data is 82H, the address for hour data is 84H, and so on. In other words, after writing the address of each byte of data, its address should be increased by 2 accordingly to prepare for writing the next byte address. The entire program can realize the writing of seven bytes of data, that is, writing the address once and writing the data once, until the loop count value is 0, and the writing of the clock data is completed.

When writing one byte of data, you must first set the loop count value (here set to 8), and a total of 8 bits of data must be input serially. Before each data is shifted in, the data should be shifted one bit to C, and then the following instructions are executed:

The purpose of these instructions is to input a falling edge of the clock to the serial clock port. Only after the falling edge can a bit of data be written into the clock chip. In this way, after 8 cycles, a byte of data is written into the clock chip. After the entire initial clock data is written, the DS1302 can automatically run and keep time.

3.2 Reading Program Analysis

The principle of reading a byte subroutine is the same as that of writing a byte subroutine. First, the loop count value can be set to 8 to prepare for reading an 8-bit byte of data. Then, a clock data is read from the P0.2 port to C at the falling edge of the serial clock to perform a right shift of the accumulator with carry. In this way, after 8 cycles, the reading of a byte of clock data is completed. The result is stored in the accumulator ACC. The specific program for reading a byte of data is as follows:

3.3 Calculation of safe production days

One of the functions of this system is to display the current number of days of safe production. To obtain the value of the number of days of safe production, the starting date of the number of days of safe production should be set in the memory unit of the single-chip microcomputer first, and a reference time should be set at the same time, so that the number of days from the set starting date of the number of days of safe production to this reference time can be calculated, that is, the cumulative number of days from the starting point. Then, every time the calendar clock data of the clock chip is read, the system will calculate the number of days from the current date to the reference time, that is, the cumulative number of days of the current date, and the difference between the two cumulative days is the number of days of safe production to be displayed.

4. Design of real-time monitoring system

The main program of this system is used to complete data initialization and T0 timer setting, and other tasks are put into the timing interrupt program for execution. Figure 3 shows the interrupt service program flow chart. The interrupt service program must first determine whether a key is pressed, that is, whether it has entered the data setting state? If it is not in the setting state, it is necessary to read the data to be displayed from the clock chip, and send the data of each display buffer to the digital tube for display. If it is in the setting state, it is set to refresh the display data every 0.25 s.

If it is in the setting state, it means that a key is pressed, so the corresponding key must be read. In this design, if the key is in the setting state and no corresponding data adjustment operation is performed, the set data is saved and the setting state is exited. When reading a key, first read out its key code and save it. Then determine whether the key code is stable. If it is not stable, it means that the key has responded, and no data adjustment is performed. If the key code is stable, then determine whether it is an adjustment key. If it is an adjustment key, adjust the modification pointer, that is, each time the adjustment key is pressed, the modification pointer increases by one, and the next data is modified. The modification pointer generally ranges from thousands, hundreds, tens, and numbers of safe days to years, months, days, weeks, and then hours and minutes. If the key pressed at the beginning is not an adjustment key, the setting state will not be entered. If a signal of a key being pressed is read again when the adjustment key has responded, then when it is not an adjustment key, the data modification state is entered to adjust the corresponding data. Note: In the setting state, the clock is cleared for each operation to exit with timing. After adjusting the corresponding data, the data can be saved and displayed.

5 Data Display

This design uses 16 8-bit serial input/parallel output 74HC164N and digital tubes for serial shift display. The digital tubes used are 8-segment digital tubes with common anode. Since the data is displayed in three groups of outputs, the 74HC164N clock lines of the safe production days and temperature display parts are connected together to P0.5 of the microcontroller, and the 74HC164N clock lines of the year, month, day and week display parts are connected together to P0.7 of the microcontroller. In addition, the 74HC164N clock lines of the clock display part are connected together to P1.0 of the microcontroller.

6 Conclusion

This design underwent many experiments during the completion process, especially in the reading of temperature, and received guidance from many teachers, whom I would like to thank here.

Keywords:P87LPC762 Reference address:Design of electronic timer board based on single chip microcomputer

Previous article:Improve the performance of traditional PFC controller using simple circuit
Next article:Digital Elevator System Based on C167CS Microcontroller

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号