温度采集报警系统C语言程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void delay4(uchar count)
{
while(count>0) count--;
}
void reset4(void) //send reset and initialization command
{
DS4=0;
delay4(100); DS4=1;
delay4(4);
delay4(200);
temp4=tt*10+0.5;
return temp4
}
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^0;
sbit lcden=P2^2;
#define lcd_mode 0x38
#define display_cursor 0x0f
{ write_date(*p); delay(20); p++;
} } //******************************************************** void gotoxy(uchar x,uchar y) { if(x==1) write_com(0x80+y); else write_com(0xc0+y); } //******************************************************** void display_data(char number) {
}
bit read_bit2(void) //read a bit
{
bit temp;
DS2=0;
_nop_();
DS2=1;
_nop_();
temp=DS2;
delay2(200);
return temp;
}
uchar read_byte2(void) //read a byte date
{
uchar i,byte=0;
{
uchar i,byte=0;
bit j;
for(i=0;i<8;i++)
{
byte=_cror_(byte ,1);
j=read_bit();
if(j==0) byte=byte|0x00;
else byte=byte|0x80;
}
return byte;
}
void write_byte(uchar command) //write a byte to ds18b20
#define undisplay_cursor 0x0c
char code int_to_char[]="0123456789";
//********************************************************
void delay(uint x)
{
uint a,b; for(a=x;a>0;a--) for(b=10;b>0;b--);
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uint temp4;
// variable of temperature
sbit DS4=P1^3; //define interface
{
reset2();
write_byte2(0xcc); //直接向 18b20 发送温度变换命令
write_byte2(0x44); //启动 18b20 进行温度转换 }
uint tmp2()
//get the temperature
{
float tt;
uchar a,b;
reset2();
write_byte2(0xcc); //直接向 18b20 发送温度变换命令
}
//********************************************************
void write_com(uchar com) //写命令
{
P0=com;
rs=0;
lcden=0;
Βιβλιοθήκη Baidu
delay(10);
lcden=1;
delay(10); lcden=0; } //******************************************************** void write_date(uchar date) //写数据
write_byte2(0xbe); //读取温度寄存器的温度值
a=read_byte2();//读低八位
b=read_byte2();//读高八位
temp2=b;
temp2<<=8; //two byte compose a int variable
temp2=temp2|a;
tt=temp2*0.0625;
{
reset4();
write_byte4(0xcc); //直接向 18b20 发送温度变换命令
write_byte4(0x44); //启动 18b20 进行温度转换
}
uint tmp4()
//get the temperature
{
float tt;
uchar a,b;
reset4();
write_byte4(0xcc); //直接向 18b20 发送温度变换命令
{
uchar i;
for(i=0;i<8;i++)
{
if((command & 0x01)==0)
{
DS2=0;
delay2(8);
DS2=1;
_nop_(); }
else
{
DS2=0;
_nop_();
DS2=1;
delay2(8);
}
command=_cror_(command,1);
}
}
void tmpchange2(void) //DS18B20 begin change
{
reset();
write_byte(0xcc); //直接向 18b20 发送温度变换命令
write_byte(0x44); //启动 18b20 进行温度转换
}
uint tmp()
//get the temperature
{
float tt;
uchar a,b;
reset();
write_byte(0xcc); //直接向 18b20 发送温度变换命令
{
uchar i;
for(i=0;i<8;i++) {
if((command & 0x01)==0)
{
DS4=0;
delay4(8);
DS4=1;
_nop_();
}
Else
{
DS4=0;
_nop_();
DS4=1;
delay4(8);
}
command=_cror_(command,1);
}
}
void tmpchange4(void) //DS18B20 begin change
{
DS=0;
delay1(100);
DS=1;
delay1(4);
delay1(200);
}
bit read_bit(void) //read a bit
{
bit temp;
DS=0;
_nop_();
DS=1;
_nop_();
temp=DS;
delay1(200);
return temp;
}
uchar read_byte(void) //read a byte date
{ P0=date; rs=1; lcden=0; delay(10); lcden=1; delay(10); lcden=0; } //******************************************************** void init_lcd(void) //初始化 lcd1602
bit j;
for(i=0;i<8;i++)
{
byte=_cror_(byte ,1);
j=read_bit2();
if(j==0) byte=byte|0x00;
else byte=byte|0x80;
}
return byte;
}
void write_byte2(uchar command) //write a byte to ds18b20
bit j;
for(i=0;i<8;i++)
{
byte=_cror_(byte ,1);
j=read_bit4();
if(j==0) byte=byte|0x00;
else byte=byte|0x80;
}
return byte;
}
void write_byte4(uchar command) //write a byte to ds18b20
return temp;
}
#include <reg52.h> #include <intrins.h>
#define uchar unsigned char #define uint unsigned int
uint temp2;
// variable of temperature
sbit DS2=P1^1; //define interface
uchar x,y; x=number/10; y=number%10;//y=number-10*x; write_date(int_to_char[x]); write_date(int_to_char[y]); }
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
write_byte(0xbe); //读取温度寄存器的温度值
a=read_byte();//读低八位
b=read_byte();//读高八位
temp=b;
temp<<=8; //two byte compose a int variable
temp=temp|a;
tt=temp*0.0625;
temp=tt*10+0.5;
temp2=tt*10+0.5;
return temp2
}
#include <reg52.h>
{ delay(15); write_com(lcd_mode); delay(20); write_com(undisplay_cursor); delay(20); write_com(0x06); //let cursor move delay(20); write_com(0x01); //clear lcd delay(20); } //******************************************************** void display_string(char *p) //写字符串 { while(*p)
{
uchar i;
for(i=0;i<8;i++)
{
if((command & 0x01)==0)
{
DS=0;
delay1(8);
DS=1;
_nop_();
}
else
{
DS=0;
_nop_();
DS=1;
delay1(8);
}
command=_cror_(command,1);
}
}
void tmpchange(void) //DS18B20 begin change
#define uint unsigned int
uint temp;
// variable of temperature
sbit DS=P1^0;
//define interface
void delay1(uchar count)
{
while(count>0) count--;
}
void reset(void) //send reset and initialization command
}
bit read_bit4(void) //read a bit
bit temp;
DS4=0;
_nop_();
DS4=1;
_nop_();
temp=DS4;
delay4(200);
return temp;
}
uchar read_byte4(void) //read a byte date
{
uchar i,byte=0;
void delay2(uchar count)
{
while(count>0) count--;
}
void reset2(void) //send reset and initialization command
{
DS2=0;
delay2(100);
DS2=1;
delay2(4);
delay2(200);
write_byte4(0xbe); //读取温度寄存器的温度值
a=read_byte4();//读低八位
b=read_byte4();//读高八位
temp4=b;
temp4<<=8; //two byte compose a int variable
temp4=temp4|a;
tt=temp4*0.0625;