📄 temperread.c
字号:
#include "temperread.h"
#include "hardware.h"
//*******************************
// CRC校验
//*******************************
/*uint8 crccheck(uint8 *p,uint8 len)
{
uint8 bit0,cbit,r,temp,i,j,byte;
temp=0;
for(j=0;j<len;j++)
{
byte=p[j];
for(i=0;i<8;i++)
{
cbit=temp&0x01;
bit0=byte&0x01;
temp=temp>>1;
r=cbit^bit0;
if(r==1)
temp=temp^0x8c;
byte=byte>>1;
}
}
return temp;
}
*/
//*******************************
// 匹配ds18b20
//*******************************
void ds18b20_match(uint8 *p)
{
uint8 i;
do
i=ds18b20_ack();
while(i==0x01);
ds18b20_write(0x55);
for(i=0;i<8;i++)
ds18b20_write(p[i]);
}
//*******************************
// 读取ds18b20温度数据
//*******************************
void TMread()
{
uint8 ds18b20[9]; //ds18b20数据
uint8 i;
uint16 ds18b20_temp;
uint8 temp;
ds18b20_match(ROM_CODE);
ds18b20_write(0x44); //开始转换
DelayMs(800); //等待转换结束
// Is_ds18b20_done();
ds18b20_match(ROM_CODE);
ds18b20_write(0xbe); //读取转换后数据
for(i=0;i<9;i++) //存储位置待定
ds18b20[i]=ds18b20_read();
ds18b20_temp=ds18b20[1]; //存储位置待定
ds18b20_temp=ds18b20_temp<<8;
ds18b20_temp+=ds18b20[0]; //存储位置待定
if((ds18b20_temp&0xf800)!=0)
{
ds18b20_temp=0-ds18b20_temp;
FRAME_BUF[1][5]='-'; //在buf中的位置待定
}
else
FRAME_BUF[1][5]='+'; //在buf中的位置待定
temp=ds18b20_temp/16; //温度数据转换
for(i=0;i<3;i++)
{
FRAME_BUF[1][8-i]=ASCIItab[temp%10];
temp=temp/10;
}
// FRAME_BUF[1][]='.';
temp=ds18b20_temp%16;
temp=temp*10;
FRAME_BUF[1][10]=ASCIItab[temp/16];//存储位置待定
FRAME_BUF[1][11]=0xdf; //存储位置待定
FRAME_BUF[1][12]='C'; //存储位置待定
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -