自己畫的電路圖,寫的源碼,可以用。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #include"LM041DRV.H"
- #define LED XBYTE[0XBfff]
- #define BUTTON XBYTE[0XDfff]
- sbit sound=P3^4;
- sbit EOC=P3^0;
- uint water,press,water_up=200,water_down=30,press_up=210,press_down=40;
- void KeyPad()
- {
- uint wu,wd,pu,pd;
- switch(BUTTON)
- {
- case 0xfe:
- while(BUTTON!=0xff);
- wu=water_up;
- water_up+=5;
- break;
- case 0xfd:
- while(BUTTON!=0xff);
- wu=water_up;
- water_up-=5;
- break;
- case 0xfb:
- while(BUTTON!=0xff);
- wd=water_down;
- water_down+=5;
- break;
- case 0xf7:
- while(BUTTON!=0xff);
- wd=water_down;
- water_down-=5;
- break;
- case 0xef:
- while(BUTTON!=0xff);
- pu=press_up;
- press_up+=5;
- break;
- case 0xdf:
- while(BUTTON!=0xff);
- pu=press_up;
- press_up-=5;
- break;
- case 0xbf:
- while(BUTTON!=0xff);
- pd=press_down;
- press_down+=5;
- break;
- case 0x7f:
- while(BUTTON!=0xff);
- pd=press_down;
- press_down-=5;
- }
- if(water_down>60000)
- water_down=0;
- if(press_down>60000)
- press_down=0;
- if((water_up-water_down)<30)
- {
- water_up=wu;
- water_down=wd;
- }
- if((press_up-press_down)<30)
- {
- press_up=pu;
- press_down=pd;
- }
- }
- void T0Init()
- {
- TMOD=0x01;
- TH0=63832/256;
- TL0=63832%256;
- ET0=1;
- EA=1;
- }
- uchar Init_disp(uint a,uint b,uint c,uint d)
- {
- uchar count=0;
- SetRowCol(0,4);
- printf("UP DN RV");
- SetRowCol(1,0);
- printf("P1:%3u %3u %3u",a,b,water);
- SetRowCol(2,0);
- printf("P2:%3u %3u %3u",c,d,press);
- if(water>water_up && press>press_up)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P1>UP P2>UP");
- return 0;
- }
- if(water>water_up && press<press_down)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P1>UP P2<DN");
- return 0;
- }
- if(water<water_down && press>press_up)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P1<DN P2>UP");
- return 0;
- }
- if(water<water_down && press<press_down)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P1<DN P2<DN");
- return 0;
- }
- if(water>water_up)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P1>UP ");
- }
- if(press>press_up)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P2>UP");
- }
- if(water<water_down)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P1<DN ");
- }
- if(press<press_down)
- {
- count++;
- SetRowCol(3,0);
- printf("AM: P2<DN");
- }
- if(count==0)
- {
- SetRowCol(3,0);
- printf("AM: ");
- }
- }
- void main()
- {
- uchar xdata *adc0808=0x78ff;
- uchar i,led=0xff,count;
- LM041_Init();
- T0Init();
- while(1)
- {
- adc0808=0x78ff;
- *adc0808=0;
- while(EOC==0);
- *adc0808=0;
- while(EOC==0);
- water=*adc0808;
- adc0808+=0x100;
- *adc0808=0;
- while(EOC==0);
- *adc0808=0;
- while(EOC==0);
- press=*adc0808;
- count=0;
- if(water>water_up)
- {
- led=(led&0xfe);
- led=(led|0x02);
- }
- else if(water<water_down)
- {
- led=(led&0xfd);
- led=(led|0x01);
- }
- else
- {
- led=(led|0x03);
- count++;
- }
-
- if(press>press_up)
- {
- led=(led&0xfb);
- led=(led|0x08);
- }
- else if(press<press_down)
- {
- led=(led&0xf7);
- led=(led|0x04);
- }
- else
- {
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
報警電路.zip
(84.78 KB, 下載次數: 27)
2018-4-27 19:40 上傳
點擊文件名下載附件
|