No.22433 作者:sifan1157 邮件:xingweijun123@126.com ID:100865 登陆:2次 文章数:18篇 最后登陆IP:222.178.56.73 最后登陆:2008/3/13 22:35:55 注册:2008/2/25 16:57:25 财富:101 发帖时间:2008/2/25 17:33:53 发贴者IP:123.147.0.126 标题:sifan1157:温度传感器 源程序 摘要:No.22433温度传感器 源程序 /************************************************************************************ * Copyright (c) 2007,重庆优易特电子 * All rights reserved. * * 文件名称: DS18B20.c * 文件标识: none * 适用器件: STC89C51RC * * 摘 要: ds18b20的应用 * * 当前版本:1.0 * 作 者:行卫军 * 完成日期:2007年12月10日 * *************************************************************************************/ #include <reg51.h> unsigned char code segtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f, 0x6f,0x63,0x39}; unsigned char disp_buf[]={0,0,0,0}; unsigned char code ledbit[]={0xfe,0xfd,0xfb,0xf7}; unsigned char ledno=0,ms5; unsigned char temperature=25;//温度值 sbit DQ =P3^3; //定义通信端口 void delay(unsigned int i) { while(i--); } //初始化函数 Init_DS18B20(void) { unsigned char x=0; DQ = 1; //DQ复位 delay(8); //稍做延时 DQ = 0; //单片机将DQ拉低 delay(80); //精确延时 大于 480us DQ = 1; //拉高总线 delay(14); x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败 delay(20); } //读一个字节 ReadOneChar(void) { unsigned char i=0; unsigned char dat = 0; for (i=8;i> 0;i--) { DQ = 0; // 给脉冲信号 dat> > =1; DQ = 1; // 给脉冲信号 if(DQ) dat|=0x80; delay(4); } return(dat); } //写一 ......
>>返回讨论的主题
|