51单片机防盗报警,按键可触发报警
单片机源程序如下:
- #include <REGX52.H>
- #include <INTRINS.H>//
- sbit feeq=P2^3;//看看原理图是哪个管脚
- int i;
- void Delay(unsigned int xms) //可以给参数的延时函数给几就是几毫秒
- { unsigned char data i, j;
- while(xms)
- {
- i = 2;
- j = 239;
- do
- {
- while (--j);
- } while (--i);
- xms--;
- }
- }
- void main()
- {
- if(P3_1==0 || P3_0==0) //如果S2按键或S3按键按下
- { for(i=0;i<10;i++)
- {
- P1=0xF0;//1111 0000
- Delay(80);
- P1=0xFF;//1111 1111
- Delay(80);
- feeq=0;//停
- Delay(80);
- feeq=1;
- Delay(80);//响
- }
- }
- }
复制代码
|