野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15452|回复: 13

看火哥的视频后我跟着编程怎么报错啊

[复制链接]
发表于 2018-9-29 15:00:53 | 显示全部楼层 |阅读模式
*** Using Compiler 'V5.05 update 2 (build 169)', folder: 'D:\Program Files\KEIL\MDK\ARM\ARMCC\Bin'
Build target 'Template'
compiling main.c...
..\USER\main.c(9): warning:  #223-D: function "KEY1_Init" declared implicitly
        KEY1_Init();
..\USER\main.c(13): error:  #137: expression must be a modifiable lvalue
            if( Key_Scan(
PIOI,
PIO_Pin_8)=
EY1_ON )
..\USER\main.c: 1 warning, 1 error
".\Objects\Template.axf" - 1 Error(s), 1 Warning(s).
Target not created.
Build Time Elapsed:  00:00:01
回复

使用道具 举报

发表于 2018-9-29 15:01:37 | 显示全部楼层
函数没有声明或者没定义
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-9-29 15:04:22 | 显示全部楼层
flyleaf 发表于 2018-9-29 15:01
函数没有声明或者没定义

定义了啊 我等下把程序贴出来,受累给看下
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-9-29 15:06:11 | 显示全部楼层
本帖最后由 咸鱼之身 于 2018-9-29 15:07 编辑

#ifndef __KEY_H
#define __KEY_H

#include"stm32f4xx.h"

#endif /* _KEY_H */

//#define KEY1                GPIO_ReadInputDataBit(GPIOI,GPIO_Pin_8)
//#define KEY2                GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)
//#define KEY3                GPIO_ReadInputDataBit(GPIOI,GPIO_Pin_11)

#define KEY1_ON                0
#define KEY1_OFF    1



void KEY_Init(void);

uint8_t Key_Scan(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
——————————————————————————————————————
#include"key.h"

void Delay(uint32_t t)
{
        while(t!=0)
        t--;
}

void KEY1_Init(void)
{

  GPIO_InitTypeDef  GPIO_InitStructure;
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOI, &GPIO_InitStructure);
}

uint8_t Key_Scan(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{

        if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY1_ON)
        {
                Delay(0xFFF);       //        消抖
                if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY1_ON)
                {
                        while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY1_ON);
                        return KEY1_ON;
                }
                else return KEY1_OFF;        
        }

        else return KEY1_OFF;

}
_____________________________________________________________________

#include"stm32f4xx.h"
#include "led.h"
#include "key.h"

int main(void)
{
        Init_LED1();

        KEY1_Init();
  
        while(1)
        {
          if( Key_Scan(GPIOI,GPIO_Pin_8)= KEY1_ON )
                          LED1_ON;
                 
        }
}





   



回复 支持 反对

使用道具 举报

发表于 2018-9-29 15:26:01 | 显示全部楼层
大概你把主函数里面的key.h改成key.c就能用了,要么在key.h里面把函数声明加上,就是把函数名那一行复制过去然后加上分号。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-9-29 15:34:40 | 显示全部楼层
非谢家之宝树 发表于 2018-9-29 15:26
大概你把主函数里面的key.h改成key.c就能用了,要么在key.h里面把函数声明加上,就是把函数名那一行复制过 ...

也不行啊,我 key.h 申明了按键扫描函数了啊
回复 支持 反对

使用道具 举报

发表于 2018-9-29 15:36:40 | 显示全部楼层
咸鱼之身 发表于 2018-9-29 15:34
也不行啊,我 key.h 申明了按键扫描函数了啊

没有看到啊。。。。
回复 支持 反对

使用道具 举报

发表于 2018-9-29 15:38:20 | 显示全部楼层
本帖最后由 非谢家之宝树 于 2018-9-29 15:39 编辑

不过你的错误好像不是声明的问题 ,你的keyscan那里是不是少了个=? 应该是== 不是=
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-9-29 15:40:45 | 显示全部楼层

我看火哥视频写的,几乎都一样,我编译就报错了 ~
回复 支持 反对

使用道具 举报

发表于 2018-9-29 15:43:15 | 显示全部楼层
if( Key_Scan(GPIOI,GPIO_Pin_8)== KEY1_ON )
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-9-29 15:47:44 | 显示全部楼层
非谢家之宝树 发表于 2018-9-29 15:43
if( Key_Scan(GPIOI,GPIO_Pin_8)== KEY1_ON )

这个有错么?
回复 支持 反对

使用道具 举报

发表于 2018-9-29 15:52:27 | 显示全部楼层

搜一下c语言中= 和==的含义及区别
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-9-29 15:56:45 | 显示全部楼层
非谢家之宝树 发表于 2018-9-29 15:52
搜一下c语言中= 和==的含义及区别

嗯嗯 ,我知道这个,写错了,谢谢了
回复 支持 反对

使用道具 举报

发表于 2018-9-29 16:09:36 | 显示全部楼层
咸鱼之身 发表于 2018-9-29 15:56
嗯嗯 ,我知道这个,写错了,谢谢了

嗯嗯,刚开始学很容易在这些小地方出错,还有少分号什么的
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-6 16:05 , Processed in 0.048785 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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