編譯時在290行處顯示(290): error C141: syntax error near 'void',求幫忙改正
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define datasend P0
- sbit lcden=P1^2; //LCD 使能端
- sbit lcdrs=P1^0; //LCD 數(shù)據(jù)/指令(H/L)選擇端
- sbit lcdrw=P1^1;
- uchar mytable0[ ]=" Welcometo ";
- uchar mytable1[ ]=" Yangzhou Univ.";
- uchar code line0[ ]=" 2021-6-24 "; //初始化顯示
- uchar code line1[ ]=" 00:00:00 ";
- uchar code month0[ ]={31,28,31,30,31,30,31,31,30,31,30,31}; //平年月
- uchar code month1[ ]={31,29,31,30,31,30,31,31,30,31,30,31}; //閏年月
- uchar count,hour,minute,second,year=1,month=1,date=1;
- uchar slnum; //slnum :定義功能鍵按下次數(shù)變量
- void delay (unsigned int z)//延時子函數(shù) z*lms
- {
- unsigned int x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void write_(unsigned char c) //寫命令子函數(shù)
- {
- lcdrs=0; //低電平選擇為寫指令
- lcden=0;
- datasend=c; //把指令寫入P0 口
- delay(5);
- lcden=1; //開使能
- delay(5); //讀取指令
- lcden=0; //關閉使能
- }
- void write_data(unsigned char d) //寫數(shù)據(jù)子函數(shù)
- {
- lcdrs=1;//高電平選擇為寫數(shù)據(jù)
- datasend=d;//把數(shù)據(jù)寫入P0 口
- delay(5);
- lcden=1;//開使能
- delay(5);//讀取數(shù)據(jù)
- lcden=0;//關閉使能
- }
- void write_hms(uchar add,uchar dat) //時分秒寫函數(shù) add :輸入位置設置變量 dat :輸入時分秒數(shù)據(jù)
- {
- uchar sw,gw;//定義十位,個位變量
- sw=dat/10;
- gw=dat%10;
- write_(0x80+0x40+add);//從第一行(add)位開始寫數(shù)據(jù)
- write_data(0x30+sw);//寫入十位
- write_data(0x30+gw);//寫入個位
- }
- void write_ymd(uchar add,uchar dat)//年月日寫函數(shù) add :輸入位置設置變量 dat :輸入時分秒數(shù)據(jù)
- {
- uchar sw,gw;
- sw=dat/10;
- gw=dat%10;
- write_(0x80+add);//從第一行(add)位開始寫數(shù)據(jù)
- write_data(0x30+sw);//寫入十位
- write_data(0x30+gw);//寫入個位
- }
- void t0() interrupt 1//定時器0中斷子程序
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- count++;
- }
- void gethms()//時分秒處理子程序
- {
- second++;
- if(second==60)
- {
- second=0;
- minute++;
- if(minute==60)
- {
- minute=0;
- hour++;
- if(hour==24)
- {
- hour=0;
- date++;
- }
- write_hms(2,hour);//時輸出顯示
- }
- write_hms(5,minute);//分輸出顯示
- }
- write_hms(8,second);//秒輸出顯示
- }
- void getymd( )//年月日處理子程序
- {
- if(year%4==0)
- {
- if(date==month1[month-1]+1)
- {
- date=1;
- month++;
- if(month==13)
- {
- month=1;
- year++;
- if(year==100)
- {
- year=1;
- }
- write_ymd(4,year);
- }
- write_ymd(7,month);
- }
- write_ymd(10,date);
- }
- else
- {
- if(date==month0[month-1]+1)
- {
- date=1;
- month++;
- if(month==13)
- {
- month=1;
- year++;
- if(year==100)
- {
- year=1;
- }
- write_ymd(4,year);
- }
- write_ymd(7,month);
- }
- write_ymd(10,date);
- }
- }
- void key_process()//按鍵掃描子程序
- {
- if(P2==0xf6)//功能鍵
- delay(25);
- if(P2==0xf6)//功能鍵按下
- {
- while(P2==0xf6);//松手檢測
- slnum++;//功能鍵按下計數(shù)
- TR0=0;//T0定時停止,進入時間調(diào)整
- switch(slnum)
- {
- case 1: write_(0x80+0x40+0x09);break;//光標閃爍位定為秒個位
- case 2: write_(0x80+0x40+0x06);break;//光標閃爍位定為分個位
- case 3: write_(0x80+0x40+0x03);break;//光標閃爍位定為時個位
- case 4: write_(0x80+0x0b);//光標閃爍位定為日個位
- case 5: write_(0x80+0x08);//光標閃爍位定為月個位
- case 6: write_(0x80+0x05);//光標閃爍位定為年個位
- }
- write_(0x0f);//光標閃爍
- if(slnum==7)
- {
- slnum=0;//按鍵計數(shù)復位
- write_(0x0c);//光標停止閃爍
- TR0=1;//重新啟動定時器
- }
- }
- if(P2==0xee)//時分秒+1模塊
- {
- delay(25);
- if(P2==0xee)
- {
- while(P2==0xee);
- switch(slnum)
- {
- case 1: second++;//秒+
- if(second==60) second=0;//復位
- write_hms(8,second); //秒輸出顯示
- write_(0x80+0x40+0x09);//光標閃爍位定為秒個位
- break;
- case 2: minute++;
- if(minute==60) minute=0;//復位
- write_hms(5,minute); //分輸出顯示
- write_(0x80+0x40+0x06);//光標閃爍位定為分個位
- break;
- case 3: hour++;
- if(hour==24) hour=0; //復位
- write_hms(2,hour); //時輸出顯示
- write_(0x80+0x40+0x03);//光標閃爍位定為時個位
- break;
- case 4: date++;//日+
- if(year%4==0)//平閏年判斷
- break;
- {
- if(date==month1[month-1]+1)
- {
- date=1;
- }
- else
- {
- if(date==month0[month-1]+1)
- {
- date=1;
- }
- }
- }
- write_ymd(10,date); //日輸出顯示
- write_(0x80+0x0b);//光標閃爍位定為日個位
- break;
- case 5:month++;//月+
- if(month==13) month=1;
- if(year%4==0)//判斷日和月的配對關系
- {
- if(date>month1[month-1])
- date=month1[month-1];
- }
- else
- {
- if(date>month0[month-1])
- date=month0[month-1];
- }
- write_ymd(10,date); //日輸出顯示
- write_ymd(7,month);//月輸出顯示
- write_(0x80+0x08);//光標閃爍位定為月個位
- break;
- case 6: year++;//年+
- if(year==100) year=1;//復位
- write_ymd(4,year);//年輸出顯示
- write_(0x80+0x05);//光標閃爍位定為年個位
- break;
- }
- }
- }
- if(P2==0xde)//時分秒-1模塊
- {
- delay(5);
- if(P2==0xde)
- {
- while(P2==0xde);
- switch(slnum)
- {
- while(P2==0xde);
- switch(slnum)
- {
- case 1:second--;//秒-
- if(second==255) second=59; //復位
- write_hms(8,second);//秒輸出顯示
- write_(0x80+0x40+0x09);//光標閃爍位定為秒個位
- break;
- case 2: minute--;
- if(minute==255) minute=59;//復位
- write_hms(5,minute); //分輸出顯示
- write_(0x80+0x40+0x06);//光標閃爍位定為分個位
- break;
- case 3: hour--;
- if(hour==255) hour=23; //復位
- write_hms(2,hour); //時輸出顯示
- write_(0x80+0x40+0x03);//光標閃爍位定為時個位
- break;
- case 4: date--;//日-
- if(year%4==0)//平閏年判斷
- {
- if(date==0)
- {
- date=month1[month-1];
- }
- }
- else
- {
- if(date==0)
- {
- date=month0[month-1];
- }
- }
- write_ymd(10,date); //日輸出顯示
- write_(0x80+0x0b);//光標閃爍位定為日個位
- break;
- case 5:month--; //月-
- if(month==0) month=12;
- if(year%4==0) //判斷日和月的配對關系
- {
- if(date>month1[month-1])
- date=month1[month-1];
- }
- {
- if(date>month0[month-1])
- date=month0[month-1];
- }
- write_ymd(10,date); //日輸出顯示
- write_ymd(7,month);//月輸出顯示
- write_(0x80+0x08);//光標閃爍位定為月個位
- break;
- case 6: year--;//年-
- if(year==1) year=99;//復位
- write_ymd(4,year);//年輸出顯示
- write_(0x80+0x05);//光標閃爍位定為年個位
- break;
- }
- }
- }
- }
- void initialize()//LCD初始化函數(shù)
- {
- uchar num;
- lcden=0;
- write_(0x38);//設置16x2顯示,5x7點陣顯示,8位數(shù)據(jù)接口
- write_(0x0c);//00001DCB,D(開關顯示),C(是否顯示光標),B(光標閃爍,光標不顯示)
- write_(0x06);//000001N0,N(地址指針+-1)
- write_(0x01);//清屏指令 每次顯示下一屏容時,必須清屏
- write_(0x80+0x10);//第一行顯示
- for(num=0;num<16;num++)//顯示16個字符
- {
- write_data(mytable0[num]);
- delay(10);
- }
- write_(0x80+0x50);//第二行,從第一格開始顯示
- for(num=0;num<16;num++)//顯示16個字符
- {
- write_data(mytable1[num]);
- delay(10);
- }
- for(num=0;num<16;num++)
- {
- write_(0x1c);//0001(S/C)(R/L)**;S/C:高電平移動字符,低電平移動光標;R/L:高電平左移,低電平右移
- delay(300);
- }
- delay(1000);
- write_(0x01);//清屏指令 每次顯示下一屏內(nèi)容時,必須清屏
- write_(0x80);
- for(num=0;num<13;num++)//初始化第一行顯示
- {
- write_data(line0[num]);
- delay(50);
- }
- write_(0x80+0x40);//第二行,頂格顯示
- for(num=0;num<10;num++)//初始化第二行顯示
- {
- write_date(line1[num]);
- delay(50);
- }
- TMOD=0x01;//定時器0中斷初值設置
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1:
- ET0=1;
- TR0=1;
- }
- void main()
- {
- lcdrw=0;
- P2=0xfe;
- initialize();//初始化
- while(1)
- {
- key_process();//按鍵掃描
- if(count==20)//定時1s運行模塊
- {
- count=0;
- gethms();//時分秒數(shù)據(jù)處理
- getymd();//年月日數(shù)據(jù)處理
- }
- }
- }
復制代碼
|