#include "stm32f10x.h"
static GPIO_InitTypeDef GPIO_InitStructure;
#define PB5OUT(n) *(volatile uint32_t *)(0x42000000+((uint32_t)&GPIOB->ODR-0x40000000)*32+n*4)
void led0(void){
//led0-->PB5
//使能端口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
//初始化GPIO引脚
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;//高速响应
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
}
int main(){
led0();
//例子假如
//系统定时器的时钟源168MHz
//只要系统定时器进行168000000个计数,就代表1秒钟时间的到达
//只要系统定时器进行168000000/10个计数,就代表1/10秒钟时间的到达
//只要系统定时器进行168000000/100个计数,就代表1/100秒钟时间的到达
//所以下面那个句子也可以写成SysTick_Config(168000);
//配置系统定时器触发1000Hz的中断
//周期时间T=1/f=1/1000Hz=1ms
SysTick_Config(SystemCoreClock/1000);
while(1){
}
}
void SysTick_Handler(void){
static uint32_t i=0;
i++;
if(i>500){
i=0;
//灯状态的翻转
PB5OUT(5)^=1;//7异或 1^1=0 0^1=1 反复
}
}
微信扫码关注
更新实时通知