keil编译C语言内存不足 怎么解决 求助各位老师

2019-07-16 02:58发布

一个万年历的程序,就是有点长不知道压缩。。。【求助】
#include<reg52.h>
#include<intrins.h>
#define LCD_Data P0
#define uchar unsigned char
unsigned char sec,min,hour,day,month,year,cen,week,next,aa,bb,cc,dd,mm,temp0,LunARMonth,LunarDay,LunarYear;
int temp;
uchar tt=1;
bit c_moon;
bit cenbit=1;
bit w;
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
sbit PSB=P2^3;
sbit DS1302_CLK=P3^7;
sbit DS1302_IO=P3^6;
sbit DS1302_RST=P3^5;
sbit DS18B20=P2^5;
sbit speak=P2^7;
sbit SetKey=P1^4; //按键功
sbit SureKey=P1^5; //按键功
sbit PlusKey=P1^6; //按键功
sbit ReduceKey=P1^7; //按键功
sbit scl=P1^1;
sbit sda=P1^0;
void DisplayShengXiao(void);
void delay(unsigned int a)//延时1MS/次
{
unsigned char i;
while(--a)
{
for(i=0;i<125;i++);
}
}
void delayb(unsigned int count)
{
while(count--);
}
void delays()
{;;}
void start()
{
sda=1;
scl=1;
delays();
sda=0;
delays();
}
void stop()
{
sda=0;
scl=1;
delays();
sda=1;
delays();
}
void response()
{
uchar i;
while((sda==1)&&i<255)i++;
scl=1;
delays();
scl=0; //没有这一步出错,如果
delays();
}
void write24c02(uchar date)
{
uchar temp,i;
temp=date;
for(i=0;i<8;i++)
{
scl=0;
sda=temp&0x80;
delays();
scl=1;
delays();
temp=temp<<1;
}
scl=0;
delays();
sda=1;
delays();
}
uchar read24c02()
{
uchar k,i;
scl=0;
delays();
sda=1;//仅仅是释放数据线,可有
for(i=0;i<8;i++)
{
scl=1;
delays();
k=k<<1;
if(sda)
k++;
scl=0;
delays();
}
return k;
}
void write_24c02add(uchar address,uchar date)
{
start();
write24c02(0xa0);
response();
write24c02(address);
response();
write24c02(date);
response();
stop();
}
uchar read_24c02add(uchar address)
{
uchar a;
start();
write24c02(0xa0);
response();
write24c02(address);
response();
start();
write24c02(0xa1);
response();
a=read24c02();
stop();
return a;
}
unsigned char DS18B20Init()
{
unsigned char x;
DS18B20=1;
delayb(2);
DS18B20=0;
delayb(80);
DS18B20=1;
delayb(5);
x=DS18B20;
delayb(20);
return x;
}
unsigned char TempRead(void)
{
unsigned char i,dat;
DS18B20=1;
delayb(1);
for(i=0;i<8;i++)
{
DS18B20=0;
dat=dat>>1;
DS18B20=1;
if(DS18B20)
dat=dat|0x80;
delayb(4);
}
return dat;
}
void TempWriteByte(unsigned char
dat)
{
unsigned int i;
DS18B20=1;
delayb(2);
for(i=0;i<8;i++)
{
DS18B20=0;
DS18B20=dat&0x01;
delayb(8);
DS18B20=1;
dat=dat>>1;
delayb(2);
}
}
int GetTemp()
{
float tt;
unsigned char a,b;
DS18B20Init();
TempWriteByte(0xcc);
TempWriteByte(0x44);
delayb(100);
DS18B20Init();
TempWriteByte(0xcc);
TempWriteByte(0xbe);
delayb(200);
a=TempRead();
b=TempRead();
temp=b;
temp<<=8;
temp=temp|a;
tt=temp*0.0625;
temp=tt*10+0.5;
return temp;
}
void WriteDs1302Byte(unsigned char temp)
{
unsigned char i;
for(i=8;i>0;i--)
{
DS1302_IO=temp&0x01;
DS1302_CLK=0;
DS1302_CLK=1;
temp>>=1;
}
}
void WriteDs1302(unsigned char address,unsigned char dat)
{
DS1302_RST=0;
DS1302_CLK=0;
DS1302_RST=1;
delay(1);
WriteDs1302Byte(address);
WriteDs1302Byte(dat);
DS1302_RST=0;
}
unsigned char read_byte()
{
unsigned char i;
for(i=8;i>0;i--)
{
if(DS1302_IO)
temp0=temp0|0x80;
DS1302_CLK=1;
DS1302_CLK=0;
temp0=temp0>>1;
}
return temp0;
}
unsigned char ReadDs1302(unsigned char address)
{
unsigned char temp;
DS1302_RST=0;
DS1302_CLK=0;
DS1302_RST=1;
WriteDs1302Byte(address);
temp=read_byte();
DS1302_RST=0;
DS1302_CLK=1;
return temp;
}
void InitDS1302()
{
unsigned char Second=ReadDs1302(0x80);
if(Second&0x80)
{
WriteDs1302(0x8e,0x00);
delay(5);
WriteDs1302(0x8c,0x10);//写入年份10年
delay(5);
WriteDs1302(0x8a,0x06);//写入星期6
delay(5);
WriteDs1302(0x88,0x11);//定入月分11月
delay(5);
WriteDs1302(0x86,0x6);//写入日期6日
delay(5);
WriteDs1302(0x84,0x17);//写入小时17点
delay(5);
WriteDs1302(0x82,0x43);
delay(5);
WriteDs1302(0x80,0x00);//写入秒30秒
delay(5);
WriteDs1302(0x8e,0x80);//控制命令,WP为1,禁止写操作
}
}/*阳历对应的阴历数据,每年三字节,格式第一字节BIT7-4位表示闰月月份,为0,则无闰月,BIT3-0对应阴历第1-4月的大小,第二字节BIT7-0对应阴历第5-12月大小,第三字节BIT7表示阴历第13月大小月分对应的位为1,表示农历月大(30天)为0表示小(29天)第三字节BIT6-5表示春节的公历月份,BIT4-0表示春节公历日期*/
code unsigned char YearCode[597]=
{
0x04,0xAe,0x53, //19010
0x0A,0x57,0x48, //19023
0x55,0x26,0xBd, //19036
0x0d,0x26,0x50, //19049
0x0d,0x95,0x44, //190512
0x46,0xAA,0xB9, //190615
0x05,0x6A,0x4d, //190718
0x09,0xAd,0x42, //190821
0x24,0xAe,0xB6, //1909
0x04,0xAe,0x4A, //1910
0x6A,0x4d,0xBe, //1911
0x0A,0x4d,0x52, //1912
0x0d,0x25,0x46, //1913
0x5d,0x52,0xBA, //1914
0x0B,0x54,0x4e, //1915
0x0d,0x6A,0x43, //1916
0x29,0x6d,0x37, //1917
0x09,0x5B,0x4B, //1918
0x74,0x9B,0xC1, //1919
0x04,0x97,0x54, //1920
0x0A,0x4B,0x48, //1921
0x5B,0x25,0xBC, //1922
0x06,0xA5,0x50, //1923
0x06,0xd4,0x45, //1924
0x4A,0xdA,0xB8, //1925
0x02,0xB6,0x4d, //1926
0x09,0x57,0x42, //1927
0x24,0x97,0xB7, //1928
0x04,0x97,0x4A, //1929
0x66,0x4B,0x3e, //1930
0x0d,0x4A,0x51, //1931
0x0e,0xA5,0x46, //1932
0x56,0xd4,0xBA, //1933
0x05,0xAd,0x4e, //1934
0x02,0xB6,0x44, //1935
0x39,0x37,0x38, //1936
0x09,0x2e,0x4B, //1937
0x7C,0x96,0xBf, //1938
0x0C,0x95,0x53, //1939
0x0d,0x4A,0x48, //1940
0x6d,0xA5,0x3B, //1941
0x0B,0x55,0x4f, //1942
0x05,0x6A,0x45, //1943
0x4A,0xAd,0xB9, //1944
0x02,0x5d,0x4d, //1945
0x09,0x2d,0x42, //1946
0x2C,0x95,0xB6, //1947
0x0A,0x95,0x4A, //1948
0x7B,0x4A,0xBd, //1949
0x06,0xCA,0x51, //1950
0x0B,0x55,0x46, //1951
0x55,0x5A,0xBB, //1952
0x04,0xdA,0x4e, //1953
0x0A,0x5B,0x43, //1954
0x35,0x2B,0xB8, //1955
0x05,0x2B,0x4C, //1956
0x8A,0x95,0x3f, //1957
0x0e,0x95,0x52, //1958
0x06,0xAA,0x48, //1959
0x7A,0xd5,0x3C, //1960
0x0A,0xB5,0x4f, //1961
0x04,0xB6,0x45, //1962
0x4A,0x57,0x39, //1963
0x0A,0x57,0x4d, //1964
0x05,0x26,0x42, //1965
0x3e,0x93,0x35, //1966
0x0d,0x95,0x49, //1967
0x75,0xAA,0xBe, //1968
0x05,0x6A,0x51, //1969
0x09,0x6d,0x46, //1970
0x54,0xAe,0xBB, //1971
0x04,0xAd,0x4f, //1972
0x0A,0x4d,0x43, //1973
0x4d,0x26,0xB7, //1974
0x0d,0x25,0x4B, //1975
0x8d,0x52,0xBf, //1976
0x0B,0x54,0x52, //1977
0x0B,0x6A,0x47, //1978
0x69,0x6d,0x3C, //1979
0x09,0x5B,0x50, //1980
0x04,0x9B,0x45, //1981
0x4A,0x4B,0xB9, //1982
0x0A,0x4B,0x4d, //1983
0xAB,0x25,0xC2, //1984
0x06,0xA5,0x54, //1985
0x06,0xd4,0x49, //1986
0x6A,0xdA,0x3d, //1987
0x0A,0xB6,0x51, //1988
0x09,0x37,0x46, //1989
0x54,0x97,0xBB, //1990
0x04,0x97,0x4f, //1991
0x06,0x4B,0x44, //1992
0x36,0xA5,0x37, //1993
0x0e,0xA5,0x4A, //1994
0x86,0xB2,0xBf, //1995
0x05,0xAC,0x53, //1996
0x0A,0xB6,0x47, //1997
0x59,0x36,0xBC, //1998
0x09,0x2e,0x50, //1999294
0x0C,0x96,0x45, //2000297
0x4d,0x4A,0xB8, //2001300
0x0d,0x4A,0x4C, //2002303
0x0d,0xA5,0x41, //2003306
0x25,0xAA,0xB6, //2004309
0x05,0x6A,0x49, //2005312
0x7A,0xAd,0xBd, //2006315
0x02,0x5d,0x52, //2007318
0x09,0x2d,0x47, //2008321
0x5C,0x95,0xBA, //2009324
0x0A,0x95,0x4e, //2010327
0x0B,0x4A,0x43, //2011
0x4B,0x55,0x37, //2012
0x0A,0xd5,0x4A, //2013
0x95,0x5A,0xBf, //2014
0x04,0xBA,0x53, //2015
0x0A,0x5B,0x48, //2016
0x65,0x2B,0xBC, //2017
0x05,0x2B,0x50, //2018
0x0A,0x93,0x45, //2019
0x47,0x4A,0xB9, //2020
0x06,0xAA,0x4C, //2021
0x0A,0xd5,0x41, //2022
0x24,0xdA,0xB6, //2023
0x04,0xB6,0x4A, //2024
0x69,0x57,0x3d, //2025
0x0A,0x4e,0x51, //2026
0x0d,0x26,0x46, //2027
0x5e,0x93,0x3A, //2028
0x0d,0x53,0x4d, //2029
0x05,0xAA,0x43, //2030
0x36,0xB5,0x37, //2031
0x09,0x6d,0x4B, //2032
0xB4,0xAe,0xBf, //2033
0x04,0xAd,0x53, //2034
0x0A,0x4d,0x48, //2035
0x6d,0x25,0xBC, //2036
0x0d,0x25,0x4f, //2037
0x0d,0x52,0x44, //2038
0x5d,0xAA,0x38, //2039
0x0B,0x5A,0x4C, //2040
0x05,0x6d,0x41, //2041
0x24,0xAd,0xB6, //2042
0x04,0x9B,0x4A, //2043
0x7A,0x4B,0xBe, //2044
0x0A,0x4B,0x51, //2045
0x0A,0xA5,0x46, //2046
0x5B,0x52,0xBA, //2047
0x06,0xd2,0x4e, //2048
0x0A,0xdA,0x42, //2049
0x35,0x5B,0x37, //2050
0x09,0x37,0x4B, //2051
0x84,0x97,0xC1, //2052
0x04,0x97,0x53, //2053
0x06,0x4B,0x48, //2054
0x66,0xA5,0x3C, //2055
0x0e,0xA5,0x4f, //2056
0x06,0xB2,0x44, //2057
0x4A,0xB6,0x38, //2058
0x0A,0xAe,0x4C, //2059
0x09,0x2e,0x42, //2060
0x3C,0x97,0x35, //2061
0x0C,0x96,0x49, //2062
0x7d,0x4A,0xBd, //2063
0x0d,0x4A,0x51, //2064
0x0d,0xA5,0x45, //2065
0x55,0xAA,0xBA, //2066
0x05,0x6A,0x4e, //2067
0x0A,0x6d,0x43, //2068
0x45,0x2e,0xB7, //2069
0x05,0x2d,0x4B, //2070
0x8A,0x95,0xBf, //2071
0x0A,0x95,0x53, //2072
0x0B,0x4A,0x47, //2073
0x6B,0x55,0x3B, //2074
0x0A,0xd5,0x4f, //2075
0x05,0x5A,0x45, //2076
0x4A,0x5d,0x38, //2077
0x0A,0x5B,0x4C, //2078
0x05,0x2B,0x42, //2079
0x3A,0x93,0xB6, //2080
0x06,0x93,0x49, //2081
0x77,0x29,0xBd, //2082
0x06,0xAA,0x51, //2083
0x0A,0xd5,0x46, //2084
0x54,0xdA,0xBA, //2085
0x04,0xB6,0x4e, //2086
0x0A,0x57,0x43, //2087
0x45,0x27,0x38, //2088
0x0d,0x26,0x4A, //2089
0x8e,0x93,0x3e, //2090
0x0d,0x52,0x52, //2091
0x0d,0xAA,0x47, //2092
0x66,0xB5,0x3B, //2093
0x05,0x6d,0x4f, //2094
0x04,0xAe,0x45, //2095
0x4A,0x4e,0xB9, //2096
0x0A,0x4d,0x4C, //2097
0x0d,0x15,0x41, //2098
0x2d,0x92,0xB5, //2099
};
void WriteDataLCD(unsigned char dat)
{
LCD_RS=1;
LCD_RW=0;
LCD_E=0;
delay(2);
LCD_Data=dat;
delay(2);
LCD_E=1;
delay(5);
LCD_E=0;
delay(5);
}
void WriteCommandLCD(unsigned char udat)
{
LCD_RS=0;
LCD_RW=0;
LCD_E=0;
delay(2);
LCD_Data=udat;
delay(2);
LCD_E=1;
delay(5);
LCD_E=0;
delay(5);}
void LCDInit(void)
{
WriteCommandLCD(0x30);
WriteCommandLCD(0x01);
WriteCommandLCD(0x06);
WriteCommandLCD(0x0C);
}
void LCDClear(void)
{
WriteCommandLCD(0x01);
WriteCommandLCD(0x34);
WriteCommandLCD(0x30);
}
void LCDSendWord(unsigned char *p)
{
while(*p>0)
{
WriteDataLCD(*p);
p++;
}
}
void LCDTestWord(bit i,unsigned char word)
{
if(i==0)
{
WriteCommandLCD(word);
}
else
{
WriteDataLCD(word);
}
}
void DisplayYear(void)
{
year=ReadDs1302(0x8d);
LCDTestWord(0,0x81);
LCDTestWord(1,(year/16)+0x30);
LCDTestWord(1,year%16+0x30);
LCDTestWord(0,0x82);
LCDSendWord("年");
DisplayShengXiao();
}
void DisplayMonth(void)
{
month=ReadDs1302(0x89);
LCDTestWord(0,0x83);
if(month/16!=0)
{
LCDTestWord(1,(month/16)+0x30);
}
else
{
LCDTestWord(1,0x20);
}
LCDTestWord(1,month%16+0x30);
LCDTestWord(0,0x84);
LCDSendWord("月");
DisplayShengXiao();
}
void DisplayWeek(void)
{
week=ReadDs1302(0x8b);
LCDTestWord(0,0x90);
LCDSendWord("星期");
LCDTestWord(0,0x92);
LCDTestWord(1,week+0x30);
if(week==7) {LCDSendWord("日");}
if(week==6) {LCDSendWord("六");}
if(week==5) {LCDSendWord("五");}
if(week==4) {LCDSendWord("四");}
if(week==3) {LCDSendWord("三");}
if(week==2) {LCDSendWord("二");}
if(week==1) {LCDSendWord("一");}
}
void DisplayDay(void)
{
day=ReadDs1302(0x87);
LCDTestWord(0,0x85);
if(day/16!=0)
{LCDTestWord(1,(day/16)+0x30);}
else
{LCDTestWord(1,0x20);}
LCDTestWord(1,day%16+0x30);
LCDTestWord(0,0x86);
LCDSendWord("日");
DisplayShengXiao();
}
void DisplayHour(void)
{
hour=ReadDs1302(0x85);
LCDTestWord(0,0x88);
LCDTestWord(1,(hour/16)+0x30);
LCDTestWord(1,hour%16+0x30);
}
void DisplayMin(void)
{
min=ReadDs1302(0x83);
LCDTestWord(0,0x89);
LCDTestWord(1,0x3a);
LCDSendWord("点");
LCDTestWord(1,(min/16)+0x30);
LCDTestWord(1,min%16+0x30);
LCDSendWord("分");
}
void DisplaySec(void)
{
unsigned char i=0;
unsigned int a=0,b=0,c=0;
sec=ReadDs1302(0x81);
LCDTestWord(0,0x8c);
LCDTestWord(1,(sec/16)+0x30);
LCDTestWord(1,sec%16+0x30);
}
void DisplayTemp(void)
{
unsigned int i;
unsigned char a,b,c;
WriteCommandLCD(0x8c);
LCDTestWord(0,0x8d);
LCDSendWord(" ");
i=GetTemp();
a=i/100;
LCDTestWord(1,a+0x30);
b=i%100/10;
LCDTestWord(1,b+0x30);
LCDTestWord(1,0x2e);
c=i-a*100-b*10;
LCDTestWord(1,c+0x30);
LCDSendWord("C");
}
code unsigned char
DayCode1[9]={0x00,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
code unsigned int
DayCode2[3]={0x111,0x130,0x14e};//计算公历日离当年元旦的天数,为了减少运算,用了两个表DayCode1[9],DayCode2[3]
//如果公历月在九月或前,天数会少于0xff,用表DayCode1[9],在九月后,天数大于0xff,用表DayCode2[3]
//如输入公历日为8月10日,则公历日离元旦天数为DayCode1[8-1]+10-1,如输入公历日为11月10日,则公历日离元旦天数为DayCode2[11-10]+10-1
/*读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0*/
bit GetMoonDay(unsigned char
LunarMonth,unsigned int TableAddr)
{
unsigned char temp;
switch(LunarMonth)
//LunarMonth指向农历月份
{
case 1:
{
temp=YearCode[TableAddr]&0x08;
//1月,对应年份表里第一字节的BIT3位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
//为1,月大
}
case 2:
{
temp=YearCode[TableAddr]&0x04;
//2月,对应年份表里第一字节的BIT2位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
//为0,月小
else return(1);
//为1,月大
}
case 3:
{
temp=YearCode[TableAddr]&0x02; //3月,对应第一字节的BIT1位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);//为0,月小
else return(1);//为1,月大
}
case 4:
{
temp=YearCode[TableAddr]&0x01; //1月,对应第一字节的BIT0位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 5:
{
temp=YearCode[TableAddr+1]&0x80;
//5月,对应第二字节的BIT7位,如果是1,则月大,如果是0,则月小
if(temp==0) return(0);
else return(1);
}
case 6:
{
temp=YearCode[TableAddr+1]&0x40; //6月,对应第二字节的BIT6位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 7:
{
temp=YearCode[TableAddr+1]&0x20; //7月,对应第二字节的BIT5位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 8:
{
temp=YearCode[TableAddr+1]&0x10; //8月,对应第二字节的BIT4位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 9:
{
temp=YearCode[TableAddr+1]&0x08; //9月,对应第二字节的BIT3位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 10:
{
temp=YearCode[TableAddr+1]&0x04;//10月,对应第二字节的BIT2位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 11:
{
temp=YearCode[TableAddr+1]&0x02;//11月,对应第二字节的BIT1位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 12:
{
temp=YearCode[TableAddr+1]&0x01;//12月,对应第二字节的BIT0位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
case 13:
{
temp=YearCode[TableAddr+2]&0x80;//13月,对应第三字节的BIT7位,如果是1,则月大,如果是0,则月小
if(temp==0)return(0);
else return(1);
}
}
return(0);  }
void Conversion(bit cenbit,unsigned char year,unsigned char month,unsigned char day)
{
unsigned char temp1,temp2,temp3,MonthP;//temp3,temp4分别表示春节距元旦的天数,公历日离元旦的天数
unsigned int temp4,TableAddr;
bit flag2,flag_y;
temp1=year/16;//BCD->hex先把数据转换为十六进制高位
temp2=year%16; //低位
year=temp1*10+temp2; //把年数据转换成10进制
temp1=month/16; //月份高位
temp2=month%16; //月份低位
month=temp1*10+temp2; //把月数据转换成10进制
temp1=day/16; //日期高位
temp2=day%16; //日期低位
day=temp1*10+temp2; //把日数据转换成16进制//如果是21世纪
TableAddr=(year+0x64-1)*0x03;//定位数据表地址year对应的年份表中的地址是(year+99)*3如2010年其地址是327
LCDTestWord(0,0x80);
LCDSendWord("20");
temp1=YearCode[TableAddr+2]&0x60;//取当年春节所在的公历月份 年份表中第三字节BIT6-5表示春节的公历月份
temp1=_cror_(temp1,5);//循环右移5位,得到春节所在的公历月份
temp2=YearCode[TableAddr+2]&0x1f;//取当年春节所在的公历日 年份表中第三字节BIT4-0表示当年春节所在的公历日
if(temp1==0x01)//计算当年春年离当年元旦的天数,春节只会在公历1月或2月
temp3=temp2-1;//假如春节在公历1月,则元旦离春节的天数为temp2-1天
else
temp3=temp2+0x1f-1;//假如春节在公历2月,则无理离春节的天数为temp2+0x1f-1天
if(month<10)
temp4=DayCode1[month-1]+day-1;//0到8月某日距元旦的天数
else
temp4=DayCode2[month-10]+day-1;//9月开始的某一天距元旦的天数
if
((month>0x02)&&(year%0x04==0))//如果公历月大于2月并且该年的2月为闰月,天数加1temp4+=1;//计算机出公历日距元旦的天数和春节距元旦的天数,则是为了比较公历日是在春节前还是春节后//如果temp3>temp4 则公历日在春节之前
if(temp4>=temp3)//公历日在春节后或就是春节当日使用下面代码进行运算
{
temp4-=temp3;//公历日离春节的天数因为公历日在春节后所以为temp4-temp3
month=0x01;
MonthP=0x01;//LunarMonth为月份指向,公历日在春节前或就是春节当日LunarMonth指向首月
flag2=GetMoonDay(MonthP,TableAddr);//检查该农历月为大小还是小月,大月返回1,小月返回0
flag_y=0;
if(flag2==0)//GetMoonDay()函数返回的是0
{temp1=0x1d;}//小月29天
else//GetMoonDay()函数返回的是1
{temp1=0x1e;}//大月30天
temp2=YearCode[TableAddr]&0xf0;//年份数据表中第1字节BIT7-4为闰月,为0则这年无闰月,如为1,表示有闰月
temp2=_cror_(temp2,4);//从数据表中取该年的闰月月份,如为0,则该年无闰月BIT3-0表示阴历1到4月的大小1为大0为小
while(temp4>=temp1)
{
temp4-=temp1;
MonthP+=1;
if(month==temp2)
{
flag_y=~flag_y;
if(flag_y==0)
{month+=1;}
}
else
{
month+=1;
}
flag2=GetMoonDay(MonthP,TableAddr);
if(flag2==0)
{
temp1=0x1d;
}
else
{
temp1=0x1e;
}
}
day=temp4+1;
}
else
{
temp3-=temp4;
if
(year==0x00){year=0x63;cenbit=1;}
else year-=1;
TableAddr-=0x03;
month=0x0c;
temp2=YearCode[TableAddr]&0xf0;
temp2=_cror_(temp2,4);
if(temp2==0)MonthP=0x0c;
else MonthP=0x0d;
flag_y=0;
flag2=GetMoonDay(MonthP,TableAddr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
while(temp3>temp1)
{
temp3-=temp1;
MonthP-=1;
if(flag_y==0)month-=1;
if(month==temp2)flag_y=~flag_y;
flag2=GetMoonDay(MonthP,TableAddr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp1-temp3+1;
}
c_moon=cenbit;
temp1=year/10;
temp1=_crol_(temp1,4);
temp2=year%10;
LunarYear=temp1|temp2;
temp1=month/10;
temp1=_crol_(temp1,4);
temp2=month%10;
LunarMonth=temp1|temp2;
temp1=day/10;
temp1=_crol_(temp1,4);
temp2=day%10;
LunarDay=temp1|temp2;
}
void DisplayShengXiao(void)
{
unsigned char LunarYearD,ReYear;
if(cen==0x19) {cenbit=1;}
if(cen==0x20) {cenbit=0;}
Conversion(cenbit,year,month,day);
LCDTestWord(0,0x94);
LCDTestWord(1,LunarYear/16+0x30);
LCDTestWord(1,LunarYear%16+0x30);
//农历年个位
LCDTestWord(1,'-');
//用-隔开
LCDTestWord(1,LunarMonth/16+0x30);
//农历月十位
LCDTestWord(1,LunarMonth%16+0x30);
//农历月个位
LCDTestWord(1,'-');
LCDTestWord(1,LunarDay/16+0x30);
//农历日十位
LCDTestWord(1,LunarDay%16+0x30);
//农历日个位
LunarYearD=(LunarYear/16)*10+LunarYear%16;
switch(ReYear)
{
case 0:
LCDTestWord(0,0x93);LCDSendWord("龙");break;
case 1:
LCDTestWord(0,0x93);LCDSendWord("蛇");break; //蛇年
case 2:
LCDTestWord(0,0x93);LCDSendWord("马");break;
case 3:
LCDTestWord(0,0x93);LCDSendWord("羊");break;
case 4:
LCDTestWord(0,0x93);LCDSendWord("猴");break;
case 5:
LCDTestWord(0,0x93);LCDSendWord("鸡");break;
case 6:
LCDTestWord(0,0x93);LCDSendWord("狗");break;
case 7:
LCDTestWord(0,0x93);LCDSendWord("猪");break;
case 8:
LCDTestWord(0,0x93);LCDSendWord("鼠");break;
case 9:
LCDTestWord(0,0x93);LCDSendWord("牛");break;
case
10:LCDTestWord(0,0x93);LCDSendWord("虎");break;
case
11:LCDTestWord(0,0x93);LCDSendWord("兔");break;
}
}
void Holidays(void)
{
LCDTestWord(0,0x98);
if(next==0){
if(LunarMonth==0x01&&LunarDay==0x01)
{LCDSendWord(" 春节快乐!");}
if(LunarMonth==0x01&&LunarDay==0x15)
{LCDSendWord(" 元宵节快乐!");}
if(LunarMonth==0x04&&LunarDay==0x18)
{LCDSendWord(" 爸爸的生日!");}
if(LunarMonth==0x05&&LunarDay==0x05)
{LCDSendWord(" 端午节快乐!");}
if(LunarMonth==0x07&&LunarDay==0x07)
{LCDSendWord("中国情人节快乐!");}
if(LunarMonth==0x08&&LunarDay==0x15)
{LCDSendWord(" 中秋节快乐!");}
if(LunarMonth==0x08&&LunarDay==0x25)
{LCDSendWord("嘿嘿,我又长大了");}
if(LunarMonth==0x09&&LunarDay==0x09)
{LCDSendWord(" 重阳节快乐!");}
if(LunarMonth==0x09&&LunarDay==0x30)
{LCDSendWord(" 妈妈的生日!");}
if(LunarMonth==0x12&&LunarDay==0x08)
{LCDSendWord(" 腊八节! ");}
if(LunarMonth==0x12&&LunarDay==0x15)
{LCDSendWord(" 过小年啦! ");}
if(LunarMonth==0x12&&LunarDay==0x29)
{LCDSendWord("还有一天新年啦!");}
if(LunarMonth==0x12&&LunarDay==0x30)
{LCDSendWord("今天就到新年夜了");}
//以上是农历节日,以下是公历节日
if(month==0x01&&day==0x01)
{LCDSendWord(" 元旦节快乐!");}
if(month==0x02&&day==0x10)
{LCDSendWord(" 世界气象日!");}
if(month==0x02&&day==0x14)
{LCDSendWord(" 情人节快乐!");}
if(month==0x03&&day==0x12)
{LCDSendWord(" 中国植树节!");}
if(month==0x04&&day==0x01)
{LCDSendWord(" 愚人节快乐!");}
if(month==0x04&&day==0x05)
{LCDSendWord(" 中国清明节!");}
if(month==0x04&&day==0x22)
{LCDSendWord(" 世界地球日!");}
if(month==0x05&&day==0x01)
{LCDSendWord(" 国际劳动节!");}
if(month==0x05&&day==0x04)
{LCDSendWord(" 中国青年节!");}
if(month==0x05&&day==0x12)
{LCDSendWord(" 世界护士节!");}
if(month==0x06&&day==0x01)
{LCDSendWord(" 国际儿童节!");}
if(month==0x06&&day==0x05)
{LCDSendWord(" 世界环境日!");}
if(month==0x06&&day==0x06)
{LCDSendWord(" 国际爱眼日!");}
if(month==0x06&&day==0x25)
{LCDSendWord(" 世界土地日!");}
if(month==0x06&&day==0x26)
{LCDSendWord(" 国际禁毒日!");}
if(month==0x07&&day==0x01)
{LCDSendWord("香港回归纪念日!");}
if(month==0x08&&day==0x01)
{LCDSendWord(" 中国建军节!");}
if(month==0x09&&day==0x10)
{LCDSendWord("中国教师节快乐!");}
if(month==0x09&&day==0x18)
{LCDSendWord("九一八事件纪念日");}
if(month==0x09&&day==0x19)
{LCDSendWord("西北民族大学校庆");}
if(month==0x10&&day==0x01)
{LCDSendWord(" 中国国庆节!");}
if(month==0x10&&day==0x09)
{LCDSendWord(" 世界邮政日!");}
if(month==0x10&&day==0x10)
{LCDSendWord("辛亥革命纪念日!");}
if(month==0x12&&day==0x20)
{LCDSendWord("澳门回归纪念日!");}
if(month==0x12&&day==0x24)
{LCDSendWord(" 平安夜快乐!");}
if(month==0x12&&day==0x25)
{LCDSendWord(" 圣诞节快乐!");}
else
{
if(((temp-0.5)/10)>2&((temp-0.5)/
10)<34){
if(SetKey==1&&SureKey==1&&PlusKey==1&&ReduceKey==1)
{
if((hour/16*10+hour%16)>=6&&(hour/16*
10+hour%16)<22)
{if((hour/16*10+hour%16)>12&&(hour/16
*10+hour%16)<14)
LCDSendWord("午休时间(^@^)~~");
else
LCDSendWord("快乐每一天^_^‘’"); }
if((hour/16*10+hour%16)>21||(hour/16*
10+hour%16)<=5)
LCDSendWord("夜深了注意休息喔");
}
}
if(((temp-0.5)/10)<=2)
LCDSendWord("天气寒冷注意保暖");
else
LCDSendWord("天气炎热注意防暑");
}
}
}
void UpDate(void)
{
DisplayYear();
DisplayMonth();
DisplayDay();
DisplayWeek();
DisplayHour();
DisplayMin();
DisplaySec();
DisplayShengXiao();
}
void Settime(unsigned char count)
{
char address,item;
unsigned char max,mini;
if(count<8){
LCDTestWord(0,0x98);
LCDSendWord("调整");
if(count==7) {LCDSendWord("秒钟请按+-");address=0x81;max=59;mini=0;}
if(count==2) {LCDSendWord("分钟请按+-");address=0x83;max=59;mini=0;}
if(count==1) {LCDSendWord("小时请按+-");address=0x85;max=23;mini=0;}
if(count==5) {LCDSendWord("星期请按+-");address=0x8b;max=7;mini=1;}
if(count==3) {LCDSendWord("日期请按+-");address=0x87;max=31;mini=1;}
if(count==4) {LCDSendWord("月份请按+-");address=0x89;max=12;mini=1;}
if(count==6) {LCDSendWord("年份请按+-");address=0x8d;max=99;mini=0;}
item=ReadDs1302(address);//读取DS1302某地址上的数值赋给item
item=(item/16)*10+item%16;
if(PlusKey==0) //PlusKey-加
{item++;} //数加1
if(ReduceKey==0)//ReduceKey-减
{item--;} //数减1
if(item>max)
item=mini; //查看数值有效范围
if(item<mini)
item=max;
WriteDs1302(0x8e,0x00);
item=(item/10)*16+item%10;
WriteDs1302(address-1,item);//将调整好的item值写入DS1302
UpDate(); }
else{
if(count==8){
LCDTestWord(0,0x01);
WriteCommandLCD(0x0c);
aa=read_24c02add(30);
if(PlusKey==0) //PlusKey-加
aa++; //数加1
if(ReduceKey==0)
//ReduceKey-减
aa--;
write_24c02add(30,aa);
LCDTestWord(0,0x80);
LCDSendWord("请输入温度报警上");
LCDTestWord(0,0x90);
LCDSendWord("限:");
LCDTestWord(0,0x92);
LCDTestWord(1,aa/10+0x30);
LCDTestWord(1,aa%10+0x30);
LCDSendWord("度");
}
if(count==9)
{
bb=read_24c02add(31);
WriteCommandLCD(0x0c);
if(PlusKey==0) //PlusKey-加
bb++; //数加1
if(ReduceKey==0)//ReduceKey-减
bb--;
write_24c02add(31,bb);
LCDTestWord(0,0x88);
LCDSendWord("请输入温度报警下限:");
LCDTestWord(0,0x98);
LCDSendWord("限:");
LCDTestWord(0,0x9a);
LCDTestWord(1,bb/10+0x30);
LCDTestWord(1,bb%10+0x30);
LCDSendWord("度");
}
if(count==10){
cc=read_24c02add(32);
LCDTestWord(0,0x01);
WriteCommandLCD(0x0c);
LCDTestWord(0,0x92);
if(PlusKey==0) //PlusKey-加cc++; //数加1
if(ReduceKey==0)//ReduceKey-减cc--;
write_24c02add(32,cc);
LCDTestWord(0,0x80);
LCDSendWord("请设置闹钟1");
LCDTestWord(0,0x93);
LCDSendWord("点");
LCDTestWord(0,0x95);
LCDSendWord("分");
LCDTestWord(0,0x92);
LCDTestWord(1,cc/10+0x30);
LCDTestWord(1,cc%10+0x30);
LCDTestWord(0,0x94);
LCDTestWord(1,dd/10+0x30);
LCDTestWord(1,dd%10+0x30);
LCDTestWord(0,0x88);
LCDSendWord("闹钟:");
LCDTestWord(0,0x98);
LCDSendWord("设置闹钟小时位");
}
if(count==11)
{ dd=read_24c02add(33);
if(PlusKey==0) //PlusKey-加dd++; //数加1
if(ReduceKey==0)//ReduceKey-减dd--;
write_24c02add(33,dd);
LCDTestWord(0,0x94);
LCDTestWord(1,dd/10+0x30);
LCDTestWord(1,dd%10+0x30);
LCDTestWord(0,0x98);
LCDSendWord("设置闹钟分钟位");
}
if(count==12)
{
LCDTestWord(0,0x98);
LCDSendWord("设置闹钟状态");
if(PlusKey==0) //PlusKey-加mm=1;
if(ReduceKey==0)//ReduceKey-减mm=0;
write_24c02add(34,mm);
if(mm==1)
{LCDTestWord(0,0x8b);LCDSendWord("开");}
if(mm==0)
{LCDTestWord(0,0x8b);LCDSendWord("关");}
}
}
}
void Key(void)
{
if(SetKey==0) //设置时间
{
delay(10); //按键消抖
if(SetKey==0&&w==0) //当是正常状态时就进入调时状态
{
w=1; //进入调时
SetTime(next); //调整
}
if(SetKey==0&&w==1) //当是调时状态本键用于调整下一项
{
next++;
if(next==15) {next=0;WriteCommandLCD(0x0c);}
SetTime(next); //调整
}
while(SetKey==0); //等待键松开
}
switch(next)
{
case 1:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x88);
break;
case 2:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x8a);
break;
case 3:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x85);
break;
case 4:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x83);
break;
case 5:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x92);
break;
case 6:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x81);
break;
case 7:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x8c);
break;
case 8:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x92);
break;
case 9:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x9a);
break;
case 10:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x92);
break;
case 11:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x94);
break;
case 12:
WriteCommandLCD(0x0f);
LCDTestWord(0,0x8b);
break;
}
if(SureKey==0) //当在调时状态时就退出调时
{
delay(10); //按键消抖
if(SureKey==0&&w==1)
{
w=0;
next=0;
Holidays();
}
while(SureKey==0); //等待键松开
}
if(PlusKey==0) //加调整
{
delay(10); //按键消抖
if(PlusKey==0&&w==1)
{
SetTime(next); //调整
}
while(PlusKey==0); //等待键松开
}
if(ReduceKey==0) //减调整
{
delay(10); //按键消抖
if(ReduceKey==0&&w==1)
{
SetTime(next); //调整
}
while(ReduceKey==0); //等待键松开
}
}
void beep()
{int i;
uchar hour1,min1,high,low;
hour1=read_24c02add(32);
min1=read_24c02add(33);
high=read_24c02add(30);
low=read_24c02add(31);
mm=read_24c02add(34);
hour=ReadDs1302(0x85)/16*10+ReadDs1302(0x85)%16;
min=ReadDs1302(0x83)/16*10+ReadDs1302(0x83)%16;
i=GetTemp()/10.0;//tt=1;
if(mm==1)
{
LCDTestWord(0,0x87);WriteDataLCD(
0x0e);WriteDataLCD(0x0e);
}
if(mm==0)
{LCDTestWord(0,0x87);
WriteDataLCD(0x01);WriteDataLCD(0x01);
}
if(((hour>6&&hour<23)&&sec==0&&min==0)
&&mm==1)
{
speak=0;
delay(20);
speak=1;
delay(10);
}
if((hour==hour1&&min==min1)&&mm==1)
{
speak=0;
delay(20);
speak=1;
delay(10);
}
if((i+1>high||i<low)&&mm==1)
{
speak=0;
delay(150);
speak=1;
delay(50);
}
}
void main()
{
SetKey=1;
SureKey=1;
PlusKey=1;
ReduceKey=1;
PSB=1;
next=0;
delayb(100);
LCDInit();
LCDClear();
InitDS1302();
while(1)
{while(!next){
Key();
WriteCommandLCD(0x0c);
DisplayYear(); //显示年
DisplayMonth(); //显示月
DisplayDay(); //显示日
DisplayWeek(); //显示星期
DisplayHour(); //显示时
DisplayMin(); //显示分
DisplaySec(); //显示秒
Holidays(); //显示节日
DisplayTemp(); //显示温度
beep();
}
Key();
}
}

未命名1.jpg
未命名.jpg
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。