STM32F103 使用寄存器点亮LED(两个LED的闪烁+流水灯)

//注意事项: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)
{
        //函数体为空,目的是为了骗过编译器不报错
}
  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tony带水!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值