1.使用寄存器的方法,配置引脚PA5,PC6分别 为上拉输入、复用开漏。
时间: 2023-05-13 07:05:20 浏览: 58
以下是使用寄存器的方法,配置引脚PA5和PC6分别为上拉输入和复用开漏的代码:
```
// 使能GPIOA和GPIOC的时钟
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOCEN;
// 配置PA5为上拉输入
GPIOA->MODER &= ~(3 << (5 * 2)); // 清零
GPIOA->PUPDR |= 1 << (5 * 2); // 上拉
// 配置PC6为复用开漏
GPIOC->MODER &= ~(3 << (6 * 2)); // 清零
GPIOC->MODER |= 2 << (6 * 2); // 复用
GPIOC->OTYPER |= 1 << 6; // 开漏
```
希望这个代码对你有所帮助!
相关问题
3.使用寄存器的方法,配置引脚PA1,PC2位流 水偶数引脚,共阳接法,延时函数直接使用De lay(intms),延时时间300ms。
以下是使用寄存器的方法,配置引脚PA1,PC2位流水偶数引脚,共阳接法,延时函数直接使用Delay(int ms),延时时间300ms的代码:
```
#include <stm32f10x.h>
void Delay(int ms) {
while (ms--) {
for (int i = 0; i < 7200; i++);
}
}
int main() {
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN; // enable GPIOA and GPIOC clock
GPIOA->CRL &= ~(GPIO_CRL_MODE1 | GPIO_CRL_CNF1); // clear PA1 mode and configuration
GPIOA->CRL |= GPIO_CRL_MODE1_0; // set PA1 output mode
GPIOC->CRL &= ~(GPIO_CRL_MODE2 | GPIO_CRL_CNF2); // clear PC2 mode and configuration
GPIOC->CRL |= GPIO_CRL_MODE2_0; // set PC2 output mode
while (1) {
GPIOA->ODR |= GPIO_ODR_ODR1; // set PA1 high
GPIOC->ODR &= ~GPIO_ODR_ODR2; // set PC2 low
Delay(300); // delay 300ms
GPIOA->ODR &= ~GPIO_ODR_ODR1; // set PA1 low
GPIOC->ODR |= GPIO_ODR_ODR2; // set PC2 high
Delay(300); // delay 300ms
}
}
```
希望能对您有所帮助!
使用寄存器的方法,配置引脚PA1,PC2位流水灯引脚,共阳接法,延时函数直接使用Delay(int ms ),延时时间300ms
以下是使用寄存器的方法,配置引脚PA1,PC2位流水灯引脚,共阳接法,延时函数直接使用Delay(int ms ),延时时间300ms的代码:
```
#include <stm32f10x.h>
void Delay(int ms);
int main(void)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN; // Enable GPIOA and GPIOC clock
GPIOA->CRL &= ~(GPIO_CRL_MODE1 | GPIO_CRL_CNF1); // Configure PA1 as output push-pull
GPIOA->CRL |= GPIO_CRL_MODE1_0;
GPIOC->CRL &= ~(GPIO_CRL_MODE2 | GPIO_CRL_CNF2); // Configure PC2 as output push-pull
GPIOC->CRL |= GPIO_CRL_MODE2_0;
while (1)
{
GPIOA->BSRR = GPIO_BSRR_BS1; // Turn on PA1
Delay(300);
GPIOA->BSRR = GPIO_BSRR_BR1; // Turn off PA1
GPIOC->BSRR = GPIO_BSRR_BS2; // Turn on PC2
Delay(300);
GPIOC->BSRR = GPIO_BSRR_BR2; // Turn off PC2
}
}
void Delay(int ms)
{
for (int i = 0; i < ms * 1000; i++);
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)