STM32F103C8T6点亮第一个LED和程序讲解

  1. boot0=1, boot1=1
  2. 函数如下
int main(void)
{
  RCC->APB2ENR |= 0x00000010;  // I/O port C clock enabled
  GPIOC->CRH   &= 0xFF0FFFFF;  // set general purpose output mode for LEDs
  GPIOC->CRH   |= 0x00100000;  // PC13 pull-push, 
  //GPIOC->BSRR   = 0x20000000;  // LEDs on
  //GPIOC->BSRR   = 0x00002000;  // LEDs off
	
	while(1) {
		GPIOC->BSRR = 0x20000000;  //set high level 
		DelayMicroSeconds(2000000); //On LED, delay 2seconds
		
		GPIOC->BSRR = 0x00002000; // set low level
		DelayMicroSeconds(2000000); //off LED, 2seconds
		
	}
}
  1. 按reset就可以看到LED1闪烁了。

程序讲解:
RCC->APB2ENR

RCC->APB2ENR |= 0x00000010;  // I/O port C clock enabled

在这里插入图片描述

GPIOx->CRH
在这里插入图片描述

// SDA on port B, bit 14
#define SDA_LOW()  (GPIOB->BSRR = 0x40000000) // set SDA to low
#define SDA_OPEN() (GPIOB->BSRR = 0x00004000) // set SDA to open-drain
#define SDA_READ   (GPIOB->IDR  & 0x4000)     // read SDA


// SCL on port B, bit 13              /* -- adapt the defines for your uC -- */
#define SCL_LOW()  (GPIOB->BSRR = 0x20000000) // set SCL to low
#define SCL_OPEN() (GPIOB->BSRR = 0x00002000) // set SCL to open-drain
#define SCL_READ   (GPIOB->IDR  & 0x2000)     // read SCL

在这里插入图片描述

GPIOx->BSRR

GPIOC->BSRR   = 0x20000000;  // LEDs on

在这里插入图片描述

  RCC->APB2ENR |= 0x00000008;  // I/O port B clock enabled

  GPIOB->CRH   &= 0x0FF0FFFF;  // set push-pull output for Vdd & GND pins
  GPIOB->CRH   |= 0x10010000;  // set mode for PB12/PB15 

  GPIOB->BSRR = 0x10008000;     //set Vdd to High, set GND to Low- GND PB12, VDD PB15, BS-high, BR-low
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值