The adjustable countdown reminder has the advantages of simple circuit, eye-catching display, accurate timing, easy production, adjustable countdown from 0 to 99 minutes, and convenient use. It is both interesting to produce and practical to use.
1. Hardware Circuit
As shown in Figure 1, the power transformer T1 converts the AC220V mains power into an AC9V AC voltage, which is then rectified by D1~D4, filtered by C4, and stabilized by U2MC7805 (or LM7805) to obtain a 5V DC voltage to power the entire machine.
The main control chip is the PIC16F627 microcontroller, and the source current or sink current of each port can reach 25mA. It can directly drive the LED digital tube without adding an external transistor.
Assume that the RB port of PIC16F627 is output, among which RB0~RB6 is used for the segment drive of the digital tube. Because the LG5621BH common anode digital tube is selected, the digital tube can only be lit when RBO~RB6 outputs a low level. The RB7 port is used to control the buzzer, and the transistor Q3 (S8050) is used for driving and amplifying. The buzzer can only sound an alarm when RB7 outputs a high level. Assume that RA0~RA2 is output port, among which RA0 and RAI are used for the bit drive of the digital tube, and the output is enabled by a low level; RA2 is used for the decimal point drive of the digital tube, and is enabled by a low level. It is used as a timer working indicator. When the timer is working, the decimal point of the digital tube flashes at a frequency of 2s. Assume that RA5, RA4, and RA3 are input ports, and RR4, RR5, and R6 are pull-up resistors of RA5, RA4, and RA3 ports. Key switches S1~S3 are connected to RA5, RA4, and RA3 ports. S1 is the start/alarm release key; S2 is the tens digit preset adjustment key. Press this key once to reduce the tens digit of the timer by 1. When it reaches 0, press this key again and the value returns to 9. This cycle is repeated; S3 is the ones digit preset adjustment key of the timer. The adjustment method is the same as S2. So far, all ports of the PIC16F627 microcontroller have been used.
Timer function: When the timer is initially powered on, the two-digit digital tube displays 99 and is in standby mode. At this time, if you press the ones-digit timer preset key S3, the ones-digit digital tube display value decreases by 1, and if you press S2, the tens-digit digital tube display value decreases by 1.
S1 is the start/alarm release button. Press S1, the timer enters the working state, and the countdown begins (the timing time is minutes). The timing duration starts from the current display value of the digital tube. During the countdown, the decimal point dp of the digital tube flashes at a frequency of 2s, and the unit digit display value decreases by 1 every minute; every 10 minutes, the tens digit display value decreases by 1. When the digital tube display value decreases to 00, the buzzer starts to alarm after another 60 seconds. During the alarm period, the digital tube always displays 00 until the S1 button is pressed again, the buzzer will stop the alarm, and the digital tube will display the last preset timing time.
During the countdown period, buttons S1 to S3 are shielded and cannot be enabled.
2. Programming
1. Program Flow The main program flow is shown in Figure 2 (omitted). The 1-minute timing subroutine flow is shown in Figure 3 (omitted). The digital tube display subroutine flow is shown in Figure 4 (omitted).
2. Key points of program design
(1) This timer uses the PIC16F627 timer module TM10 to create a 50ms timer interrupt, and then uses the register decrement and zero judgment statement "DECFSZ F" to determine whether the display has reached 1 minute. If it has not reached 1 minute, continue to display the current digital value. When 1 minute is reached, the current digital value is reduced by 1 and then displayed for 1 minute. In this way, the display value of the digital tube's ones digit is reduced by 1 every 1 minute, and the display value of the digital tube's tens digit is reduced by 1 every 10 minutes, until the display value of the two-digit digital tube is reduced to 00.
(2) How to distinguish the timer In program design, a register flag is used to distinguish between the preset display program and the timer working display program. If the flag is 0, the preset display program is executed; if it is 1, the timer working program is executed.
(3) Key anti-shake problem. Mechanical keys are connected and disconnected many times when they are pressed and released. This program uses software to solve the key anti-shake problem. The specific method is to add a delay program during the process of pressing and releasing the key. Generally, the delay time is about 10ms.
(4) Weekly display table lookup program, using table lookup method to display the digital value of the digital tube can make the software and hardware design more concise and easy to understand. However, in this timer design, the decimal point of the digital tube is used as a "working indicator light", and because the digital tube is lit by "dynamic scanning", this table lookup code is not the same as the other table lookup code, that is, the table lookup code has changed. The code table of the table lookup program used for the common anode digital in this project is on the right.
If the code table values are written upside down, that is, RETLW 0X40 is written at the front and RETLW 0X10 is written at the end, then this timer becomes a "positive" timer.
3. Notes on Programming
When burning the program, be sure to pay attention to the "configuration bit" setting of the programmer, otherwise it may cause problems such as the program not running normally.
Previous article:Design of AC contactor energy saver based on PIC12F508
Next article:PIC Programming Based on PICC Compilation Environment
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
- GD32 pin PWM output stops level issue
- What's wrong with this circuit?
- Are audio amplifiers, Class A, Class B, Class C, Class AB, Class D, OTL, etc. circuits a type of DAC amplification? And...
- [N32L43x Review] 8. Flash read\write\erase - using internal Flash to store data
- EMC Design of RS-485 Port
- Several issues with op amp circuits
- A simple method to solve the problem of "The Film is too small for this PCB" in AD gerber
- Infineon MERUS Class D Audio Solution | [Read to win gifts, place an order to get a development board]
- 【AT-START-F403A Review】+ Display driver for color OLED screen
- [DWIN Serial Port Screen] Data Storage of Nucleic Acid Sampling and Registration System