标题: 基于ds18b20的温度检测 [打印本页]

作者: Scien    时间: 2019-12-6 21:55
标题: 基于ds18b20的温度检测
部分代码:
#include <reg51.h>

#define uchar unsigned char
#define uint unsigned int

//--定义使用的IO口--//
#define GPIO_DIG   P1        //段选
#define GPIO_PLACE P2        //位选

sbit K1=P3^6;
sbit K2=P3^7;

sbit DS=P3^0;           //define interface
signed long int temp;             // variable of temperature

uchar state=0;

unsigned char code DIG_PLACE[8] = {
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位选控制   查表的方法控制
unsigned char code DIG_CODE[] = {
                                0xFC,  //"0"
                0x60,  //"1"
                0xDA,  //"2"
                0xF2,  //"3"
                0x66,  //"4"
                0xB6,  //"5"
                0xBE,  //"6"
                0xE0,  //"7"
                0xFE,  //"8"
                0xF6,  //"9"
                0xEE,  //"A"
                0x3E,  //"B"
                0x9C,  //"C"
                0x7A,  //"D"
                0x9E,  //"E"
                0x8E,  //"F"
                0x6E,  //"H"
                0x1C,  //"L"
                0xEC,  //"n"
                0x7C,  //"u"
                0xCE,  //"P"
                0x3A,  //"o"
                0x02,  //"-"
                0x00,  //熄灭
                0x00  //自定义
                         };
unsigned char DisplayData[8];
//用来存放要显示的8位数的值


void delay(uint count)      //delay
{
  uint i;
  while(count)
  {
    i=200;
    while(i>0)
    i--;
    count--;
  }
}
void dsreset(void)       //send reset and initialization command
{
  uint i;
  DS=0;
  i=103;
  while(i>0)i--;
  DS=1;
  i=4;
  while(i>0)i--;
}


1.jpg (87.03 KB, 下载次数: 36)

1.jpg

ds18b20.zip

74.06 KB, 下载次数: 21, 下载积分: 黑币 -5






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1