野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 361|回复: 3

STM32 第12课用GPIO点亮流水灯 有无大佬指点为何报错

[复制链接]
发表于 2024-2-3 12:05:20 | 显示全部楼层 |阅读模式
请大佬指点为何报错




这是main函数
#include  "stm32f10x.h"
#include   "bsp_led.h"
void delay_us(int delay_us);
void delay_ms(int delay_ms);


void delay_us(int delay_us)
{
    volatile unsigned int num;
    volatile unsigned int t;

    for (num = 0; num < delay_us; num++)
    {
        t = 11;
        while (t != 0)
        {
            t--;
        }
    }
}

void delay_ms(int delay_ms)
{   
  volatile unsigned int num;
  for (num = 0; num < delay_ms; num++)
  {
    delay_us(1000);
  }
}



int main(void)
{
        LED_CLK_SET();
        while(1)
        {       
                LED_G_GPIO_Congif();               
                LED_G(ON);
                delay_ms(100);
                LED_G(OFF);
               
                LED_R_GPIO_Congif();
                LED_R(ON);
                delay_ms(100);
                LED_R(OFF);
               
                LED_B_GPIO_Congif();               
                LED_B(ON);
                delay_ms(100);
                LED_B(OFF);
        }

}

这是bsp_led.c
#include "bsp_led.h"

GPIO_InitTypeDef  GPIO_InitStruct;


void LED_G_GPIO_Congif(void)
{
        GPIO_InitStruct.GPIO_Pin= LED_G_GPIO_PIN;
        GPIO_InitStruct.GPIO_Mode= GPIO_Mode_Out_PP;
        GPIO_InitStruct.GPIO_Speed= GPIO_Speed_50MHz;
        GPIO_Init(LED_G_GPIO_PORT, &GPIO_InitStruct);
}
void LED_R_GPIO_Congif(void)
{
       
        GPIO_InitStruct.GPIO_Pin= LED_R_GPIO_PIN;
        GPIO_InitStruct.GPIO_Mode= GPIO_Mode_Out_PP;
        GPIO_InitStruct.GPIO_Speed= GPIO_Speed_50MHz;
        GPIO_Init(LED_G_GPIO_PORT, &GPIO_InitStruct);
}

void LED_B_GPIO_Congif(void)
{
        GPIO_InitStruct.GPIO_Pin= LED_B_GPIO_PIN;
        GPIO_InitStruct.GPIO_Mode= GPIO_Mode_Out_PP;
        GPIO_InitStruct.GPIO_Speed= GPIO_Speed_50MHz;
        GPIO_Init(LED_G_GPIO_PORT, &GPIO_InitStruct);
}

void LED_CLK_SET(void)
{
        RCC_APB2PeriphClockCmd(LED_GPIO_CLK, ENABLE);
}

这是bsp_led.h
#ifndef __BSP_LED_H
#define __BSP_LED_H

#include "stm32f10x.h"

//LED时钟的设置
#define LED_GPIO_CLK     RCC_APB2Periph_GPIOB
//绿灯的设置
#define LED_G_GPIO_PIN     GPIO_Pin_0
#define LED_G_GPIO_PORT    GPIOB

//红灯的设置
#define LED_R_GPIO_PIN     GPIO_Pin_5
#define LED_R_GPIO_PORT    GPIOB


//蓝灯的设置
#define LED_B_GPIO_PIN     GPIO_Pin_1
#define LED_B_GPIO_PORT    GPIOB


#define ON     1
#define OFF    0
#define LED_G(a)    if(a) \
                                GPIO_ResetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);\
                                                                                else  GPIO_SetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
#define LED_R(a)    if(a) \
                                GPIO_ResetBits(LED_R_GPIO_PORT, LED_R_GPIO_PIN);\
                                                                                else  GPIO_SetBits(LED_R_GPIO_PORT, LED_R_GPIO_PIN);

#define LED_B(a)    if(a) \
                                GPIO_ResetBits(LED_B_GPIO_PORT, LED_B_GPIO_PIN);\
                                                                                else  GPIO_SetBits(LED_B_GPIO_PORT, LED_B_GPIO_PIN);


#endif /*__BSP_LED_H*/

野火论坛202402031205149572..png
回复

使用道具 举报

发表于 2024-2-3 19:05:23 | 显示全部楼层
你的bsp_led_h实际文件名字和位置对不对 工程头文件inclue路径选对没有
回复 支持 反对

使用道具 举报

发表于 2024-2-6 17:06:24 | 显示全部楼层
编译器找不到你这个头文件,打开魔术棒->C/C++->include paths,检查你这个文件是不是在那边列出的路径中。编译器只会在列出的路径中找文件,不会在那些路径的下级路径中找。

或者你看看是不是你的文件名写错了,导致文件名对不上。
回复 支持 反对

使用道具 举报

发表于 2024-2-18 10:12:15 | 显示全部楼层
头文件找不到,文件名或者路径问题。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-30 14:38 , Processed in 0.113865 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表