找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 14095|回复: 5
打印 上一主题 下一主题
收起左侧

undefined identifier 单片机程序运行后出现以下情况,是什么问题?谢谢回复。

[复制链接]
跳转到指定楼层
楼主


keil报错:undefined identifier

  1. #include<reg52.h>                              //包含单片机寄存器的头文件
  2. #include<string.h>                             //使用字符串
  3. #include<intrins.h>                            //单片机头文件
  4. #include<lcd1602.h>                            //液晶显示lcd1602的头文件
  5. //#include<24c04.h>                            //24c02(存储记忆)的头文件
  6. #include<ds1302.h>                             //时钟芯片ds1302头文件
  7. #define uchar unsigned char
  8. #define uint unsigned int
  9. uchar  display[]={"             "};
  10. uchar i=0,j=0;
  11. uint x=0;
  12. //-------------INT0中断------------
  13. void INT0_0() interrupt 0
  14. {
  15.         i++;
  16.         if(i==1)
  17.         {
  18.                 TR0=1;
  19.         }
  20. }


  21. //------------INT1中断-------------
  22. void INT1_1() interrupt 2
  23. {
  24.         j++;
  25.         if(j==1)
  26.         {
  27.                 TR0=0;

  28.                 x=256*TH0+TL0;                  //将字节转换成十进制数
  29.         }
  30. }



  31. //-------------初始化--------------

  32. void INIT()
  33. {
  34.         TMOD=0x01;
  35.         TH0=0;
  36.         TL0=0;
  37.         EA=1;
  38.         EX0=1;
  39.         EX1=1;
  40.         IT0=1;
  41.         IT1=1;
  42.         PX0=1;
  43. }


  44. //------------数据转换--------------
  45. void dispose()
  46. {
  47.         display[7]=x/10000+'0';
  48.         display[8]=x%10000/1000+'0';
  49.         display[10]='s';
  50.         display[11]='e';
  51.         display[12]='c';
  52. }


  53. //----------主程序----------------
  54. void main()
  55. {
  56.     Init_LCD();         //初始化LCD
  57.         //display[7]='1';
  58.         //display[8]='1';
  59.         //display[10]='s';
  60.         //display[11]='e';
  61.         //display[12]='c';
  62.     //IIC_24C04_Init();   //初始化24C04
  63.         INIT();
  64.         while(1)
  65.         {
  66.                 GetTime();              //获得当前时间
  67.                 Format_DateTime(DateTime[6],LCD_DSY_BUFFER1+5);         //通道号显示
  68.                 Format_DateTime(DateTime[4],LCD_DSY_BUFFER1+8);
  69.                 Format_DateTime(DateTime[3],LCD_DSY_BUFFER1+11);
  70.             //strcpy(LCD_DSY_BUFFER1+13,WEEK[DateTime[5]]);
  71.                 Format_DateTime(DateTime[2],LCD_DSY_BUFFER2+5);
  72.                 Format_DateTime(DateTime[1],LCD_DSY_BUFFER2+8);        
  73.                 Format_DateTime(DateTime[0],LCD_DSY_BUFFER2+11);
  74.                 //Display_String(display,0x40);
  75.                 Display_String(LCD_DSY_BUFFER2,0X00);      //液晶显示
  76.                 dispose();
  77.                 Display_String(display,0x40);
  78.         }
  79. }

  80.                                                    
  81. #ifndef _lcd1602_2010_4_28_
  82. #define _lcd1602_2010_4_28_
  83. /*********************************lcd1602*****************************/
  84. #define uchar unsigned char
  85. #define uint unsigned int
  86.                               //定义1602与单片机的接口
  87. sbit RS=P2^0;                  //指令数据选择
  88. sbit RW=P2^1;                  //接地,执行写操作
  89. sbit EN=P2^2;                  //信号使能

  90. //---------------延时i毫秒函数------------------
  91. void DelayMs(uint x)
  92. {
  93. uchar i;
  94. while(x--) for(i=0;i<120;i++);
  95. }

  96. //---------------读LCD状态------------------
  97. uchar Read_LCD_State()
  98. {
  99. uchar state;
  100. RS=0;
  101. RW=1;
  102. EN=1;
  103. DelayMs(1);
  104. state=P0;
  105. EN=0;
  106. DelayMs(1);
  107. return state;
  108. }


  109. //----------------忙等待(LCD忙检测)--------------------------
  110. void LCD_Busy_Wait()
  111. {
  112. while((Read_LCD_State()&0x80)==0x80); //读取忙标志位BF,BF=1则一直等待 DelayMS(5)
  113. DelayMs(5);
  114. }


  115. //-----------------向LCD写数据----------------
  116. void Write_LCD_Data(uchar dat)
  117. {
  118. LCD_Busy_Wait();      //忙检测确保上一指令完成,也可用适当的延时替换此行
  119. RS=1;
  120. RW=0;
  121. EN=0;
  122. P0=dat;
  123. EN=1;
  124. DelayMs(1);
  125. EN=0;
  126. }
  127. //--------------写LCD命令--------------------
  128. void Write_LCD_Command(uchar cmd)
  129. {
  130. LCD_Busy_Wait();
  131. RS=0;RW=0;EN=0;P0=cmd;EN=1;DelayMs(1);EN=0;
  132. }
  133. //----------------LCD初始化-------------------
  134. void Init_LCD()
  135. {
  136. Write_LCD_Command(0x38);     //8位数据接口,2行显示,5*7点阵字符
  137. DelayMs(1);   //延时保证上一指令完成
  138. Write_LCD_Command(0x01);     //清DDRAM和AC值
  139. DelayMs(1);
  140. Write_LCD_Command(0x06);     //数据读写操作画面不动,AC自动加1
  141. DelayMs(1);
  142. Write_LCD_Command(0x0c);     //开显示,关光标和闪烁
  143. DelayMs(1);
  144. }
  145. //-------------设置液晶显示位置---------------------
  146. void Set_LCD_POS(uchar p)
  147. {
  148. Write_LCD_Command(p|0x80);
  149. }
  150. //-------------在LCD上显示字符串-----------------
  151. void Display_String(uchar*s,uchar p)
  152. {uchar i;
  153. Set_LCD_POS(p);
  154. for(i=0;i<16;i++)
  155. {
  156. Write_LCD_Data(s[i]);
  157. DelayMs(1);
  158. }
  159. }
  160. /*********************lcd1602结束*****************************/

  161. #endif
  162. #ifndef _ds1302_2010_4_28_
  163. #define _ds1302_2010_4_28_

  164. /************************ds1302*********************/

  165. #define uchar unsigned char
  166. #define uint unsigned int                     
  167.                                                //定义DS1302与MCU接口
  168. sbit IO=P2^4;                                //IO接口
  169. sbit SCLK=P2^5;                              //时钟线引脚
  170. sbit RST=P2^6;                               //复位线引脚
  171. uchar*WEEK[]={"SUN","***","MON","TUS","WEN","THU","FRI","SAT"};
  172. uchar LCD_DSY_BUFFER1[]={"DATE 00-00-00   "};
  173. uchar LCD_DSY_BUFFER2[]={"TIME 00:00:00   "};
  174. uchar DateTime[7];
  175. //--------------向DS1302写入一字符(一字节数据)----------------
  176. void Write_A_Byte_TO_DS1302(uchar x)
  177. {
  178. uchar i;
  179. for(i=0;i<8;i++)
  180. {
  181. IO=x&0x01;SCLK=1;SCLK=0;X>>=1;            //x右移1位,高位补0
  182. }
  183. }
  184. //-------------从DS1302读取一字节(一字节数据)-------------
  185. uchar Get_A_Byte_FROM_DS1302()
  186. {
  187. uchar i,b=0x00;
  188. for(i=0;i<8;i++)
  189. {
  190. b|=_crol_((uchar)IO,i);
  191. SCLK=1;SCLK=0;
  192. }
  193. return b/16*10+b%16;
  194. }
  195. //----------------从DS1302指定位置读数据(读取DS1302某地址的数据,先写命令字,后读数据)-------------------
  196. uchar Read_Date(uchar addr)
  197. {
  198. uchar dat;
  199. RST=0;          //复位
  200. SCLK=0;         //时钟脉冲置0
  201. RST=1;          //启动数据传送
  202. Write_A_Byte_IO_DS1302(addr);         //写入地址命令字
  203. dat=Get_A_Byte_FROM_DS1302();         //读出一个字节的数据
  204. SCLK=1;RST=0;
  205. return dat;
  206. }
  207. //---------------读取当前日期时间----------------
  208. void GetTime()
  209. {
  210. uchar i;addr=0x81;
  211. for(i=0;i<7;i++)
  212. {
  213. DateTime[i]=Read_Data(addr);addr+=2;
  214. }
  215. }
  216. //---------------日期与时间转换为数字字符(格式化日期时间函数)-------------------
  217. void Format_DateTime(uchar d,uchar*a)
  218. {
  219. a[0]=d/10+'0';
  220. a[1]=d%10+'0';
  221. }
  222. /**********************ds1302结束****************************/
  223. #endif

