标题: 单片机温度动态检测每当温度超出限值时,语音报警一次要怎么弄?程序想不通 [打印本页]

作者: sd244179582    时间: 2019-4-18 14:46
标题: 单片机温度动态检测每当温度超出限值时,语音报警一次要怎么弄?程序想不通
温度动态检测每当温度超出限值时,语音报警一次要怎么弄,程序大概是什么样的 想不通

作者: 郑汉松    时间: 2019-4-18 19:08
我自己写的一个温度报警
#include<reg51.h>
#include<temp.h>
ds18b20readtemp();

static uchar HorS=1;
static float atemp=27.9;
static bit enled=1;

sbit k1=P2^0;
sbit k2=P2^1;
sbit k3=P2^2;
sbit LSA=P2^3;
sbit LSB=P2^4;
sbit LSC=P2^5;
sbit led=P2^6;
sbit zd=P3^2;

uchar codetemp[4];
uchar duanxuan[12]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0xf6};



void delay(uint x)
{
   while(x--);
}

void settemp(int temp)
{
     float tp;
         if(temp<0)
         {       
            codetemp[0]=0x40;
                temp=temp-1;
                temp=~temp;
                led=(enled==1)?(temp>=atemp*16?0:1):1;
                tp=temp;
                tp=(tp*0.0625*(1.8-0.8*HorS)+(32-32*HorS))*10;
                temp=tp;
                codetemp[1]=duanxuan[temp%1000/100];
                codetemp[2]=duanxuan[temp%100/10]|0x80;
                codetemp[3]=duanxuan[temp%10];
         }
         else
         {       
            led=(enled==1)?(temp>=atemp*16?0:1):1;
            tp=temp;
                tp=(tp*0.0625*(1.8-0.8*HorS)+(32-32*HorS))*10;
                temp=tp;
                codetemp[0]=(temp/1000)==0?duanxuan[10]:duanxuan[temp/1000];
                codetemp[1]=duanxuan[temp%1000/100];
                codetemp[2]=duanxuan[temp%100/10]|0x80;
                codetemp[3]=duanxuan[temp%10];
         }
}

void weiandduan()
{
   uchar i;
   for(i=0;i<4;i++)
   {
           switch(i)
          {
            case(0):
                        LSA=0;LSB=0;LSC=0;break;
            case(1):
                        LSA=1;LSB=0;LSC=0;break;
                case(2):
                        LSA=0;LSB=1;LSC=0;break;
                case(3):
                        LSA=1;LSB=1;LSC=0;break;
          }
          P1=codetemp[i];
          delay(100);
          P1=0x00;
   }
}

void changatemp()
{
   uint j;
   uchar i;
   for(j=400;j>0;j--)
{
   int reatemp;
   if(k1==0) {delay(10000);if(k1==0) {atemp=atemp+0.1;j=400;continue;}}
   if(k2==0) {delay(10000);if(k2==0) {atemp=atemp-0.1;j=400;continue;}}
   reatemp=(atemp+0.1)*10;
   codetemp[0]=duanxuan[11];
   codetemp[1]=duanxuan[reatemp%1000/100];
   codetemp[2]=duanxuan[reatemp%100/10]|0x80;
   codetemp[3]=duanxuan[reatemp%10];
   for(i=0;i<4;i++)
   {
           switch(i)
          {
            case(0):
                        LSA=0;LSB=0;LSC=0;break;
            case(1):
                        LSA=1;LSB=0;LSC=0;break;
                case(2):
                        LSA=0;LSB=1;LSC=0;break;
                case(3):
                        LSA=1;LSB=1;LSC=0;break;
          }
          P1=codetemp[i];
          delay(100);
          P1=0x00;
  }  
}
}


void main()
{  
   uchar x=1;
   
   IT0=1;
   EA=1;
   EX0=1;
   
   while(1)
        {

            if(k1==0)
           {
            while(!k1);
            HorS=HorS^x;
       }
       
            if(k2==0)
           {
            while(!k2);
            zd=~zd;
           }
       
       
            settemp(ds18b20readtemp());
            weiandduan();
        }         
}


void zd1() interrupt 0
{
          uchar i;
        uint re;
        enled=0;
        for(i=250;i>0;i--)
        {
          re=(atemp+0.1)*10;
          codetemp[0]=duanxuan[10];
          codetemp[1]=duanxuan[re%1000/100];
          codetemp[2]=duanxuan[re%100/10]|0x80;
          codetemp[3]=duanxuan[re%10];
          weiandduan();

          if(k1==0)
         {
           while(!k1);
           changatemp();
           break;
         }
        }

        enled=1;
        zd=~zd;
}

这是我写的一个温度报警程序,我的是达到报警温度led灯亮,你把LED的输出信号改成语音报警就行了,还有你还要自己创建一个C程序写一个温度测量程序就是这个 接上这个 ds18b20readtemp();

作者: dzbj    时间: 2019-4-18 22:55
低于120度用NTC 高于120用PT100 然后AD采集 自己设定限值 高于就驱动蜂鸣器
作者: DDDDDDDCCC    时间: 2019-4-24 09:43
低于120度可以用NTC 高于120可以用PT100 经过AD采集 可以自己设定限值 高于就驱动蜂鸣器啦




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1