我是微控制器和嵌入式世界的新手,所以我开始尝试使用基本寄存器在 stm32 中编写闪烁程序,最后,我让它闪烁,但后来我发现每当引脚 pc13 为高时内置 LED 关闭但在 pc13 低电平时打开(完全反转!),我不知道为什么我什至添加了一个外部 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++);
}