Often these problems are caused by too much delay added to the entire process. The delay program is a relatively straightforward program, but it also destroys the overall performance of the microcontroller because the delay microcontroller is running at full speed.
What comes to my mind now is the process I wrote before: initialization->display->button->other functions->end.
1. For example, the naked eye cannot distinguish above 50HZ, so the average display time for each display is 5ms when using 4 digital tubes for dynamic display. According to the previous view, it is written like this: the first digital tube lights up -> delay for a few milliseconds, turn off the first one, light up the second one ->... -> delay, turn off the last one, light up the first one. If 8 digital tubes are used for dynamic display, wouldn't there be a delay of 8 * a few milliseconds?
2. There is another button, and the button needs to have a jitter removal function, usually with software delay of about 20ms. If you add the tens of milliseconds of display, the delay is quite terrifying.
3. Other functions also have delays, especially drivers. For example, the MAX7279 read operation requires a certain delay, but this delay is at the us level, which can be ignored compared to the ms level.
The author suggests that when writing a program, especially a delay program, you should consider how long your delay will be. If it is at the ms level, consider using a timer interrupt to handle it.
For example, in the display program, if 8 digital tubes are displayed dynamically, then you have to consider that the 8 digital tubes are refreshed once every 20ms, which means that the display time of each digital tube is 2.5ms.
Then the procedure is as follows:
volatile unsigned char time_2500_flag; //2.5ms flag
void TimerA(void) //Timer initialization
{
// Initialization, configure to interrupt once every 500us
}
#pragma interrupt_handler TimerA_ISR:NUM
void Timer1_ISR(void) //Interrupt service routine
{
static unsigned char cnt = 0;
//reload reassignment
if (++cnt > 5)
{
cnt = 0;
time_2500_flag = 1;
}
}
void Display(void)
{
;
}
void main(void)
{
//initialization
for (;;)
{
if (time_2500_flag == 1)
{
time_2500_flag = 0;
Display();
}
}
}
The program is written here.
The display program needs special processing here. Execute the display program once and the digital tubes will light up one by one.
Previous article:MSP430G2553 test program (serial port program, USCI mode)
Next article:MCU 4-button menu
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Principles of Circuits (Second Edition)
- CircuitPython 6.3.0 released
- Methods to increase the transmission distance of wireless modules
- [Evaluation of Anxinke Bluetooth Development Board PB-02-Kit] KEY and LED Control
- Award-winning live broadcast | Azure Sphere helps to provide stable, secure and flexible IoT solutions
- EEWORLD University Hall----Keithley 4200A-SCS parameter analyzer accelerates semiconductor equipment, materials and process development
- The upcoming Adafruit Feather STM32F405 Express
- Transfer a PCB experience collection to see
- How to use the Power Path Selector function of BQ24170 with BQ3050?
- The new version of Unico software for STEVAL-MKI109V3 already supports the LIS25BA bone vibration sensor