sj 22.c(69): warning C206: 'Read_Data': missing function-prototype
sj 22.c(69): error C267: 'Read_Data': requires ANSI-style prototype
sj 22.c(139): error C100: unprintable character 0xA3 skipped
sj 22.c(139): error C100: unprintable character 0xBB skipped
sj 22.c(140): error C141: syntax error near 'Format_DateTime'
sj 22.c(140): error C100: unprintable character 0xA3 skipped
sj 22.c(140): error C100: unprintable character 0xBB skipped
sj 22.c(141): error C141: syntax error near 'Format_DateTime'
sj 22.c(141): error C100: unprintable character 0xA3 skipped
sj 22.c(141): error C100: unprintable character 0xBB skipped
sj 22.c(143): error C141: syntax error near 'strcpy'
sj 22.c - 10 Error(s), 1 Warning(s).
單片機源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- #include<string.h>
- #define uint unsigned int
- #define uchar unsigned char
- //定義DS1302與MCU接口
- sbit I0=P1^0;//IO接口
- sbit SCLK=P1^1;//時鐘引腳
- sbit RST=P1^2;//復位線引腳
- //定義1602與單片機的接口
- sbit RS=P2^0;//指令數(shù)據(jù)選擇
- sbit RW=P2^1;//接地,執(zhí)行寫操作
- sbit EN=P2^2;//信號使能
- uchar *WEEK[]=
- {
- "SUN","MON","TUS","WEN","THU","FRI","SAT"
- };
- uchar LCD_DSY_BUFFER1[ ]={"DATA 00-00-00 "};
- uchar LCD_DSY_BUFFER2[ ]={"TIME 00:00:00 "};
- uchar DateTime[7];
- /************延時i毫秒函數(shù)****************/
- void DelayMS(uint ms)
- {
- uchar i;
- while(ms--)
- {
- for(i=0;i<120;i++);
- }
- }
- /************向DS1302寫入1字節(jié)數(shù)據(jù)*********/
- void Write_A_Byte_T0_DS1302(uchar x)
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- I0=x&0x01;SCLK=1;SCLK=0;
- x>>=1; //x右移1位,高位補0
- }
- }
- /************向DS1302讀出1字節(jié)數(shù)據(jù)*********/
- uchar Get_A_Byte_FROM_DS1302()
- {
- uchar i,b=0x00;
- for(i=0;i<8;i++)
- {
- b=b|_crol_((uchar)I0,i);
- SCLK=1;SCLK=0;
- }
- return b/16*10+b%16;
- }
- /************讀取DS1302某地址的數(shù)據(jù),先寫命令字,后讀數(shù)據(jù)*********/
- uchar Read_Data_Data(uchar addr)
- {
- uchar dat;
- RST=0;//復位
- SCLK=0;//時鐘脈沖置0
- RST=1;//啟動數(shù)據(jù)傳送
- Write_A_Byte_T0_DS1302(addr);//寫入地址命令字
- dat = Get_A_Byte_FROM_DS1302();//讀出一個字節(jié)的數(shù)據(jù)
- 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;
- }
- }
- /************讀出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);//讀取忙標志BF,BF=1則一直等待
- DelayMS(5);
- }
- /************向LCD寫數(shù)據(jù)*********/
- void Write_LCD_Data(uchar dat)
- {
- LCD_Busy_Wait();//忙檢測確保上一指令完成,也可用適當?shù)难訒r替代此行
- RS=1;RW=0;EN=0;P0=dat;EN=1;DelayMS(1);EN=0;
- }
- void Write_LCD_Command(uchar cmd)
- {
- LCD_Busy_Wait();
- RS=0;RW=0;EN=0;P0=cmd;EN=1;DelayMS(1);EN=0;
- }
- /************初始化LCD函數(shù)*********/
- 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)光標和閃爍
- DelayMS(1);
- }
- void Set_LCD_P0S(uchar p)
- {
- Write_LCD_Command(p|0x80);
- }
- void Display_LCD_String(uchar p,uchar *s)
- {
- uchar i;
- Set_LCD_P0S(p);
- for(i=0;i<16;i++)
- {
- Write_LCD_Data(s[i]);
- DelayMS(1);
- }
- }
- /************格式化日期時間函數(shù)*********/
- void Format_DateTime(uchar d,uchar *a)
- {
- a[0]=d/10+'0';
- a[1]=d%10+'0';
- }
- /************主函數(shù)*********/
- void main()
- {
- Init_LCD();//初始化液晶
- 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_BUFFER1+5);
- Format_DateTime(DateTime[1],LCD_DSY_BUFFER1+8);
- Format_DateTime(DateTime[0],LCD_DSY_BUFFER1+11);
-
- Display_LCD_String(0x00,LCD_DSY_BUFFER1);//液晶顯示
- Display_LCD_String(0x40,LCD_DSY_BUFFER2);
- }
- }
復制代碼
|