報警系統99秒定時報警器
proteus仿真原理圖:
0.png (33.76 KB, 下載次數: 99)
下載附件
2017-5-5 00:27 上傳
0.png (53.32 KB, 下載次數: 56)
下載附件
2017-5-5 00:26 上傳
單片機源程序:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit k1=P1^0;
- sbit k2=P1^1;
- sbit k3=P1^2;
- sbit k4=P1^3;
- sbit buz=P3^0;
- uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
- uchar count,shi,ge,dcount,dicount;
- void delay(int ms)
- {
- uchar i,j;
- for(i=ms;i>0;i--)
- for(j=200;j>0;j--);
- }
- void init()
- {
- P0=0x6f;
- P2=0x6f;
- P1=0xff;
- buz=0;
- TMOD=0x01;
- IE=0x82;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- TR0=1;
- dcount=99;
- }
- void keyscan()
- {
- if(k1==0)
- {
-
- delay(5);
- if(k1==0)
- {
- TR0=0;
- }
- }
- if(TR0==0)
- {
- if(k2==0)
- {
- delay(5);
- if(k2==0)
- {
-
- dcount++;
- if(dcount==100)
- dcount=0;
- while(!k2)
- {
- shi=dcount/10;
- ge=dcount%10;
- P0=duan[shi];
- P2=duan[ge];
- }
- }
- }
-
- if(k3==0)
- {
- delay(5);
- if(k3==0)
- {
- dcount--;
- if(dcount==-1)
- dcount=99;
- while(!k3)
- {
- shi=dcount/10;
- ge=dcount%10;
- P0=duan[shi];
- P2=duan[ge];
- }
- }
-
- }
- }
-
- if(k4==0)
- {
- delay(5);
- if(k4==0)
- {
- TR0=1;
-
- }
- }
-
-
- }
- void timer0() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- if(++count==20)
- {
- count=0;
- dcount--;
- if(dcount==-1)
- {
- TR0=0;
- while(k1!=0)
- {
- P0=0x00;
- P2=0x00;
- buz=1;
- delay(1000);
- P0=0xff;
- P2=0xff;
- buz=0;
- delay(1000);
- }
- dcount=99;
- }
- shi=dcount/10;
- ge=dcount%10;
- P0=duan[shi];
- P2=duan[ge];
- }
-
- }
- void main()
- {
-
- init();
- while(1)
- {
- keyscan();
- }
-
- }
復制代碼
下載:
定時報警器.rar
(32.15 KB, 下載次數: 119)
2017-5-4 22:37 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|