|
keil報錯:undefined identifier
- #include<reg52.h> //包含單片機(jī)寄存器的頭文件
- #include<string.h> //使用字符串
- #include<intrins.h> //單片機(jī)頭文件
- #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; //將字節(jié)轉(zhuǎn)換成十進(jìn)制數(shù)
- }
- }
- //-------------初始化--------------
- void INIT()
- {
- TMOD=0x01;
- TH0=0;
- TL0=0;
- EA=1;
- EX0=1;
- EX1=1;
- IT0=1;
- IT1=1;
- PX0=1;
- }
- //------------數(shù)據(jù)轉(zhuǎn)換--------------
- 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(); //獲得當(dāng)前時間
- 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與單片機(jī)的接口
- sbit RS=P2^0; //指令數(shù)據(jù)選擇
- sbit RW=P2^1; //接地,執(zhí)行寫操作
- sbit EN=P2^2; //信號使能
- //---------------延時i毫秒函數(shù)------------------
- void DelayMs(uint x)
- {
- uchar i;
- while(x--) for(i=0;i<120;i++);
- }
- //---------------讀LCD狀態(tài)------------------
- 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); //讀取忙標(biāo)志位BF,BF=1則一直等待 DelayMS(5)
- DelayMs(5);
- }
- //-----------------向LCD寫數(shù)據(jù)----------------
- void Write_LCD_Data(uchar dat)
- {
- LCD_Busy_Wait(); //忙檢測確保上一指令完成,也可用適當(dāng)?shù)难訒r替換此行
- 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位數(shù)據(jù)接口,2行顯示,5*7點陣字符
- DelayMs(1); //延時保證上一指令完成
- Write_LCD_Command(0x01); //清DDRAM和AC值
- DelayMs(1);
- Write_LCD_Command(0x06); //數(shù)據(jù)讀寫操作畫面不動,AC自動加1
- DelayMs(1);
- Write_LCD_Command(0x0c); //開顯示,關(guān)光標(biāo)和閃爍
- DelayMs(1);
- }
- //-------------設(shè)置液晶顯示位置---------------------
- 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結(jié)束*****************************/
- #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; //復(fù)位線引腳
- 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寫入一字符(一字節(jié)數(shù)據(jù))----------------
- 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位,高位補(bǔ)0
- }
- }
- //-------------從DS1302讀取一字節(jié)(一字節(jié)數(shù)據(jù))-------------
- 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指定位置讀數(shù)據(jù)(讀取DS1302某地址的數(shù)據(jù),先寫命令字,后讀數(shù)據(jù))-------------------
- uchar Read_Date(uchar addr)
- {
- uchar dat;
- RST=0; //復(fù)位
- SCLK=0; //時鐘脈沖置0
- RST=1; //啟動數(shù)據(jù)傳送
- Write_A_Byte_IO_DS1302(addr); //寫入地址命令字
- dat=Get_A_Byte_FROM_DS1302(); //讀出一個字節(jié)的數(shù)據(jù)
- SCLK=1;RST=0;
- return dat;
- }
- //---------------讀取當(dāng)前日期時間----------------
- void GetTime()
- {
- uchar i;addr=0x81;
- for(i=0;i<7;i++)
- {
- DateTime[i]=Read_Data(addr);addr+=2;
- }
- }
- //---------------日期與時間轉(zhuǎn)換為數(shù)字字符(格式化日期時間函數(shù))-------------------
- void Format_DateTime(uchar d,uchar*a)
- {
- a[0]=d/10+'0';
- a[1]=d%10+'0';
- }
- /**********************ds1302結(jié)束****************************/
- #endif
復(fù)制代碼 |
|