#include"temp.h"
uchar code table_[]={0x00,0x00,0x00,0x00,0x30,0x00,0x48,0x00,0x48,
0x70,0x30,0x88,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x80,
0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //自定义字符:显示℃
uchar HZ[]="温度曲线";
/*******************************************************************************
* 函数名 : Delay1ms
* 函数功能 : 延时函数
* 输入 : 无
* 输出 : 无
*******************************************************************************/
void Delay1ms(unsigned int y)
{
unsigned int x;
for(y;y>0;y--)
for(x=110;x>0;x--);
}
/*******************************************************************************
* 函数名 : Ds18b20Init
* 函数功能 : 初始化
* 输入 : 无
* 输出 : 初始化成功返回1,失败返回0
*******************************************************************************/
unsigned char Ds18b20Init()
{
unsigned int i;
DSPORT=0; //将总线拉低480us~960us
i=70;
while(i--);//延时642us
DSPORT=1; //然后拉高总线,如果DS18B20做出反应会将在15us~60us后总线拉低
i=0;
while(DSPORT) //等待DS18B20拉低总线
{
i++;
if(i>5000)//等待>5MS
return 0;//初始化失败
}
return 1;//初始化成功
}
/*******************************************************************************
* 函数名 : Ds18b20WriteByte
* 函数功能 : 向18B20写入一个字节
* 输入 : com
* 输出 : 无
*******************************************************************************/
void Ds18b20WriteByte(unsigned char dat)
{
unsigned int i,j;
for(j=0;j<8;j++)
{
DSPORT=0; //每写入一位数据之前先把总线拉低1us
i++;
DSPORT=dat&0x01; //然后写入一个数据,从最低位开始
i=6;
while(i--); //延时68us,持续时间最少60us
DSPORT=1; //然后释放总线,至少1us给总线恢复时间才能接着写入第二个数值
dat>>=1;
}
}
/*******************************************************************************
* 函数名 : Ds18b20ReadByte
* 函数功能 : 读取一个字节
* 输入 : com
* 输出 : 无
*******************************************************************************/
unsigned char Ds18b20ReadByte()
{
unsigned char byte,bi;
unsigned int i,j;
for(j=8;j>0;j--)
{
DSPORT=0;//先将总线拉低1us
i++;
DSPORT=1;//然后释放总线
i++;
i++;//延时6us等待数据稳定
bi=DSPORT; //读取数据,从最低位开始读取
/*将byte左移一位,然后与上右移7位后的bi,注意移动之后移掉那位补0。*/
byte=(byte>>1)|(bi<<7);
i=4; //读取完之后等待48us再接着读取下一个数
while(i--);
}
return byte;
}
/*******************************************************************************
* 函数名 : Ds18b20ChangTemp
* 函数功能 : 让18b20开始转换温度
* 输入 : com
* 输出 : 无
*******************************************************************************/
void Ds18b20ChangTemp()
{
Ds18b20Init();
Delay1ms(1);
Ds18b20WriteByte(0xcc); //跳过ROM操作命令
Ds18b20WriteByte(0x44); //温度转换命令
// Delay1ms(100); //等待转换成功,而如果你是一直刷着的话,就不用这个延时了
}
/*******************************************************************************
* 函数名 : Ds18b20ReadTempCom
* 函数功能 : 发送读取温度命令
* 输入 : com
* 输出 : 无
*******************************************************************************/
void Ds18b20ReadTempCom()
{
Ds18b20Init();
Delay1ms(1);
Ds18b20WriteByte(0xcc); //跳过ROM操作命令
Ds18b20WriteByte(0xbe); //发送读取温度命令
}
/*******************************************************************************
* 函数名 : Ds18b20ReadTemp
* 函数功能 : 读取温度
* 输入 : com
* 输出 : 无
*******************************************************************************/
//int Ds18b20ReadTemp()
//{
// int temp=0;
// unsigned char tmh,tml;
// Ds18b20ChangTemp(); //先写入转换命令
// Ds18b20ReadTempCom(); //然后等待转换完后发送读取温度命令
// tml=Ds18b20ReadByte(); //读取温度值共16位,先读低字节
// tmh=Ds18b20ReadByte(); //再读高字节
// temp=tmh;
// temp<<=8;
// temp|=tml;
// return temp;
//}
int Ds18b20ReadTemp()
{
int temp=0;
float tp;
unsigned char tmh,tml;
Ds18b20ChangTemp(); //先写入转换命令
Ds18b20ReadTempCom(); //然后等待转换完后发送读取温度命令
tml=Ds18b20ReadByte(); //读取温度值共16位,先读低字节
tmh=Ds18b20ReadByte(); //再读高字节
temp=tmh;
temp<<=8;
temp |=tml;
if(temp < 0)
{
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
tp=temp;
temp=tp*0.0625*100+0.5;
}
return temp/100;
}
没有合适的资源?快使用搜索试试~ 我知道了~
51单片机课设实验源码-LCD12864液晶显示温度曲线STC51单片机例程源码.zip
共26个文件
h:5个
obj:4个
c:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 165 浏览量
2024-05-24
07:32:16
上传
评论
收藏 60KB ZIP 举报
温馨提示
51单片机课设实验源码-LCD12864液晶显示温度曲线STC51单片机例程源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
51单片机课设实验源码-LCD12864液晶显示温度曲线STC51单片机例程源码.zip (26个子文件)
51单片机课设实验源码-LCD12864液晶显示温度曲线STC51单片机例程源码
LCD12864显示温度曲线(keil4)
test.M51 23KB
test.hex 8KB
12864.LST 8KB
test.uvopt 55KB
test_uvproj.bak 13KB
test.c 1KB
test.plg 664B
12864.c 3KB
temp.h 448B
temp.LST 9KB
test.OBJ 6KB
ds18b20.h 356B
test_uvopt.bak 60KB
bmp.h 4KB
test.LST 3KB
ds18b20.OBJ 4KB
temp.c 5KB
ds18b20.c 1KB
test 19KB
ds18b20.LST 4KB
test.uvproj 13KB
test.lnp 67B
12864.h 528B
temp.OBJ 6KB
12864.OBJ 9KB
STC.h 17KB
共 26 条
- 1
资源评论
GJZGRB
- 粉丝: 1984
- 资源: 7116
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功