//注意事项:CRL寄存器初始值是0,配置之前需要进行清零操作,不然可能点不亮LED。
//置位操作:|=,清0操作:&=~
#include "stm32f10x.h"
void Delay(__IO u32 nCount);
int main(void)
{
//打开 GPIOB 端口的时钟
*(unsigned int * )0x40021018 |= ((1)<<3);
//配置IO(PB5)口为输出
*(unsigned int*)(0x40011800) &= ~((0x0F)<<(4*5));//清零
*(unsigned int * )0x40010C00 |= ((1)<<(4*5));
//打开 GPIOE 端口的时钟
*(unsigned int * )0x40021018 |= ((1)<<6);
//配置IO(PE5)口为输出
*(unsigned int*)(0x40010C00) &= ~((0x0F)<<(4*5));//清零
*(unsigned int * )0x40011800 |= ((1)<<(4*5));
while(1)
{
//控制 ODR 寄存器
*(unsigned int * )0x40010C0C &= ~(1<<5);
Delay(0x0FFFFF);
*(unsigned int * )0x40010C0C |= (1<<5);
Delay(0x0FFFFF);
*(unsigned int * )0x4001180C &= ~(1<<5);
Delay(0x0FFFFF);
*(unsigned int * )0x4001180C |= (1<<5);
Delay(0x0FFFFF);
}
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
void SystemInit(void)
{
//函数体为空,目的是为了骗过编译器不报错
}
STM32F103 使用寄存器点亮LED(两个LED的闪烁+流水灯)
最新推荐文章于 2024-06-19 09:50:26 发布