This article mainly summarizes the meaning of each statement when developing library functions of STM8.
(1) TIM1 initialization configuration function
The main function of the function is to set the parameters and working mode of the counter and enable it;
void Tim1_Init(void)
{
TIM1_TimeBaseInit(16,TIM1_COUNTERMODE_UP,1000,0);
//(Timer frequency: 16-division is 1/16 of the system frequency, which is 1M, counting up, timer overflow value, reload count starts from 0)
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE); //Interrupt configuration and enable function
TIM1_ARRPreloadConfig(ENABLE); //Enable the automatic reload function
TIM1_Cmd(ENABLE); //Start timer
}
About the calculation of timer overflow value: timer overflow value = scheduled timing time (us) * timer frequency
(2) TIM1 interrupt vector function
The main function of the function: call the interrupt execution function and clear the counter flag;
//Interrupt vector function
#pragma vector=0xD
__interrupt void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)
{
Tim1_Execut(); //Call interrupt execution function
TIM1_ClearITPendingBit(TIM1_IT_UPDATE); //Clear update counter flag
}
(3) Interrupt execution function
The main function of the function is to perform timing according to your needs and call related function execution;
Note that the count variable must be declared as a static type, which is related to the life cycle of the count variable;
static u16 i=0;
void Tim1_Execute(void)
{
i++;
if(i==1000)
{
i=0;
Led_Revese(); //Function
}
}
(4) Note that the general interrupt must be enabled in the main function
__enable_interrupt();
Previous article:stm8s timer output compare mode
Next article:STM8S105 TIM1 TIM2 timer timing initialization
- Popular Resources
- Popular amplifiers
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- XMC4800 Review (Part 3) -- USB Multiplexing Device CDC+HID
- After the web page is controlled, the repl connection will be disconnected.
- Based on fpga controllable divider.doc
- 2G---5G and future antenna technology
- Pingtou Ge RVB2601 Review: Web Player
- The 2019 Intel FPGA Technology Conference in Beijing invites you to attend!
- About posting and replying prestige
- [Domestic RISC-V Linux board Fang·Starlight VisionFive trial report] C language programming to control WS2812B colorful lamp beads
- The AD voltage check has been completed, how to connect it to the LED
- Mechanical and electrical system testing and control from entry to mastery