微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > STM32用LCD画按钮时遇到个问题,找了不少人问都没法解决

STM32用LCD画按钮时遇到个问题,找了不少人问都没法解决

时间:10-02 整理:3721RD 点击:
我想要画按钮,就定义了一个按钮结构体,并且定义了几个结构体变量数组,结果编译时出现问题,先看代码
该段代码位于GUI.H里

  1. #ifndef _gui_h
  2. #define        _gui_h

  3. #include "stm32f10x.h"
  4. #include "lcd.h"

  5. #define        Radius                        30
  6. #define        Main_height         40
  7. #define        Main_width                100
  8. #define        Main_x                        120
  9. #define        Main_y                        60
  10. #define        Main_w_color        RED
  11. #define        Main_b_color        YELLOW
  12. #define        Main_w_size         16
  13. #define        Main_r_color        BLACK
  14. #define        BUTTONNUM                10


  15. typedef struct
  16. {
  17.         u16 x;//按钮中心点X坐标
  18.         u16        y;
  19.         u16        width;//按钮宽度
  20.         u16        height;//按钮高度
  21.         u16        word_color;//字颜色
  22.         u16 button_color;//按钮颜色
  23.         u16        rec_color;//边框颜色
  24.         u8        size;//字大小
  25.         u8 *string;//按钮显示文字

  26. }Button_Typedef;

  27. Button_Typedef ButtonX[BUTTONNUM];
  28. void GUI_Init(void);

  29. void DrawButton(Button_Typedef*);
  30. void Button_DeInit(void);
  31. void MenuButton_Init(void);
  32. void Button_Init(u8,Button_Typedef *);
  33. #endif

复制代码

编译结果如下:

  1. Build target 'LCD'
  2. compiling main.c...
  3. main.c(47): warning:  #177-D: variable "key_num" was declared but never referenced
  4.                 KEY_NUM key_num,key_num_buf;
  5. main.c(47): warning:  #177-D: variable "key_num_buf" was declared but never referenced
  6.                 KEY_NUM key_num,key_num_buf;
  7. main.c(49): warning:  #177-D: variable "i" was declared but never referenced
  8.                 u8 i=0;
  9. main.c(50): warning:  #177-D: variable "release_key" was declared but never referenced
  10.                 u8      release_key=1;
  11. main.c(51): warning:  #177-D: variable "loop_cnt" was declared but never referenced
  12.                 u32 loop_cnt=0;
  13. main.c: 5 warnings, 0 errors
  14. compiling GUI.c...
  15. linking...
  16. ..\OBJ\LCD.axf: Error: L6200E: Symbol ButtonX multiply defined (by gui.o and main.o).
  17. Not enough information to list image symbols.
  18. Not enough information to list the image map.
  19. Finished: 2 information, 0 warning and 1 error messages.
  20. "..\OBJ\LCD.axf" - 1 Error(s), 5 Warning(s).
  21. Target not created.
  22. Build Time Elapsed:  00:00:03

复制代码

我去网上查了下,有人说是RAM超出了,我发现RAM还有很大富余。
另外如果我将Button_Typedef ButtonX[BUTTONNUM];这一句放在MAIN.C里面编译就不出错。
但是我想把这个定义放到GUI.H里。
请问问题出在哪里?看编译结果的话,说是ButtonX重复定义了,但是其实并没有,我将这个变量名改成其他的也不行。

将这句话Button_Typedef ButtonX[BUTTONNUM];定义在gui.c里
然后在gui.h里写external Button_Typedef ButtonX[BUTTONNUM];试试

编译出了5个警告,说你定义的这5个变量但是没有调用,Symbol ButtonX multiply defined说ButtonX被main和gui重复定义。一般这样的警告和错误都能很容易找到的

二楼正解,要养成良好的编程习惯,不要在头文件中定义变量,一般只在头文件中声明变量类型。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top