复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:96682 发表于 2017-6-4 21:47 | 只看该作者
已经给出缺少哪样文件的提示了,查找添加相应的文件进去就好
回复

使用道具 举报

板凳
ID:207753 发表于 2017-6-4 22:17 | 只看该作者
DateTime,LCD_DSY_BUFFER1和LCD_DSY_BUFFER2怎么定义?我添加了这两行,然后变成这样了。

#include<reg52.h>                              //包含单片机寄存器的头文件
#include<string.h>                             //使用字符串
#include<intrins.h>                            //单片机头文件
#include<lcd1602.h>                            //液晶显示lcd1602的头文件
//#include<24c04.h>                            //24c02(存储记忆)的头文件
#include<ds1302.h>                             //时钟芯片ds1302头文件
#define uchar unsigned char
#define uint unsigned int
uchar  display[]={"             "};
uchar i=0,j=0;
下两行是添加的
uint Format_DateTime(uchar *a,uchar *b);
uint x=0,DateTime[],LCD_DSY_BUFFER1[],LCD_DSY_BUFFER2[];


结果是这样
compiling shijiyi.c...
shijiyi.c(4): warning C318: can't open file 'lcd1602.h'
shijiyi.c(6): warning C318: can't open file 'ds1302.h'
SHIJIYI.C(83): warning C182: pointer to different objects
SHIJIYI.C(83): error C214: illegal pointer conversion
shijiyi.c - 1 Error(s), 3 Warning(s).
回复

