#include "msp430g2553.h"
#define CON 3
#define MAX 100
#define MIN 30
char de=1,j=20;
unsigned int con=0,osc=0,i=0;
void delay(unsigned i)
{
while(i--);
}
int main( void )
{
WDTCTL = WDTPW + WDTHOLD;
P3DIR|=BIT4;
P1IE |= BIT4;
P1IES |= BIT4;
P1IFG &= ~BIT4;
osc=MAX;
while(1)
{
for(i=0;i<10;i++)
{
if(de)
{
con=CON;
while(con--)
{
P3OUT ^=BIT4;
delay(osc);
}
if(osc--<MIN)
{
de=0;
con=CON;
if(!j--)
{
__bis_SR_register(LPM4_bits + GIE); // LPM0, WDT_ISR will force exit
}
}
}
else
{
con=CON;
while(con--)
{
P3OUT ^=BIT4;
delay(osc);
}
if(osc++>MAX)
{
de=1;
con=CON;
}
}
}
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
j=20;
__bic_SR_register_on_exit(LPM4_bits); // Exit LPM0
P1IFG &= ~BIT4; // P1.4 IFG cleared
}
复制代码程序上电时会报警20下,然后进入休眠模式,烟雾传感器检测到有异常气体时(使用打火机放气实验)会输出低电平,触发P1.4中断,然后唤醒MCU报警20次再次休眠。
报警频率时长可以修改MAX,MIN,CON三个数值。
程序在浴室终端上测试成功。
没有图像采集设备,暂未上传图像资料。
代码附上:
烟感报警.rar
(43.56 KB, 下载次数: 17)