keil报错:undefined identifier
- #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 x=0;
- //-------------INT0中断------------
- void INT0_0() interrupt 0
- {
- i++;
- if(i==1)
- {
- TR0=1;
- }
- }
- //------------INT1中断-------------
- void INT1_1() interrupt 2
- {
- j++;
- if(j==1)
- {
- TR0=0;
- x=256*TH0+TL0; //将字节转换成十进制数
- }
- }
- //-------------初始化--------------
- void INIT()
- {
- TMOD=0x01;
- TH0=0;
- TL0=0;
- EA=1;
- EX0=1;
- EX1=1;
- IT0=1;
- IT1=1;
- PX0=1;
- }
- //------------数据转换--------------
- void dispose()
- {
- display[7]=x/10000+'0';
- display[8]=x%10000/1000+'0';
- display[10]='s';
- display[11]='e';
- display[12]='c';
- }
- //----------主程序----------------
- void main()
- {
- Init_LCD(); //初始化LCD
- //display[7]='1';
- //display[8]='1';
- //display[10]='s';
- //display[11]='e';
- //display[12]='c';
- //IIC_24C04_Init(); //初始化24C04
- INIT();
- while(1)
- {
- GetTime(); //获得当前时间
- Format_DateTime(DateTime[6],LCD_DSY_BUFFER1+5); //通道号显示
- Format_DateTime(DateTime[4],LCD_DSY_BUFFER1+8);
- Format_DateTime(DateTime[3],LCD_DSY_BUFFER1+11);
- //strcpy(LCD_DSY_BUFFER1+13,WEEK[DateTime[5]]);
- Format_DateTime(DateTime[2],LCD_DSY_BUFFER2+5);
- Format_DateTime(DateTime[1],LCD_DSY_BUFFER2+8);
- Format_DateTime(DateTime[0],LCD_DSY_BUFFER2+11);
- //Display_String(display,0x40);
- Display_String(LCD_DSY_BUFFER2,0X00); //液晶显示
- dispose();
- Display_String(display,0x40);
- }
- }
-
- #ifndef _lcd1602_2010_4_28_
- #define _lcd1602_2010_4_28_
- /*********************************lcd1602*****************************/
- #define uchar unsigned char
- #define uint unsigned int
- //定义1602与单片机的接口
- sbit RS=P2^0; //指令数据选择
- sbit RW=P2^1; //接地,执行写操作
- sbit EN=P2^2; //信号使能
- //---------------延时i毫秒函数------------------
- void DelayMs(uint x)
- {
- uchar i;
- while(x--) for(i=0;i<120;i++);
- }
- //---------------读LCD状态------------------
- uchar Read_LCD_State()
- {
- uchar state;
- RS=0;
- RW=1;
- EN=1;
- DelayMs(1);
- state=P0;
- EN=0;
- DelayMs(1);
- return state;
- }
- //----------------忙等待(LCD忙检测)--------------------------
- void LCD_Busy_Wait()
- {
- while((Read_LCD_State()&0x80)==0x80); //读取忙标志位BF,BF=1则一直等待 DelayMS(5)
- DelayMs(5);
- }
- //-----------------向LCD写数据----------------
- void Write_LCD_Data(uchar dat)
- {
- LCD_Busy_Wait(); //忙检测确保上一指令完成,也可用适当的延时替换此行
- RS=1;
- RW=0;
- EN=0;
- P0=dat;
- EN=1;
- DelayMs(1);
- EN=0;
- }
- //--------------写LCD命令--------------------
- void Write_LCD_Command(uchar cmd)
- {
- LCD_Busy_Wait();
- RS=0;RW=0;EN=0;P0=cmd;EN=1;DelayMs(1);EN=0;
- }
- //----------------LCD初始化-------------------
- void Init_LCD()
- {
- Write_LCD_Command(0x38); //8位数据接口,2行显示,5*7点阵字符
- DelayMs(1); //延时保证上一指令完成
- Write_LCD_Command(0x01); //清DDRAM和AC值
- DelayMs(1);
- Write_LCD_Command(0x06); //数据读写操作画面不动,AC自动加1
- DelayMs(1);
- Write_LCD_Command(0x0c); //开显示,关光标和闪烁
- DelayMs(1);
- }
- //-------------设置液晶显示位置---------------------
- void Set_LCD_POS(uchar p)
- {
- Write_LCD_Command(p|0x80);
- }
- //-------------在LCD上显示字符串-----------------
- void Display_String(uchar*s,uchar p)
- {uchar i;
- Set_LCD_POS(p);
- for(i=0;i<16;i++)
- {
- Write_LCD_Data(s[i]);
- DelayMs(1);
- }
- }
- /*********************lcd1602结束*****************************/
- #endif
- #ifndef _ds1302_2010_4_28_
- #define _ds1302_2010_4_28_
- /************************ds1302*********************/
- #define uchar unsigned char
- #define uint unsigned int
- //定义DS1302与MCU接口
- sbit IO=P2^4; //IO接口
- sbit SCLK=P2^5; //时钟线引脚
- sbit RST=P2^6; //复位线引脚
- uchar*WEEK[]={"SUN","***","MON","TUS","WEN","THU","FRI","SAT"};
- uchar LCD_DSY_BUFFER1[]={"DATE 00-00-00 "};
- uchar LCD_DSY_BUFFER2[]={"TIME 00:00:00 "};
- uchar DateTime[7];
- //--------------向DS1302写入一字符(一字节数据)----------------
- void Write_A_Byte_TO_DS1302(uchar x)
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- IO=x&0x01;SCLK=1;SCLK=0;X>>=1; //x右移1位,高位补0
- }
- }
- //-------------从DS1302读取一字节(一字节数据)-------------
- uchar Get_A_Byte_FROM_DS1302()
- {
- uchar i,b=0x00;
- for(i=0;i<8;i++)
- {
- b|=_crol_((uchar)IO,i);
- SCLK=1;SCLK=0;
- }
- return b/16*10+b%16;
- }
- //----------------从DS1302指定位置读数据(读取DS1302某地址的数据,先写命令字,后读数据)-------------------
- uchar Read_Date(uchar addr)
- {
- uchar dat;
- RST=0; //复位
- SCLK=0; //时钟脉冲置0
- RST=1; //启动数据传送
- Write_A_Byte_IO_DS1302(addr); //写入地址命令字
- dat=Get_A_Byte_FROM_DS1302(); //读出一个字节的数据
- SCLK=1;RST=0;
- return dat;
- }
- //---------------读取当前日期时间----------------
- void GetTime()
- {
- uchar i;addr=0x81;
- for(i=0;i<7;i++)
- {
- DateTime[i]=Read_Data(addr);addr+=2;
- }
- }
- //---------------日期与时间转换为数字字符(格式化日期时间函数)-------------------
- void Format_DateTime(uchar d,uchar*a)
- {
- a[0]=d/10+'0';
- a[1]=d%10+'0';
- }
- /**********************ds1302结束****************************/
- #endif
复制代码 |