|
把时间 初始化函数 和 读时间函数 注释掉,才可正常显示温度
我全部取消掉注释的话,时间时可以正常走,但是温度显示为00.0°C
下面时相对应的一些函数
void Ds1302Init() //时间初始化
{
uchar n;
Ds1302Write(0x8E,0x00); //关闭写保护功
for (n=0; n<7; n++)//写入7个字节的时钟信号:分秒时日月周年
{
Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]);
}
Ds1302Write(0x8E,0x80); //打开写保护
}
void Ds1302ReadTime() //读时间
{
uchar n;
for (n=0; n<7; n++)//读取7个字节的时钟信号:分秒时日月周年
{
TIME[n] = Ds1302Read(READ_RTC_ADDR[n]);
}
}
void get_temp()
{
init_temp();
write_temp(0xcc); //跳过ROM
write_temp(0x44); //温度转换
delay1(1000); //等待转换1000毫秒
init_temp();
write_temp(0xcc); //跳过ROM
write_temp(0xbe); //读RAM内容
low=read_temp(); //低8位
high=read_temp(); //高8位
temp=high;
temp<<=8;
temp=temp|low; //合并
temp=temp*10*0.0625+0.5; //转换
s[0]=temp/100; //十位
s[1]=temp%100/10; //个位
s[2]=temp%10; //小数
}

|
|