Purpose: To familiarize yourself with the use of the timer function (automatic reload)
#include"stm8s.h"
#include "stm8s_gpio.h"
#include "stm8s_tim2.h"
void CLK_Configuration();
void TIM2_Configuration_set_1ms(void);
void GPIO_Configuration();
void main()
{
CLK_Configuration();
TIM2_Configuration_set_1ms();
GPIO_Configuration();
enableInterrupts();//使能总中断
while(1)
{
}
}
void CLK_Configuration()
{
CLK_DeInit();
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);//HSI16MHZ,1分频
}
void TIM2_Configuration_set_1ms(void)
{
TIM2_DeInit();
TIM2_TimeBaseInit( TIM2_PRESCALER_16,1000);
TIM2_ITConfig( TIM2_IT_UPDATE , ENABLE);
TIM2_SetCounter(0x0000);
TIM2_Cmd(ENABLE);
}
void GPIO_Configuration()
{
GPIO_DeInit(GPIOD);
GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
}
#pragma vector=13+2
__interrupt void TIM2_IRQ()
{
static unsigned int j;
j++;
if(j==1000)
{
j=0;
GPIO_WriteReverse(GPIOD, GPIO_PIN_0);//1s取一次反
}
TIM2_ClearITPendingBit(TIM2_IT_UPDATE); //清中断标志位
}
Previous article:stm8s development (three) UART usage: serial communication!
Next article:stm8s development (nine) use of EEPROM: use EEPROM to store data!
Recommended ReadingLatest update time:2024-11-15 07:23
- Popular Resources
- Popular amplifiers
- STM8 C language programming (1) - basic program and startup code analysis
- Description of the BLDC back-EMF sampling method based on the STM8 official library
- STM32 MCU project example: Smart watch design based on TouchGFX (8) Associating the underlying driver with the UI
- MC9S12XS MCU Principle and Embedded System Development
- 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)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- LSM6DS3 3D Accelerometer and 3D Gyroscope PCB Package and Code
- Two power modules with the same voltage connected in parallel?
- How to choose the inductor of BOOST boost power supply?
- "Invite you to disassemble" Episode 1 --- Xiaomi 45W charging head disassembly
- The experience of debugging L-band RF power amplifier is in "2019.1.1" for your reference
- 2021 ON Semiconductor Avnet RSL10 Bluetooth SoC Development and Design Competition 4th Post (Bluetooth Current)
- MSP430FR5969 Remote Upgrade
- Circuit help, how do you analyze this circuit?
- EEWORLD University Hall----Live Replay: Microchip Security Series 15 Simplifies Security Application Design with dsPIC33/PIC24 and ATECC608 Devices
- EEWORLD University - Designing Wide Input DC/DC Converters for Thermostat Applications