#include< reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar time_data[7]={12,1,10,29,19,33,00};
uchar write_add[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
uchar read_add[7]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81} ;
unsigned char code digit[10]={"0123456789"};
void print(uchar *str);
uchar time,num,key;
uchar zhuanhua[14];
sbit DQ =P3^7;
sbit rs=P2^6;
sbit rw=P2^5;
sbit en=P2^7;
sbit clk=P3^6;
sbit io=P3^4;
sbit rst=P3^5;
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
bit w=0;
void write_12864com(uchar com);
void read_12864dat(uchar dat);
void ds1302_byte(uchar dat);
void ds1302_write(uchar add, uchar dat);
uchar ds1302_read(uchar add);
void delay1(uint k)
{
while(k--);
}
void delay(uint t)
{
int i;
while(t--)
{
for(i=0;i<120;i++);
}
}
/*******************************************************************************
************************温度传感器的复位:**************************************
******************** flag=0:表示18b20存在flag=1:表示18b20不存在***************/
bit init18b20(void)
{
bit flag; //储存DS18B20是否存在的标志,flag=0,表示存在;flag=1,表示不存在
DQ = 1; //先将数据线拉高
for(time=0;time<2;time++) //略微延时约6微秒
;
DQ = 0; //再将数据线从高拉低,要求保持480~960us
for(time=0;time<180;time++) //略微延时约600微秒
; //以向DS18B20发出一持续480~960us的低电平复位脉冲
DQ = 1; //释放数据线(将数据线拉高)
for(time=0;time<10;time++)
; //延时约30us(释放总线后需等待15~60us让DS18B20输出存在脉冲)
flag=DQ; //让单片机检测是否输出了存在脉冲(DQ=0表示存在)
for(time=0;time<100;time++) //延时足够长时间,等待存在脉冲输出完毕
;
return (flag); //返回检测成功标志
}
/********************************************************************************
***********************18b20写一个数据***********************************************/
void write18b20(uchar dat)
{
unsigned char i=0;
for (i=0; i<8; i++)
{
DQ =1; // 先将数据线拉高
_nop_(); //等待一个机器周期
DQ=0; //将数据线从高拉低时即启动写时序
DQ=dat&0x01; //利用与运算取出要写的某位二进制数据,
//并将其送到数据线上等待DS18B20采样
for(time=0;time<10;time++)
;//延时约30us,DS18B20在拉低后的约15~60us期间从数据线上采样
DQ=1; //释放数据线
for(time=0;time<1;time++)
;//延时3us,两个写时序间至少需要1us的恢复期
dat>>=1; //将dat中的各二进制位数据右移1位
}
for(time=0;time<4;time++)
; //稍作延时,给硬件一点反应时间
}
uchar read18b20()
{
unsigned char i=0;
unsigned char dat; //储存读出的一个字节数据
for (i=0;i<8;i++)
{
DQ =1; // 先将数据线拉高
_nop_(); //等待一个机器周期
DQ = 0; //单片机从DS18B20读书据时,将数据线从高拉低即启动读时序
dat>>=1;
_nop_(); //等待一个机器周期
DQ = 1; //将数据线"人为"拉高,为单片机检测DS18B20的输出电平作准备
for(time=0;time<2;time++)
; //延时约6us,使主机在15us内采样
if(DQ==1)
dat|=0x80; //如果读到的数据是1,则将1存入dat
else
dat|=0x00;//如果读到的数据是0,则将0存入dat
//将单片机检测到的电平信号DQ存入r
for(time=0;time<8;time++)
; //延时3us,两个读时序之间必须有大于1us的恢复期
}
return(dat); //返回读出的十进制数据
}
void readytemp(void)
{
init18b20(); //将DS18B20初始化
write18b20(0xCC); // 跳过读序号列号的操作
write18b20(0x44); // 启动温度转换
delay(5);
init18b20(); //将DS18B20初始化
write18b20(0xCC); //跳过读序号列号的操作
write18b20(0xBE); //读取温度寄存器,前两个分别是温度的低位和高位
}
void display_temp1(unsigned char x)
{
unsigned char k,l;
k=(x%100)/10; //取十位
l=x%10; //取个位
write_12864com(0x9B); //写显示地址,将在第2行第7列开始显示
read_12864dat(digit[k]); //将十位数字的字符常量写入LCD
read_12864dat (digit[l]); //将个位数字的字符常量写入LCD
print(".") ;
// delay(50); //延时1ms给硬件一点反应时间
}
void display_temp2(unsigned char x)
{
write_12864com(0x9D);
read_12864dat(digit[x]);
print("C");
// delay(50); //延时1ms给硬件一点反应时间
}
void ds1302_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
clk=0;
io=dat&0x01;
dat>>=1;
clk=1;
}
}
void ds1302_write(uchar add,uchar dat)
{
rst=0;
_nop_();
clk=0;
_nop_();
rst=1;
ds1302_byte(add);
ds1302_byte( dat);
rst=0;
io=1;
clk=1;
}
uchar ds1302_read(uchar add)
{
unsigned char i,temp=0x00;
rst=0;
_nop_();
_nop_();
clk=0;
_nop_();
_nop_();
rst=1;
_nop_();
_nop_();
ds1302_byte(add);
for (i=0;i<8;i++) //循环8次 读取数据
{
if(io)
temp|=0x80; //每次传输低字节
clk=0;
temp>>=1; //右移一位
_nop_();
_nop_();
_nop_();
clk=1;
}
rst=0;
_nop_(); //以下为DS1302复位的稳定时间
_nop_();
rst=0;
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
io=0;
_nop_();
_nop_();
io=1;
_nop_();
_nop_();
return (temp);
}
void write_12864com(uchar com)
{
rs=0;
rw=0;
P0=com;
delay(1);
en=1;
delay(3);
en=0;
}
void read_12864dat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay(1);
en=1;
delay(3);
en=0;
}
void set_rtc(void)
{ uchar i,j,k;
for(i=0;i<7;i++)
{
j =time_data/10;
time_data=time_data%10;
time_data=j*16+time_data;
}
ds1302_write(0x8e,0x00); //去除写保护
for(k=0;k<7;k++)
{
ds1302_write(write_add[k],time_data[k]);
}
ds1302_write(0x8e,0x80);
}
void read_rtc(void)
{
uchar i;
for(i=0;i<7;i++)
{
time_data=ds1302_read(read_add);
}
}
void time_pros(void)
{
zhuanhua[0]=time_data[0]/16+0x30;
zhuanhua[1]=time_data[0]%16+0x30;
zhuanhua[2]=time_data[1]/16;
zhuanhua[3]=time_data[1]%16;
zhuanhua[4]=time_data[2]/16+0x30;
zhuanhua[5]=time_data[2]%16+0x30;
zhuanhua[6]=time_data[3]/16+0x30;
zhuanhua[7]=time_data[3]%16+0x30;
zhuanhua[8]=time_data[4]/16+0x30;
zhuanhua[9]=time_data[4]%16+0x30;
zhuanhua[10]=time_data[5]/16+0x30;
zhuanhua[11]=time_data[5]%16+0x30;
zhuanhua[12]=time_data[6]/16+0x30;
zhuanhua[13]=time_data[6]%16+0x30;
}
void init_lcd(void)
{ P0=0xff;
delay1(10);
write_12864com(0x30); //写基本指令集
delay1(1);
write_12864com(0x30);
delay1(1);
write_12864com(0x0c); //显示开
delay1(1);
write_12864com(0x01); //清屏指令
delay1(5);
write_12864com(0x06); //游标右移
//delay1(20);
}
dishanzi(uchar addr,uchar *hz)
{
int i;
//checkbusy();
write_12864com(addr);
for(i=0;hz!='\0';i++)
{
read_12864dat(hz);
// checkbusy();
}
}
void print(uchar *str)
{
while(*str!='\0')
{
read_12864dat(*str);
str++;
}
}
void distime()
{ uchar temp;
dishanzi(0x90,"阳20");
read_12864dat(zhuanhua[0]);
read_12864dat(zhuanhua[1]);
dishanzi(0x93,"年");
read_12864dat(zhuanhua[4]);
read_12864dat(zhuanhua[5]);
dishanzi(0x95,"月");
read_12864dat(zhuanhua[6]);
read_12864dat(zhuanhua[7]);
dishanzi(0x97,"日");
write_12864com(0x88);
read_12864dat(zhuanhua[8]);
read_12864dat(zhuanhua[9]);
dishanzi(0x89,"时");
read_12864dat(zhuanhua[10]);
read_12864dat(zhuanhua[11]);
dishanzi(0x8b,"分");
read_12864dat(zhuanhua[12]);
read_12864dat(zhuanhua[13]);
dishanzi(0x8d,"秒");
dishanzi(0x98,"星期");
temp=zhuanhua[2]*10+zhuanhua[3];
switch(temp)
{
case 1: write_12864com(0x9a) ; print("一"); break;
case 2: write_12864com(0x9a) ; print("二"); break;
case 3: write_12864com(0x9a) ; print("三"); break;
case 4: write_12864com(0x9a) ; print("四"); break;
case 5: write_12864com(0x9a) ; print("五"); break;
case 6: write_12864com(0x9a) ; print("六"); break;
case 7: write_12864com(0x9a) ; print("日"); break;
}
}
/*---------------------------------公历转换阴历年份数据表--------------------------------*/
static unsigned char code year_code[]=
{
0x04,0xAe,0x53, //1901 0
0x0A,0x57,0x48, //1902 3
0x55,0x26,0xBd, //1903 6
0x0d,0x26,0x50, //1904 9
0x0d,0x95,0x44, //1905 12
0x46,0xAA,0xB9, //1906 15
0x05,0x6A,0x4d, //1907 18
0x09,0xAd,0x42, //1908 21
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, //1999 294
0x0C,0x96,0x45, //2000 297
0x4d,0x4A,0xB8, //2001
0x0d,0x4A,0x4C, //2002
0x0d,0xA5,0x41, //2003
0x25,0xAA,0xB6, //2004
0x05,0x6A,0x49, //2005
0x7A,0xAd,0xBd, //2006
0x02,0x5d,0x52, //2007
0x09,0x2d,0x47, //2008
0x5C,0x95,0xBA, //2009
0x0A,0x95,0x4e, //2010
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
};
/*-------------------------------------月份数据表----------------------------------------*/
static unsigned char code day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
static unsigned short code day_code2[3]={0x111,0x130,0x14e};
bit c_moon,century;
data uchar year_moon,month_moon,day_moon,week;
/*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0------------------*/
static unsigned char GetMoonDay(unsigned char month_p,unsigned short table_addr)
{
switch (month_p)
{
case 1:
if((year_code[table_addr]&0x08)==0) return(0);
else return(1);
case 2:
if((year_code[table_addr]&0x04)==0) return(0);
else return(1);
case 3:
if((year_code[table_addr]&0x02)==0) return(0);
else return(1);
case 4:
if((year_code[table_addr]&0x01)==0) return(0);
else return(1);
case 5:
if((year_code[table_addr+1]&0x80)==0) return(0);
else return(1);
case 6:
if((year_code[table_addr+1]&0x40)==0) return(0);
else return(1);
case 7:
if((year_code[table_addr+1]&0x20)==0) return(0);
else return(1);
case 8:
if((year_code[table_addr+1]&0x10)==0) return(0);
else return(1);
case 9:
if((year_code[table_addr+1]&0x08)==0) return(0);
else return(1);
case 10:
if((year_code[table_addr+1]&0x04)==0) return(0);
else return(1);
case 11:
if((year_code[table_addr+1]&0x02)==0) return(0);
else return(1);
case 12:
if((year_code[table_addr+1]&0x01)==0) return(0);
else return(1);
case 13:
if((year_code[table_addr+2]&0x80)==0) return(0);
else return(1);
}
return(0);
}
/*--------------------------------公历转农历函数-----------------------------------------*/
void Conversion(bit c,unsigned char year,unsigned char month,unsigned char day)
{
unsigned char temp1,temp2,temp3,month_p;
unsigned int temp4,table_addr;
bit flag2,flag_y;
temp1=year/16; //BCD->hex 先把数据转换为十六进制
temp2=year%16;
year=temp1*10+temp2;
temp1=month/16;
temp2=month%16;
month=temp1*10+temp2;
temp1=day/16;
temp2=day%16;
day=temp1*10+temp2;
//定位数据表地址
if(c==0) { table_addr=(year+0x64-1)*0x3; }
else { table_addr=(year-1)*0x3; }
//取当年春节所在的公历月份
temp1=year_code[table_addr+2]&0x60;
temp1=_cror_(temp1,5);
//取当年春节所在的公历日
temp2=year_code[table_addr+2]&0x1f;
//取当年春节所在的公历日完成
//计算当年春年离当年元旦的天数,春节只会在公历1月或2月
if(temp1==0x1) { temp3=temp2-1; }
else { temp3=temp2+0x1f-1; }
// 计算当年春年离当年元旦的天数完成
//计算公历日离当年元旦的天数,为了减少运算,用了两个表
//day_code1[9],day_code2[3]
//如果公历月在九月或前,天数会少于0xff,用表day_code1[9],
//在九月后,天数大于0xff,用表day_code2[3]
//如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1
//如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-1
if(month<10) { temp4=day_code1[month-1]+day-1; }
else { temp4=day_code2[month-10]+day-1;}
// if ((month>0x2)&&(year%0x4==0)&&(year!=0)) //此语句造成2000年3月1日—12月31日之间
//计算农历少算一天,应删除判断语句“&&(year!=0)”
if ((month>0x2)&&(year%0x4==0))
temp4+=1; //如果公历月大于2月并且该年的2月为闰月,天数加1
//计算公历日离当年元旦的天数完成
//判断公历日在春节前还是春节后
if (temp4>=temp3)
{
temp4-=temp3; month=0x1;
month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月
flag2=GetMoonDay(month_p,table_addr); //检查该农历月为大小还是小月,大月返回1,小月返回0
flag_y=0;
if(flag2==0)temp1=0x1d; //小月29天
else temp1=0x1e; //大月30天
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月
while(temp4>=temp1)
{
temp4-=temp1; month_p+=1;
if(month==temp2)
{
flag_y=~flag_y;
if(flag_y==0)month+=1;
}
else month+=1;
flag2=GetMoonDay(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp4+1;
}
else
{
temp3-=temp4;
if (year==0x0){year=0x63;c=1;}
else year-=1;
table_addr-=0x3;
month=0xc;
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4);
if (temp2==0)month_p=0xc;
else month_p=0xd;
flag_y=0;
flag2=GetMoonDay(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
while(temp3>temp1)
{
temp3-=temp1;
month_p-=1;
if(flag_y==0)month-=1;
if(month==temp2)flag_y=~flag_y;
flag2=GetMoonDay(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp1-temp3+1;
}
c_moon=c;
year_moon=year;
month_moon=month;
day_moon=day;
dishanzi(0x80,"阴20");
read_12864dat(year_moon/10+0x30);
read_12864dat(year_moon%10+0x30);
dishanzi(0x83,"年");
read_12864dat(month_moon/10+0x30);
read_12864dat(month_moon%10+0x30);
dishanzi(0x85,"月");
read_12864dat(day_moon/10+0x30);
read_12864dat(day_moon%10+0x30);
dishanzi(0x87,"日");
}
void display()
{
uchar nian ,yue ,ri;
nian = ds1302_read(0x8d);
yue = ds1302_read(0x89);
ri = ds1302_read(0x87);
Conversion(0,nian,yue,ri);
}
void keyscan()
{
if(key1==0)
{
delay(1);
if(key1==0)
{
key++;
if(key>=6)
{
key=0;
}
write_12864com(0x9a);
}
while(key1!=0);
}
}
void main(void)
{
uchar TL;
uchar TH;
uchar TD;
uchar TN;
init_lcd();
dishanzi(0x80,"--电子时钟显示--");
dishanzi(0x90,"2012年10月29日制作");
dishanzi(0x88,"--版本:keil4--");
dishanzi(0x98,"----贺暑龙----");
delay(2000);
write_12864com(0x01);
write_12864com(0x03);
delay(500);
//set_rtc();
init18b20();
while(1)
{
if(w==0)
{
read_rtc();
time_pros();
display();
distime();
readytemp();
TL=read18b20(); //先读的是温度值低位
TH=read18b20(); //接着读的是温度值高位
TN=TH*16+TL/16; //实际温度值=(TH*256+TL)/16,即:TH*16+TL/16
//这样得出的是温度的整数部分,小数部分被丢弃了
TD=(TL%16)*10/16;
display_temp1(TN); //显示温度的整数部分
display_temp2(TD); //显示温度的小数部分
}
}
}
求大神指点一下 按键总是调不好
|