基于51单片机的火灾报警系统, 用adc0809来采集模拟数据。包含源程序,下面是proteus仿真原理图
单片机源程序:
- #include<REG51.H>
- #define uint unsigned int
- #define uchar unsigned char
- uchar code a[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //段码组合,共阴极
- uchar code b[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //位码组合 低有效
- uchar code c[9]={201,202,203,204,205,206,207,208,0};
- uchar y[8]={0,0,0,0,0,0,0,0};
- //*************************************************************************************
- sbit ST=P3^1;
- sbit OE=P3^0;
- sbit Add=P3^4;
- sbit Bdd=P3^5;
- sbit Cdd=P3^6;
- uint t=0,h=0x9f;
- uchar p[8];
- uchar k,m,n,q,g,r,d,i,cnt=0,v=0;
- void delay(uchar s);
- void inrupt(void)
- {
- TMOD=0x01;
- TH0=0x3c;
- TL0=0xb0;
-
- EX0=1;
- IT0=1;
- EX1=1;
- IT1=1;
- EA=1;
- }
- void lxy(void)
- {
- switch(d)
- {
- case 0:Add=0,Bdd=0,Cdd=0;ST=0,ST=1,ST=0;break;
- case 1:Add=1,Bdd=0,Cdd=0;ST=0,ST=1,ST=0;break;
- case 2:Add=0,Bdd=1,Cdd=0;ST=0,ST=1,ST=0;break;
- case 3:Add=1,Bdd=1,Cdd=0;ST=0,ST=1,ST=0;break;
- case 4:Add=0,Bdd=0,Cdd=1;ST=0,ST=1,ST=0;break;
- case 5:Add=1,Bdd=0,Cdd=1;ST=0,ST=1,ST=0;break;
- case 6:Add=0,Bdd=1,Cdd=1;ST=0,ST=1,ST=0;break;
- case 7:Add=1,Bdd=1,Cdd=1;ST=0,ST=1,ST=0;break;
-
- }
- }
-
-
-
- void time0(void) interrupt 2
- {
- OE=1;
- t=P1;
- OE=0;
- if(t>=h)
- {
- y[d]=t;
- p[i]=d;
- i++;
-
-
- }
- d++;
- lxy();
- r--;
-
- }
- void time1(void) interrupt 1
- {
- TH0=0x3c;
- TL0=0xb0;
- cnt++;
- if(cnt>=20)
- {
- v--;
- cnt=0;
- if(v==0)
- {
- g=1;
- ET0=0;
- TR0=0;
- }
- else g=0;
- }
-
- }
- void time2(void) interrupt 0
- {
- g=1;
- i++;
- if(p[i]==8)
- { i=0;
- g=1;
- }
- delay(20);
- }
- void delay(uchar s) //延时0.1*n毫秒 0
- {
- uchar j;
- do
- {
- for(j=0;j<23;j++)
- ;;;
- } while(s--);
- }
- void display(void)
- { for(;;)
- {
- P2=b[0],P0=a[k];
- delay(20);
- P2=b[1],P0=a[m];
- delay(20);
-
- P2=b[2],P0=a[n];
- delay(20);
- P2=b[3],P0=a[q];
- delay(20);
- P2=b[4],P0=a[v/10];
- delay(20);
- P2=b[5],P0=a[v%10];
- delay(20);
- if(g==1)
- {
-
- break;
- }
- }
- }
- void main(void)
- {
- inrupt();
- for(;;)
- {
- P2=0x3e,P0=a[0];
- delay(20);
- P2=0x3d,P0=a[0];
- delay(20);
-
- P2=0x3b,P0=a[0];
- delay(20);
- P2=0x37,P0=a[0];
-
- for(i=0;i<8;i++)
- {
- p[i]=8;
- }
- i=0;
- t=0;
- d=0;
- r=8;
- Add=0,Bdd=0,Cdd=0;
-
- ST=0;
- ST=1;
- ST=0;
- while(r);
- i=0;
- if(y[p[i]]>=h)
- {
-
- v=20;
- ET0=1;
- TR0=1;
- while(v)
- {switch(p[i])
- {
- case 0: k=c[p[i]]/1000;m=(c[p[i]]%1000)/100;n=(c[p[i]]%100)/10;q=c[p[i]]%10;display();break;
- case 1: k=c[p[i]]/1000;m=(c[p[i]]%1000)/100;n=(c[p[i]]%100)/10;q=c[p[i]]%10;display();break;
- case 2: k=c[p[i]]/1000;m=(c[p[i]]%1000)/100;n=(c[p[i]]%100)/10;q=c[p[i]]%10;display();break;
- case 3: k=c[p[i]]/1000;m=(c[p[i]]%1000)/100;n=(c[p[i]]%100)/10;q=c[p[i]]%10;display();break;
- case 4: k=c[p[i]]/1000;m=(c[p[i]]%1000)/100;n=(c[p[i]]%100)/10;q=c[p[i]]%10;display();break;
- case 5:
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
下载:
火警报警系统.rar
(24.4 KB, 下载次数: 157)
|