Design a simple timer alarm controlled by a single-chip microcomputer. It is required to count down according to the set initial value (1-59 seconds). When the time reaches 0, the digital tube flashes \"00\" (flashing at 1Hz). The key functions are as follows: (1) Set key: In the countdown mode, press this key to stop the countdown and enter the setting state; if it is already in the setting state, this key is invalid. (2) Increase key: In the setting state, each time the increment key is pressed, the initial value increases by 1. (3) Decrement key: In the setting state, each time the decrement key is pressed, the initial value decreases by 1. (4) Confirm key: In the setting state, after pressing this key, the single-chip microcomputer counts down according to the new initial value and displays the countdown number. If it is already in the timing state, this key is invalid. 3.1.2 Module 1: System design (1) Task analysis and overall design ideas According to the requirements of the topic, the following functions need to be implemented. Timing function: To realize the timing function, you need to use a timer to count. By setting the initial value of the timer to control the time interval of the overflow interrupt, a variable is used to record the number of timer overflows to achieve the function of timing in 1 second. Then, when the timing reaches 1 second, the countdown counter is reduced by 1. When the countdown counter reaches 0, another flag variable is triggered to enter the flashing state. Display function: To display the countdown number, the number should be divided into \"tens\" and \"units\" by dynamic scanning. If it is in the flashing state, there is no need for dynamic scanning display. You only need to control the bit control line of the common cathode digital tube to realize the extinguishing and lighting of the digital tube. Switching between keyboard scanning and running mode: After initializing some variables and registers, the main program needs to continuously read the status of the keyboard and dynamically scan the digital tube to display the corresponding numbers. Switching between setting state and timing state is realized according to the key value of the keyboard. (2) MCU model and required peripheral device models, MCU hardware circuit schematic diagram The MCS-51 series AT89S51 MCU is selected as the microcontroller, and two four-way common cathode digital tubes are selected to form an 8-bit display module. Due to the limited driving capability of the AT89S51 MCU, two 74HC244s are used to drive the bus. One 74HC244 completes the control and drive of the bit control line, and the other 74HC244 completes the 7-segment code output of the digital tube. A 100 ohm resistor is connected in series at each output port to limit the current of the 7-segment digital tube. Due to the small number of keyboards, independent keys are selected and connected to the P1 port as four key inputs. When no key is pressed, P1.0-P1.3 is high level, and when a key is pressed, the corresponding pins of P1.0-P1.3 are low level. The circuit schematic diagram is shown in Figure 3-1.
You Might Like
Recommended ContentMore
Open source project More
Popular Components
Searched by Users
Just Take a LookMore
Trending Downloads
Trending ArticlesMore