#define LED PC_ODR_ODR1
void GPIO_INIT() // PC1 push-pull output
{
PC_DDR_DDR1=1;
PC_CR1_C11=1;
LED=1; // Turn off LED first
}
void TIM2_INIT()
{
TIM2_PSCR_PSC=11; // Counter clock F_CLK=F_CPU/2 to the PSC power, here is 2 to the 11th power
TIM2_ARRH=0X03; // Automatically reload the high 8 bits
TIM2_ARRL=0XE8; // Automatically reload the low 8 bits TIM2_ARR=0X03E8=1000, that is, counting 1000 times to generate an interrupt
TIM2_IER_UIE=1; // Allow interrupt updates
TIM2_CR1_CEN=1; // Enable counter
}
#pragma vector=TIM2_OVR_UIF_vector // Once the timer count overflows, an interrupt is triggered
__interrupt void TIM2_OVR_UIF()
{
LED=~LED; //When the interrupt is triggered, the LED value is inverted
TIM2_SR1_UIF=0; //Update the interrupt flag
}
void main()
{
asm("sim"); //Turn off global interrupt
GPIO_INIT();
TIM2_INIT();
asm("rim"); //Turn on global interrupt
while(1);
}
Previous article:The eighth program of STM8S208R8 --- timer interrupt and long key press
Next article:The sixth program of STM8S208R8 --- interrupt and navigation key
- Popular Resources
- Popular amplifiers
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
- The STM32F103VBT6 resets with a button. After releasing the button, it takes three or four seconds for the microcontroller to execute the program.
- [Xianji HPM6750 Review] + Unboxing
- C2000 combines capacitive touch and host controller functions
- 7660 chip common mode inductor manufacturer
- "【TGF4042 Signal Generator】" High-frequency distortion measurement
- Video chip recommendation
- About MSP430 watchdog settings
- Compilation warnings
- Detailed explanation of FPGA - the driving engine of the artificial intelligence era
- Qorvo Online Design Conference - Ultra-Wideband Technology: Use Cases and Benefits