我在尝试运行此代码以使蓝色药丸板(STM32F103C8,ARM Cortex M3)上的内置 LED(位于 PC13)闪烁时遇到问题:
#include "stm32f10x.h" // Device header
#define max 1000000
int main(void){
RCC->APB2ENR |= 1<<4;
GPIOC->CRH &= 0xFF0FFFF;//clear the necessary bit
GPIOC->CRH |= 0x00300000;//set the necessary bit
GPIOC->ODR &= ~(1<<13);//turn PC_13 ON
while(1){
GPIOC->ODR |= 1<<13;//off
for(unsigned int i = 0;i < max;++i);
GPIOA->ODR &= ~(1<<13);//on
for(unsigned int i = 0;i < max;++i);
}
}
有人可以帮助我吗?此外,当我在 while 循环中声明无符号整数“i”时一切正常,但即使没有任何反应,LED 仍然不会闪烁。这是修改后的代码:
#include "stm32f10x.h" // Device header
#define max 1000000
int main(void){
RCC->APB2ENR |= 1<<4;
GPIOC->CRH &= 0xFF0FFFF;//clear the necessary bit
GPIOC->CRH |= 0x00300000;//set the necessary bit
GPIOC->ODR &= ~(1<<13);//turn PC_13 ON
while(1){
unsigned int i;
GPIOC->ODR |= 1<<13;//off
for(i = 0;i < max;++i);
GPIOA->ODR &= ~(1<<13);//on
for(i = 0;i < max;++i);
}
}
. 此外,我尝试了另一个技巧,在循环外声明整数“i”,如下所示:
#include "stm32f10x.h" // Device header
#define max 1000000
int main(void){
RCC->APB2ENR |= 1<<4;
GPIOC->CRH &= 0xFF0FFFF;//clear the necessary bit
GPIOC->CRH |= 0x00300000;//set the necessary bit
GPIOC->ODR &= ~(1<<13);//turn PC_13 ON
unsigned int i;
while(1){
GPIOC->ODR |= 1<<13;//off
for(i = 0;i < max;++i);
GPIOA->ODR &= ~(1<<13);//on
for(i = 0;i < max;++i);
}
}