将引脚改为PC6,7,8,9
时间: 2023-12-15 13:05:02 浏览: 21
好的,下面是将引脚改为 PC6、7、8、9 的代码:
```c
#include "stm32f10x.h"
int main(void) {
// 使能 GPIOC 时钟
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
// 配置 PC6、PC7、PC8、PC9 为推挽输出模式,最大输出速率为 50MHz
GPIOC->CRL &= ~(GPIO_CRL_MODE6 | GPIO_CRL_MODE7);
GPIOC->CRL |= (GPIO_CRL_MODE6_0 | GPIO_CRL_MODE7_0);
GPIOC->CRH &= ~(GPIO_CRH_MODE8 | GPIO_CRH_MODE9);
GPIOC->CRH |= (GPIO_CRH_MODE8_0 | GPIO_CRH_MODE9_0);
while (1) {
// 依次点亮 PC6、PC7、PC8、PC9
GPIOC->BSRR = GPIO_BSRR_BS6;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR6;
GPIOC->BSRR = GPIO_BSRR_BS7;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR7;
GPIOC->BSRR = GPIO_BSRR_BS8;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR8;
GPIOC->BSRR = GPIO_BSRR_BS9;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR9;
// 依次点亮 PC9、PC8、PC7、PC6
GPIOC->BSRR = GPIO_BSRR_BS9;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR9;
GPIOC->BSRR = GPIO_BSRR_BS8;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR8;
GPIOC->BSRR = GPIO_BSRR_BS7;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR7;
GPIOC->BSRR = GPIO_BSRR_BS6;
for (int i = 0; i < 1000000; i++);
GPIOC->BSRR = GPIO_BSRR_BR6;
}
}
```
这个代码可以让 PC6、PC7、PC8、PC9 这四个引脚的 LED 做跑马灯效果,每个灯亮 1 秒钟。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)