The STM8S003F3 internal crystal oscillator initialization code is as follows:
CLK_DeInit();
CLK_LSICmd(ENABLE);
CLK_HSICmd(ENABLE);
while(SET != CLK_GetFlagStatus(CLK_FLAG_HSIRDY));
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //HSI = 16M (divide by 1)
Here I use timer4 as an example, the code is as follows:
//Delay 10us (2 division = 8M count 80 pulses)
TIM4_TimeBaseInit(TIM4_PRESCALER_2, 79);
TIM4_ClearFlag(TIM4_FLAG_UPDATE);
Then here, I use timer4 as the delay function, which can be used directly. The implementation code is as follows:
void TIMDelay_N10us(uint16_t Times)
{
TIM4_Cmd(ENABLE); //Start the timer
while(Times--)
{
while(RESET == TIM4_GetFlagStatus(TIM4_FLAG_UPDATE));
TIM4_ClearFlag(TIM4_FLAG_UPDATE);
}
TIM4_Cmd(DISABLE); //Disable the timer
}
void TIMDelay_Nms(uint16_t Times)
{
while(Times--)
{
TIMDelay_N10us(100);
}
}
void TIMDelay_Ns(uint16_t Times)
{
while(Times--)
{
TIMDelay_Nms(1000);
}
}
Previous article:Use of STM8S003F3 PWM
Next article:STM8S003F3 uses timer to calculate square wave period
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
- Is this type of mask = medical surgical mask?
- TCP network communication problem
- EMI noise suppression in harsh environments
- Jump-start your new design with the TI motor control software development kit!
- PlanAhead14.7
- Analog electronics elective test + DC and AC parameters
- Introduction to TI_DSP link command file (*.cmd)
- TI CC1310 sub1G SDK development unique identification number MAC address reading
- FPGA Implementation of ECT Image Reconstruction Algorithm
- Why does the AD21 shortcut key not work after modification?