今天写程序时遇到一个不能理解的语法错误,
编译时显示致命错误,
请问各位大神是什么原因呢
报错如下:
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;
- }
复制代码
|