我是微 Controller 和嵌入式世界的新手,所以我开始尝试使用基础寄存器在 stm32 中编写一个闪烁程序,最后,我让它闪烁,但后来我发现每当引脚 pc13高电平时,内置LED灯关闭,但当pc13低电平时,内置LED灯亮起(完全相反!),我不知道为什么我什至添加了一个外部LED来检查我是否正确,我是对的(怀疑它是否正常工作) )每当内置关闭时,外部 LED 就会打开,反之亦然,请帮忙??? 我的代码是:(我的板是STM32F103C8 64KB FLASH,STM32_SMART BOARD)
#include "stm32f10x.h" // Device header
void delay(int rep);
int main(void)
{
RCC->APB2ENR |= 0x10; /// Or 0b10000 --> Anabling Preiph GPIOC
GPIOC->CRH &= 0xFF0FFFFF; /// Reset the PORT C PIN 13
GPIOC->CRH |= 0x00300000; /// Set Port C PIN 13 as Output
GPIOC->ODR |= 0x2000; /// Set Port C Pin 13
while(1)
{
/// Blinking the Port C pin 13
GPIOC->ODR |= 0x2000;
delay(10000000);
GPIOC->ODR &= ~0x2000;
delay(10000000);
}
}
/// Random time delay Function
void delay(volatile int a) {
//Added volatile in a and in i
for (volatile int i = 0; i < a; i++);
}
最佳答案
关于c - 当 GPIOC13 为高电平时,内置 LED 熄灭,但当 GPIOC13 为低电平时,内置 LED 亮起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65539472/