STC89C52单片机数字温度传感器设计 (温度传感器是DS18B20) 寻高手帮在C语言程序中加个报警程序。急需。

因为是期末大作业。所以望在这一周周末前可以搞定!!谢谢。。。谢谢了
答案发邮箱 [email protected]
STC89C52单片机设计温度传感器(用数码管显示温度) 在如下C语言程序中。加个温度报警程序,温度报警范围是25~30℃

或者你也可以自己设计 适合 STC89C52单片机 的 数字温度传感器 C语言程序 和
Protues仿真。最好有PPT说明和WORD说明
如果答案正确。设置合理。再加20分!!!!!悬赏80。。。总悬赏100分!!万分感谢。。。急急急如意令!!!!!!!!!!!

Protues仿真,C语言程序 所用 软件 见截图

#include <reg51.h>

sbit DQ=P3^2;
sbit BEEP=P1^5;

unsigned char presence;

unsigned char code LEDData[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};
unsigned char data temp_data[2]={0x00,0x00};
unsigned char data display[5]={0x00,0x00,0x00,0x00,0x00};
unsigned char code ditab[16]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};

void beep();
sbit DIN=P0^7;
bit flash=0;

void Delay(unsigned int num)
{
while (--num);
}

Init_DS18B20(void)
{
DQ=1;
Delay(8);

DQ=0;
Delay(90);

DQ=1;
Delay(8);

presence=DQ;
Delay(100);
DQ=1;

return(presence);
}

ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat=0;

for (i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;

if(DQ)
dat |=0x80;
Delay(4);
}
return(dat);
}

WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for (i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
Delay(5);

DQ=1;
dat>>=1;
}
}

Read_Temperature(void)
{
Init_DS18B20();
if(presence==1)
{ beep();flash=1;}
else
{
flash=0;
WriteOneChar(0xCC);
WriteOneChar(0x44);

Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0xBE);

temp_data[0]=ReadOneChar();
temp_data[1]=ReadOneChar();
}
}

Disp_Temperature()
{
unsigned char n=0;

display[4]=temp_data[0]&0x0f;
display[0]=ditab[display[4]];

display[4]=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x0f)<<4);
display[3]=display[4]/100;
display[1]=display[4]%100;
display[2]=display[1]/10;
display[1]=display[1]%10;

if(!display[3])
{
display[3]=0x0a;
if(!display[2])
display[2]=0x0a;
}

P0=0xc6;
P2=0x7f;
Delay(300);

P0=0x9c;
P2=0xbf;
Delay(300);

P0=LEDData[display[0]];
P2=0xdf;
Delay(300);

P0=LEDData[display[1]];
DIN=0;
P2=0xef;
Delay(300);

P0=LEDData[display[2]];
P2=0xf7;
Delay(300);

P0=LEDData[display[3]];
P2=0xfb;
Delay(300);

P2=0xff;
}

void beep()
{
unsigned char i;
for(i=0;i<100;i++)
{
Delay(60);
BEEP=!BEEP;
}
BEEP=1;
}

void main(void)
{
while(1)
{
Read_Temperature();
if(flash==0)
{
Disp_Temperature();
}
else P2= 0xff;
}
}
软件截图

第1个回答  2012-05-23
额,如果你要用STC89C52单片机,你的代码第一行应该是
#include <reg52.h>追问

通过实验验证.用STC89C52单片机..第一行代码是#include 或者#include 都可以的仿真.做程序项目的.哎...关键是我这问题你能帮回答下吗??谢谢.急求帮助...板子是4个数码管

第2个回答  2012-05-25
The temperature data is stored as a 16-bit sign-extended
two’s complement number in the temperature register (see Figure 2). The sign bits (S) indicate if the
temperature is positive or negative: for positive numbers S = 0 and for negative numbers S = 1. If the
DS18B20 is configured for 12-bit resolution, all bits in the temperature register will contain valid data.
For 11-bit resolution, bit 0 is undefined. For 10-bit resolution, bits 1 and 0 are undefined, and for 9-bit
resolution bits 2, 1, and 0 are undefined. Table 1 gives examples of digital output data and the
corresponding temperature reading for 12-bit resolution conversions.
温度信息存放于16位扩展寄存器中,符号(S)表示温度的正负,温度为正数S = 0,温度为负数S=1。
当ds18B20配置12位精度时寄存器所有值有效,
当11位精度 时寄存器0位不用
当10位精度 时寄存器0,1位不用
当10位精度 时寄存器0,1,2位不用
表一给出温度与传感器输出值的对照
翻译的不好的地方请指正
第3个回答  2012-05-24
我有做过这个,你把邮箱留下,我发给你。程序加PROTEUS的图追问

我的邮箱[email protected]。。。问题里面有说过的啊

追答

哦,程序已经发送,就是你要把TXT的用KEIL编译下,不过我警戒温度是60度,你要改下

追问

兄弟。。。。我做的是数字温度传感器。。。是4个数码管显示温度的。。不是你程序中用的LM016L液晶屏显示温度啊。。。。。⊙﹏⊙b汗。。。可愁死了。。。

追答

。。。4位数码管应该没有LCD1602难吧

追问

确实没有。。可我就是一点不会。。。。哎。。。。今天老师要我们交大作业了。。。。晕啊。。。

本回答被提问者采纳
相似回答