使用道具 举报

地板
ID:207753 发表于 2017-6-4 22:21 | 只看该作者
我不太懂,试着改,把11行改了
uint Format_DateTime(uchar *a,uchar *b);
uint x=0,DateTime[],LCD_DSY_BUFFER1[],LCD_DSY_BUFFER2[];
然后就这样了
compiling shijiyi.c...
shijiyi.c(4): warning C318: can't open file 'lcd1602.h'
shijiyi.c(6): warning C318: can't open file 'ds1302.h'
SHIJIYI.C(83): warning C182: pointer to different objects
SHIJIYI.C(83): error C214: illegal pointer conversion
shijiyi.c - 1 Error(s), 3 Warning(s).
回复

使用道具 举报

5#
ID:207753 发表于 2017-6-6 09:47 | 只看该作者
有人能帮帮忙吗?这几个error怎么解决?我在网上没有搜到什么有效的方法。
回复

使用道具 举报

6#
ID:208300 发表于 2017-6-6 10:37 | 只看该作者
我不太懂,试着改,把11行改了
uint Format_DateTime(uchar *a,uchar *b);
uint x=0,DateTime[],LCD_DSY_BUFFER1[],LCD_DSY_BUFFER2[];
然后就这样了
compiling shijiyi.c...
shijiyi.c(4): warning C318: can't open file 'lcd1602.h'
shijiyi.c(6): warning C318: can't open file 'ds1302.h'
SHIJIYI.C(83): warning C182: pointer to different objects
SHIJIYI.C(83): error C214: illegal pointer conversion
shijiyi.c - 1 Error(s), 3 Warning(s).
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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