今天寫程序時遇到一個不能理解的語法錯誤,
編譯時顯示致命錯誤,
請問各位大神是什么原因呢
TIM截圖20181001183448.png (244.2 KB, 下載次數: 33)
下載附件
2018-10-1 18:40 上傳
20181001183322.png (214.06 KB, 下載次數: 41)
下載附件
2018-10-1 18:40 上傳
報錯如下:
compiling mian.c...
C51 FATAL-ERROR -
ACTION: GOBAL OPTIMIZATION
FUNCTION: _year_split
ERROR: CANNOT OPTIMIZE FUNCTION
COMPILATION TERMINATED.
use the following work-around:
#pragma OPTIMIZE (7)
/* your original function */
_year_split () {
....
}
/* end of your original function */
#pragma OPTIMIZE (8)
實驗顯示我不給定義的變量賦初值,或者傳到子程序的參數為修改為uchar類型之后就可以了,但是uint類型卻不行,不知道為什么
全部程序如下:(問題語句為void year_split(int value)這個子函數鐘)
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define Date P0
- sbit RS=P1^0;
- sbit RW=P1^1;
- sbit EN=P2^5;
- sbit FM=P2^3;
- sbit SW1=P3^5;
- sbit SW2=P3^6;
- sbit SW3=P3^7;
- int second = 0, minute = 0, hour = 0;
- int nian = 1988,yue = 0,ri = 0;
- uint count = 0;
- uint num = 0;
- void delay(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=112;j>0;j--);
- }
- void ring()
- {
- FM=0;
- delay(100);
- FM=1;
- }
- void com(uchar command)
- {
- RS=0;
- RW=0;
- Date=command;
- delay(5);
- EN=1;
- delay(5);
- EN=0;
- }
- void dat(uchar date)
- {
- RS=1;
- RW=0;
- Date=date;
- delay(5);
- EN=1;
- delay(5);
- EN=0;
- }
- void year_split(int value)
- {
- int qian=0,bai=0,shi=0,ge=0;
- qian = value / 1000;
- bai = (value / 100) % 10;
- shi = (value / 10) % 10;
- ge = value % 10;
- com(0x80);
- dat(qian + 0x30);
- dat(bai + 0x30);
- dat(shi + 0x30);
- dat(ge + 0x30);
- }
- void date_split(uchar add,uchar value)
- {
- int shi,ge;
- shi = value / 10;
- ge = value % 10;
- com(0x80+add);
- dat(shi + 0x30);
- dat(ge + 0x30);
- }
- void time_split(uchar add,uchar value)
- {
- int shi,ge;
- shi = value / 10;
- ge = value % 10;
- com(0xc0+add);
- dat(shi + 0x30);
- dat(ge + 0x30);
- }
- void LCD_Init()
- {
- com(0x38); //LCD設置
- delay(5);
- com(0x01); //清屏
- com(0x06); //寫入新數據后光標后移一位,整屏不移動
- com(0x0c); //顯示光標,光標不顯示
- }
- void Time_Init()
- {
- com(0x80+4);
- dat('-');
- com(0x80+7);
- dat('-');
- com(0xc0+6);
- dat(':');
- com(0xc0+9);
- dat(':');
- year_split(nian);
- date_split(5,yue);
- date_split(8,ri);
- time_split(4,hour);
- time_split(7,minute);
- time_split(10,second);
- TMOD = 0x01;
- TH0 = (65536-46083)/256;
- TL0 = (65536-46083)%256;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- void Set_key()
- {
- if(SW1 == 0)
- {
- delay(5);
- if(SW1 == 0)
- {
- while(SW1 == 0);
- num++;
- ring();
- }
- }
- switch(num)
- {
- case 1:
- TR0 = 0; //定時器關
- com(0xc0+10);
- com(0x0f); //顯示開,光標閃爍
- if(SW2 == 0)
- {
- delay(5);
- if(SW2 == 0)
- {
- while(SW2 == 0);
- second++;
- ring();
- if(second >= 60)
- {
- second = 0;
- }
- time_split(10,second);
- }
- }
-
- if(SW3 == 0)
- {
- delay(5);
- if(SW3 == 0)
- {
- while(SW3 == 0);
- second--;
- ring();
- if(second <= -1)
- {
- second = 59;
- }
- time_split(10,second);
- }
- }
- break;
- case 2:
- com(0xc0+8);
- if(SW2 == 0)
- {
- delay(5);
- if(SW2 == 0)
- {
- while(SW2 == 0);
- minute++;
- ring();
- if(minute >= 60)
- {
- minute = 0;
- }
- time_split(7,minute);
- }
- }
-
- if(SW3 == 0)
- {
- delay(5);
- if(SW3 == 0)
- {
- while(SW3 == 0);
- minute--;
- ring();
- if(minute <= -1)
- {
- minute = 59;
- }
- time_split(7,minute);
- }
- }
- break;
-
- case 3:
- com(0xc0+4);
- if(SW2 == 0)
- {
- delay(5);
- if(SW2 == 0)
- {
- while(SW2 == 0);
- hour++;
- ring();
- if(hour >= 24)
- {
- hour = 0;
- }
- time_split(4,hour);
- }
- }
-
- if(SW3 == 0)
- {
- delay(5);
- if(SW3 == 0)
- {
- while(SW3 == 0);
- hour--;
- ring();
- if(hour <= -1)
- {
- hour = 23;
- }
- time_split(4,hour);
- }
- }
-
- break;
-
- case 4:
- num = 0;
- TR0 = 1; //定時器開
- com(0x0c); //顯示關,光標不閃爍
- break;
- }
- }
- void Set_display()
- {
- if(count == 20)
- {
- count = 0;
- second++;
- time_split(10,second);
- if(second >= 60)
- {
- second = 0;
- minute++;
- time_split(10,second);
- time_split(7,minute);
- if(minute >= 60)
- {
- minute = 0;
- hour++;
- time_split(7,minute);
- time_split(4,hour);
- if(hour >= 24)
- {
- hour = 0;
- time_split(4,hour);
- }
- }
- }
- }
- }
- void main()
- {
- LCD_Init();
- Time_Init();
- while(1)
- {
- Set_key();
- Set_display();
- }
- }
- void time()interrupt 1
- {
- count++;
- TH0 = (65536-46083)/256; //50ms=(12/11059200)*1000*(65536-初值)
- TL0 = (65536-46083)%256;
- }
復制代碼
|