求解单片机控制TFT屏,无法显示温度数据的问题

1、温度测试程序在1602屏显示项目上能正确显示检测的温度值;
2、将上述程序的temp.c和temp.h文件加入到TFT屏显示项目中,
keil4编译无警告错误,温度值只能显示0.06;
3、温度接口未变动,TFT屏能正确显示字符、字符串和汉字;
void DisTemp(int temp)
{
un8 datas[] = {0, 0, 0, 0, 0}; //定义数组
float tp;
if(temp< 0) //当温度值为负数
{
DispChar1016('-',50,120,YELLOW, BLUE);
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
DispChar1016('+',50,120,YELLOW, BLUE);
tp=temp;
temp=tp*0.0625*100+0.5;
}
datas[0]=temp/10000%10 +'0';
datas[1]=temp/1000%10 +'0';
datas[2]=temp/100%10 +'0';
datas[3]=temp/10%10 +'0';
datas[4]=temp%10 +'0';
DispChar1016(datas[0], 100, 120, YELLOW, BLUE);
DispChar1016(datas[1], 110, 120, YELLOW, BLUE);
DispChar1016(datas[2], 120, 120, YELLOW, BLUE);
DispChar1016(datas[3], 130, 120, YELLOW, BLUE);
DispChar1016(datas[4], 140, 120, YELLOW, BLUE);

void main ()
{
TFT_Init(); //初始化TFT
ClearScreen(BLACK); //清屏黑色
DS18B20Init();
while(1)
{DisTemp(DS18B20ReadTemp());}
}
int DS18B20ReadTemp()
{
int temp=0;
un8 tmh,tml;
DS18B20ChangTemp(); //先写入转换命令
DS18B20ReadTempCom(); //然后等待转换完后发送读取温度命令
tml=DS18B20ReadByte(); //读取温度值共16位,先读低字节
tmh=DS18B20ReadByte(); //再读高字节
temp=tmh;
temp<<=8;
temp|=tml;
return temp;
}
main.c包含了temp.h、tff.h、gui.h三个文件。DispChar1016()点阵是8*16,Ascii[96][16]
TFT屏能正确显示8*16字符、字符串和16*16汉字

第1个回答  2014-10-10
温度值显示0.06;一直不变吗?

这个DS18B20ReadTemp());函数检查过没?正确吗?追问

DS18B20ReadTemp());这个函数现成的,我按原LCD1602显示程序移植过来的,并修改成TFT屏下面的代码和+ -符号代码,其他的未动。

追答

无论外部温度怎样变化, 温度值显示0.06一直不变吗?
我的推测是:DS18B20ReadTemp());出错

追问

ReadTemp()这个函数是在temp.c文件里,程序全移植,1602能正确显示

DS18B20检测到的温度值。如果该函数有错误,1602同样不能正常显示。谢谢

追答

DispChar1016();是正确的吗?

相似回答