標(biāo)題: 基于單片機(jī)壓力傳感器MPX4115檢測(cè)-報(bào)警系統(tǒng)proteus仿真+源程序 [打印本頁]

作者: bbxyliyang    時(shí)間: 2023-11-25 20:08
標(biāo)題: 基于單片機(jī)壓力傳感器MPX4115檢測(cè)-報(bào)警系統(tǒng)proteus仿真+源程序
一、系統(tǒng)方案
1、本設(shè)計(jì)采用這51單片機(jī)作為主控器。
2、MPX4115采集壓力值、DS18B20采集溫度值送到液晶1602顯示。
3、按鍵設(shè)置報(bào)警值。
4、蜂鳴器報(bào)警。


二、硬件設(shè)計(jì)
原理圖如下:

三、單片機(jī)軟件設(shè)計(jì)
1、首先是系統(tǒng)初始化
/*******************************************************************
                  液晶初始化
************************************************************************/
void chushihua()
{
  delayxms(20); //給液晶一段時(shí)間
  en=0;
  xiemingling(0x38);//設(shè)置16*2顯示,5*7點(diǎn)陣,8位數(shù)據(jù)接口
  delayxms(20);
  xiemingling(0x38);//
  delayxms(20);
  xiemingling(0x0c);//設(shè)置開顯示,不顯示光標(biāo)
  delayxms(20);
  xiemingling(0x06);//寫一個(gè)字符后地址指針加1
  delayxms(20);
  xiemingling(0x01);//顯示清零,數(shù)據(jù)指針清零
  delayxms(20);
  xiemingling(0x80);//指定字符顯示的實(shí)際地址,,,顯示位置的確定方法規(guī)定為"80H+地址碼x"
  delayxms(20);
}
2、液晶顯示程序
//**************毫秒*******************
void delayxms(uint ms)                                           //延時(shí) x  ms
{
    uint a,j;
    for(a=0;a<ms;a++)
          for(j=0;j<110;j++);
}
/*******************************************************************
                  寫命令
************************************************************************/
void xiemingling(unsigned char mingling)
{
  en=0;
  rs=0;
  rw=0;
  P0=mingling;
  delayxms(5);
  en=1;
  delayxms(10);
  en=0;
}
/*******************************************************************
                  寫數(shù)據(jù)
************************************************************************/
void xieshuju(unsigned char shuju)
{   
  en=0;
  rs=1;
  rw=0;
  P0=shuju;
  delayxms(5);
  en=1;
  delayxms(10);
  en=0;
}
3、按鍵程序
/*********************************************************/
// 按鍵掃描
/*********************************************************/
void key()
{
        if(key5==0)
        {
                delay(10);
                if(key5==0)
                {
                        while(!key5);
                        c1=c;
                        temp1=temp;
           
    }
        }      
                if(key6==0)
        {
                delay(10);
                if(key6==0)
                {
                        while(!key6);
            mode=!mode;
                        chushihua(); //LCD1602初始化
    }
        }      
      
      
        if(key1==0)
        {
                delay(10);
                if(key1==0)
                {
                        while(!key1);
              h++;
                          if(h>1000) h=1000;
    }
        }      
      
        if(key2==0)
        {
                delay(10);
                if(key2==0)
                {
                        while(!key2);
                        if(h>=1) h--;
               
    }
        }      
        if(key3==0)
        {
                delay(10);
                if(key3==0)
                {
                        while(!key3);
              l++;
                          if(l>1000) l=1000;
    }
        }      
      
        if(key4==0)
        {
                delay(10);
                if(key4==0)
                {
                        while(!key4);
                        if(l>=1) l--;
               
    }
        }      
      
}
4、核心算法程序
void main(void)
{
         
          chushihua(); //LCD1602初始化
               
  while(1)
  {         
             key();         
          getdata=Adc0832(0);
                check_wendu();
          if(0<getdata<243)                                 
                {                           
                  int vary=getdata;                                                      
                        press=((10.0/23.0)*vary)+9.3;                                                                                                                          
                        temp=(int)(press*10);               
                                                                                 
                        dispbuf[3]=temp/1000;                                     //取壓力值百位
                        dispbuf[2]=(temp%1000)/100;                            //取壓力值十位
                        dispbuf[1]=((temp%1000)%100)/10;                    //取壓力值個(gè)位
                        dispbuf[0]=((temp%1000)%100)%10;                        //取壓力值十分位
                        if(temp/10<l){ led1=0;led2=1;beep=0;}
                        else  if(temp/10>h){led1=1;led2=0;beep=0;}
       else  {led1=1;led2=1;beep=1;}
           }
                if(mode==0)
                {
                xiemingling(0x80+0);
                xieshuju('Q');
               
                xieshuju(':');
                xieshuju(dispbuf[3]+0x30);      
                xieshuju(dispbuf[2]+0x30);      
                xieshuju(dispbuf[1]+0x30);
                xieshuju('.');               
                xieshuju(dispbuf[0]+0x30);      
                xieshuju(' ');
               
                xieshuju('T');
                xieshuju(':');
                xieshuju(c/1000+0x30);      
                xieshuju(c%1000/100+0x30);      
                xieshuju(c%1000%100/10+0x30);
                xieshuju('.');               
                xieshuju(c%10+0x30);      
      
               
               
                xiemingling(0x80+0x40);
                        xieshuju('H');
                xieshuju(':');
                xieshuju(h/100+0x30);      
                xieshuju(h%100/10+0x30);      
                xieshuju(h%10+0x30);
      
     xieshuju(' ');
    xieshuju('L');
                xieshuju(':');
                xieshuju(l/100+0x30);      
                xieshuju(l%100/10+0x30);      
                xieshuju(l%10+0x30);      
        }
        else
                {
                        xiemingling(0x80+0);
                xieshuju('R');
               
                       
                       
                                xiemingling(0xC0+0);
                xieshuju('Q');
               
                xieshuju(':');
                xieshuju(temp1/1000+0x30);      
                xieshuju(temp1%1000/100+0x30);      
                xieshuju(temp1%1000%100/10+0x30);
                xieshuju('.');               
                xieshuju(temp1%10+0x30);      
                xieshuju(' ');
                       
                        xiemingling(0xC0+0);
                xieshuju('Q');
               
                xieshuju(':');
                xieshuju(temp1/1000+0x30);      
                xieshuju(temp1%1000/100+0x30);      
                xieshuju(temp1%1000%100/10+0x30);
                xieshuju('.');               
                xieshuju(temp1%10+0x30);      
                xieshuju(' ');
               
                xieshuju('T');
                xieshuju(':');
                xieshuju(c1/1000+0x30);      
                xieshuju(c1%1000/100+0x30);      
                xieshuju(c1%1000%100/10+0x30);
                xieshuju('.');               
                xieshuju(c1%10+0x30);      
      
               
               
               
        }
               
  }
}

四、 proteus仿真設(shè)計(jì)
Proteus軟件是一款應(yīng)用比較廣泛的工具,它可以在沒有硬件平臺(tái)的基礎(chǔ)上通過自身的軟件仿真出硬件平臺(tái)的運(yùn)行情況,這樣就可以通過軟件仿真來驗(yàn)證我們?cè)O(shè)計(jì)的方案有沒有問題,如果有問題,可以重新選擇器件,連接器件,直到達(dá)到我們?cè)O(shè)定的目的,避免我們搭建實(shí)物的時(shí)候,如果當(dāng)初選擇的方案有問題,我們器件都已經(jīng)焊接好了,再去卸載下去,再去焊接新的方案的器件,測(cè)試,這樣會(huì)浪費(fèi)人力和物力,也給開發(fā)者帶來一定困惑,Proteus仿真軟件就很好的解決這個(gè)問題,我們?cè)谠O(shè)計(jì)之初,就使用該軟件進(jìn)行模擬仿真,測(cè)試,選擇滿足我們?cè)O(shè)計(jì)的最優(yōu)方案。最后根據(jù)測(cè)試沒問題的仿真圖紙,焊接實(shí)物,調(diào)試,最終完成本設(shè)計(jì)的作品。







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1