DS18B20数字温度采集
/********************************************************************
* 文件名 : 温度采集DS18B20.c
* 描述 : 该文件实现了用温度传感器件DS18B20对温度的采集,并在数码管上显示出来。
* 创建人 : 东流,2012年2月10日
* 版本号 : 2.0
***********************************************************************/
#include
#define uchar unsigned char
#define uint unsigned int
#define jump_ROM 0xCC
#define start 0x44
#define read_EEROM 0xBE
sbit DQ = P2^3; //DS18B20数据口
unsigned char TMPH,TMPL;
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/********************************************************************
* 名称 : delay()
* 功能 : 延时
函
关于工期滞后的函关于工程严重滞后的函关于工程进度滞后的回复函关于征求同志党风廉政意见的函关于征求廉洁自律情况的复函
数
* 输入 : 无
* 输出 : 无
***********************************************************************/
void delay(uint N)
{
int i;
for(i=0; i> i;
temp = temp & 0x01;
write_bit(temp);
delay(5);
}
}
/********************************************************************
* 名称 : Main()
* 功能 : 主函数
* 输入 : 无
* 输出 : 无
***********************************************************************/
void main()
{
uint temp;
P2 = 0x00;
while(1)
{
Reset();
write_byte(jump_ROM);
write_byte(start);
Reset();
write_byte(jump_ROM);
write_byte(read_EEROM);
TMPL = read_byte();
TMPH = read_byte();
temp = TMPL / 16 + TMPH * 16;
P0 = table[temp/10%10];
P2 = 6;
Delay_1ms(5);
P0 = table[temp%10];
P2 = 7;
Delay_1ms(5);
}
}
PAGE
- 43 -