简体   繁体   English

STM32F103蓝色药丸-与闪烁的led裸机有关的问题

[英]STM32F103 blue pill - problems related to blinking led bare metal

I come across a problem when trying to run this code in order to blink the built-in LED (located at PC13) on the blue pill board (STM32F103C8, ARM Cortex M3):我在尝试运行此代码以使蓝色药丸板上的内置 LED(位于 PC13)闪烁时遇到问题(STM32F103C8、ARM Cortex M3):

#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);
    }
}

. . Here I receive some errors and I don't know why:在这里我收到一些错误,我不知道为什么: 在此处输入图像描述

Could anybody help me?有人可以帮助我吗? Also, when I declare the unsigned integer "i" within the while loop all goes fine, but even though, nothing happens, the LED still does not blink.此外,当我在 while 循环中声明未签名的 integer “i”时一切正常,但即使没有任何反应,LED 仍然不闪烁。 Here is the modified code:这是修改后的代码:

#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);
    }
}

. . Moreover, I tried another trick, to declare the integer "i" outside the loop, like here:此外,我尝试了另一个技巧,在循环外声明 integer "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);
    }
}

. . Then, I've received the next error message:然后,我收到了下一条错误消息: 在此处输入图像描述 . . Now, the question is why?现在,问题是为什么? Please help me.请帮我。

In the uVision project configuration dialog C/C++ tab, select "use C99".在 uVision 项目配置对话框 C/C++ 选项卡中,select“使用 C99”。

ISO C90 dies not allow declaration of variables in either a for statement or following non -declaritive code in a statement block. ISO C90 不允许在for语句或语句块中的非声明性代码中声明变量。

Alternatively move the declaration to the top of the statement block in which it is required.或者将声明移动到需要它的语句块的顶部。 Better to use C99 though - it has been around long enough to be regarded as lowest common denominator standard I think!不过最好使用 C99 - 我认为它已经存在了足够长的时间,可以被视为最低公分母标准!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM