【main.c】
#include <stm32f10x.h>
int main(void)
{
GPIO_InitTypeDef init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
init.GPIO_Pin = GPIO_Pin_All;
init.GPIO_Speed = GPIO_Speed_50MHz;
init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &init);
SysTick_Config(SystemCoreClock / 5); // 设定中断触发周期为五分之一秒,也就是0.2秒
GPIOB->ODR = 0x100;
while (1);
}
【stm32f10x_it.c】
.......................................
.......................................
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
// 这个函数每隔0.2秒执行一次
int nCounter = 0;
void SysTick_Handler(void)
{
nCounter++;
if (nCounter >= 5) // 当这个变量的值等于5时,就刚好是1秒
{
nCounter = 0;
GPIOB->ODR <<= 1;
if (!GPIOB->ODR)
GPIOB->ODR = 0x100;
}
}
.........................................
........................................