51单片机ds18b20.h文件程序
时间: 2023-12-23 13:04:37 浏览: 172
以下是51单片机DS18B20温度传感器的头文件ds18b20.h程序示例:
```c
#ifndef __DS18B20_H__
#define __DS18B20_H__
#include <reg52.h>
#include <intrins.h>
// DS18B20数据线
#define DSPORT P2_7
// DS18B20指令
#define DSCMD_CONVERT 0x44 // 启动转换指令
#define DSCMD_READSCRATCH 0xBE // 读暂存器指令
// DS18B20温度值
extern int temperature;
// DS18B20初始化
void DS18B20_Init();
// 发送一个复位脉冲
unsigned char DS18B20_Reset();
// 发送一个字节
void DS18B20_WriteByte(unsigned char dat);
// 读取一个字节
unsigned char DS18B20_ReadByte();
// 读取温度值
void DS18B20_GetTemperature();
#endif
```
这个头文件包含了DS18B20的初始化函数、复位函数、发送字节函数、读取字节函数和读取温度值函数。你可以根据自己的需要在程序中使用这些函数。需要注意的是,在使用这个头文件之前,你需要先定义P2.7为数据线。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)