📄 ds18b20.c
字号:
#include <REG52.h>
#include "DS18B20.h"
/*************************************************
/*
/*
/************************************************/
sbit DQ = P2^0; //数据输出口
/*************************************************
/*
/*
/*
/*
/*
/************************************************/
void delay1(int us)
{
int s;
for (s=0; s<us; s++);
}
/**********************************************************
*Header:
*File Name:
*Author:陈培炜,杨帆
*Data;2007
*Function:rest the Ds18b20
*********************************************************/
void rst(void)
{
DQ = 1;
delay1(2);
DQ = 0;
delay1(30); // 精确延时 480~960us //
DQ = 1;
delay1(8);
}
/*************************************************
/*Header:DS18B20.h
/*File Name:DS18B20.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:
/************************************************/
unsigned int read(void)
{
int i = 0;
unsigned int u = 0;
for (i=0; i<16; i++)
{
DQ = 0;
u >>= 1;
DQ = 1;
if (DQ)
{
u |= 0x8000;
}
delay1(4);
}
return (u);
}
/*************************************************
/*Header:DS18B20.h
/*File Name:DS18B20.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:
/************************************************/
void write(unsigned char ku)
{
int i = 0;
for (i=0; i<8 ;i++)
{
DQ = 0;
DQ = ku & 0x01;
delay1(3);
DQ = 1;
ku >>= 1;
}
}
/*************************************************
/*Header:DS18B20.h
/*File Name:DS18B20.c
/*Author: 陈培炜,杨帆
/*Data;2007
/*Function:
/************************************************/
char read0(void)
{
int t1 = 0;
unsigned int tp;
unsigned int lsb;
rst();
write(0xCC);
write(0x44);
rst();
write(0xCC);
write(0xBE);
tp = read();
lsb = (unsigned int)(tp*6.25); //
t1=lsb/100;
return((char)t1);
}
/*************************************************
/*
/*
/************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -