TC77温度读取后怎么转换显示?
时间:10-02
整理:3721RD
点击:
网上的程序,用的是数码管显示,我改 为1602显示就是不出来,是不是主函数那里的温度编码,通过计算求得温度的温度显示错了。
void write_twobyte(uint a) //向TC77写16位数设置TC77工作方式
{
uchar i;
uint k;
k=a;
cs=0;
sck=0;
for(i=0;i<16;i++)
{
k=k<<1;
sda=CY;
sck=1;
delay2(10);
sck=0;
delay2(10);
}
cs=1;
}
uint readtc77(void) //读16位数
{ uchar wendu=0;
uchar i;
sck=0;
cs=0;
for(i=0;i<16;i++)
{
wendu<<=1;
sck=1;
delay2(10);
if(sda==1) wendu=wendu+1;
delay2(10);
sck=0;
}
cs=1;
return wendu;
}
//这部分是读温度函数
//主函数:
void main()
{ float t,tt;
uint temp1,temp2,temp4,temp3;
temp1=0;
temp2=0;
write_twobyte(0x0000);//连续转换模式
LCD_Initial();
GotoXY(0,0); Print("TC77 Test....");
GotoXY(1,0); Print("T= C");
while(1)
{
delay(2000);
temp1=readtc77();
tt=temp1>>3;
t=tt*0.0625;
temp2=t*10+0.5;
temp4=readtc77();
tt=temp4>>3;
t=tt*0.0625;
temp3=t*10+0.5;
if(abs(temp2-temp3)<10)
{
GotoXY(1,3); //lcd1602显示温度
PutCh((temp2/1000)%10+'0');
PutCh((temp2/100)%10+'0');
PutCh(temp2/10%10+'0');
PutCh(temp2%10+'0');
delay(2000);
}
delay(2000);
}
}
void write_twobyte(uint a) //向TC77写16位数设置TC77工作方式
{
uchar i;
uint k;
k=a;
cs=0;
sck=0;
for(i=0;i<16;i++)
{
k=k<<1;
sda=CY;
sck=1;
delay2(10);
sck=0;
delay2(10);
}
cs=1;
}
uint readtc77(void) //读16位数
{ uchar wendu=0;
uchar i;
sck=0;
cs=0;
for(i=0;i<16;i++)
{
wendu<<=1;
sck=1;
delay2(10);
if(sda==1) wendu=wendu+1;
delay2(10);
sck=0;
}
cs=1;
return wendu;
}
//这部分是读温度函数
//主函数:
void main()
{ float t,tt;
uint temp1,temp2,temp4,temp3;
temp1=0;
temp2=0;
write_twobyte(0x0000);//连续转换模式
LCD_Initial();
GotoXY(0,0); Print("TC77 Test....");
GotoXY(1,0); Print("T= C");
while(1)
{
delay(2000);
temp1=readtc77();
tt=temp1>>3;
t=tt*0.0625;
temp2=t*10+0.5;
temp4=readtc77();
tt=temp4>>3;
t=tt*0.0625;
temp3=t*10+0.5;
if(abs(temp2-temp3)<10)
{
GotoXY(1,3); //lcd1602显示温度
PutCh((temp2/1000)%10+'0');
PutCh((temp2/100)%10+'0');
PutCh(temp2/10%10+'0');
PutCh(temp2%10+'0');
delay(2000);
}
delay(2000);
}
}
lcd显示部分应该没错的,我是从热电偶温度传感器那里copy过来的。
注意单位 uchar wendu=0; uchar 改为uint
好的,谢谢我试试
网上说TC77读的温度编码,主函数while那里的程序是转化为十进制吗?看不太懂。
我也不清楚,我没用过这个TC77,t=tt*0.0625;这个是什么意思?
TC77资料上的温度输出编码,我也不太懂,谢谢啦,找机会问问老师
我慢慢看资料改程序吧
成功了!就把主函数0x0000改为0xffff就得了Orz
寄存器整整
其实小编写入0xffff虽然能用但是还是不对,只不过使用上电默认值,正确的应该先输入2字节的脉冲,也就是先读,然后接下来的2字节才是要写入的数据,一共32个脉冲
我的也是写入0xffff可以用,但是0x0000就不行。我是先读取16位,在写入啊