The interrupt method is rather special and requires the use of the interrupt handling mechanism inside the microcontroller and the specification of the interrupt function.
#include
sbit LED = P0^2;
unsigned int vT = 0;
void main()
{
LED = 0;
TMOD = 0x01;
TH0 = 0x3C; // Initial count value 3CB0H = 15536 (65536-15536=50000 * 1us = 50ms)
TL0 = 0xB0;
ET0 = 1; // When EA, IE^1, is equal to 1, request interrupt timer 0 interrupt to be turned on
EA = 1; // General interrupt is turned on
TR0 = 1; // Start timer 0
while(1);
}
void MyInterrupt(void) interrupt 1 // interrupt service routine
{
vT++;
if (vT == 20) // 20 * 50ms = 1000ms = 1s
{
LED = !LED;
vT = 0;
TH0 = 0x3C; // Restore the initial value of the count
TL0 = 0xB0;
}
}
Previous article:MCU timer working mode 1
Next article:Timing working mode 2 realizes 1s timing
- Popular Resources
- Popular amplifiers
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
- Classic pictures of the past
- Is the intelligent express delivery pickup system based on LabVIEW not too complicated?
- How to implement ship mode in Li-ion battery designs
- Read the good book "The Self-Taught Handbook for Electronic Engineers" - Mastery Edition
- TI E2E Chinese Community celebrates its 8th anniversary, with 8 technical collections for you who love technology!
- What is the function of the DET signal?
- Several issues with the tps65130 chip
- B-U585I-IOT02A Bluetooth problem solved
- Share the November 2018 STMicroelectronics-Shunde Motor Control Roadshow Conference Brochure
- My Journey of MCU Development (V)