驱动程序源代码如下(Theprogrammforgasdetectorandalarmsystem):
GasAlarm
Mainsourcecode
#include"map.h"//processorregisterdefines(处理寄存器定义)
#include"ssi.h"//Bootloader'sSSIincluded(包含引导函数SSI)
#defineBYTEunsignedchar
#defineWORDunsignedint
#defineEnableInterrupts()asmSLI
#defineDisableInterrupts()asmSEI
#defineGas2
#defineReference3
#defineConsumption0//numberofADSinputforgivenvalue(进入的ADS数
为给定值)
#defineAlarm2Level20//deltabetweenalarm1andalarm2levels
#defineHysteresis5//hysteresisonmeasurement
#defineCurrentLimit252//voltagelevelfornsorcurrentproblem
#defineWaitTime2//howlongtimeIneedsignal
beforealarm
#defineSensKOLow10//belowthisvaluethensorisbadI/Omappings
#defineLEDPTA1
#defineOUTPUTPTA3
#defineMEMORY_FUNPTA2
//
#pragmaDATA_SEGSHORTMY_ZEROPAGE
WORDTisk1;
BYTETick2,Led_on;
unsignedintx;
unsignedinti;
#pragmaDATA_SEGDEFAULT
BYTEConsumptionValue,GasValue;
BYTEAlarm1,Alarm2,SensorAlarm;
BYTEReferenceValue;
BYTEAl_enable;
voidint(void)
{
#ifdefSOP_ENABLE
SONFIG1=0x00;
#el
CONFIG1=CONFIG1_SOPD;
#endif
DDRA=0xFF;//alloutputs
DDRA_BIT0=0;//PTA0isinput
DDRA_BIT4=0;//PTA4isinput
DDRA_BIT5=0;//PTA5isinput
PTAPUE=0x00;//nopullups
TSS_PS2=1;
TSS_PS1=1;
TSS_PS0=0;//pressaller/64
TSS_TOIE=1;//enablesTIMinterrupt
TSS_TSTOP=0;//runstimer
TMODH=0xS3;
TMODL=0x50;//1spret
EnableInterrupts();
}
interruptIV_IRQ1voidInt_IRQ(void)
{
//ISSR_ASK1=1;/*IRQask*/
}
interruptIV_TSHOvoidInt_TimerSH0(void)
{
//TSS0;
//TSS0_SH0F=0;/*clearingSH0flag*/
}
interruptIV_TSH1voidInt_TimerSH1(void)
{
//TSS1;
//TSS1_SH1F=0;/*clearingSH1flag*/
}
interruptIV_TOVFvoidInt_TimerTOV(void)
{
TSS;
TSS_TOF=0;/*clearingTOVflag*/
//TMODH=0xS3;
//TMODL=0x50;//1spret
TMOD=500;
Tick1++;
Tick2++;
if(Al_enable==1)
{
if(Tick2<2)
{
LED=0;//LEDison
OUTPUT=1;
}
el
{
LED=1;
OUTPUT=0;
}
if(Tick2>Led_on)Tick2=0;
}
}
interruptIV_KBRDvoidInt_Keyboard(void)
{
//KBSSR_ASKK=1;/*ledge*/
}
interruptIV_ADSvoidInt_ADSonv(void)
{
BYTEtemp;
//temp=ADR;/*justreadADRorwritetoADSSRtoclearint.
}
/*-------------------------------------------------------*/
voidWaiting(unsignedintKoliko)
{
Tick1=0;
while(Tick1!=(Koliko*10));
}
/*-----------------------------------------------------*/
BYTEMeasure(BYTEInputNumber)
{
BYTEtemp;
ADSSR=0x80|InputNumber;//tsoneconversion,nointerrupt
while(ADSSR_SOSO==0);//
waitsforconversioncomplete
temp=ADR;//
readsvalue
return(temp);
}/*/
voidmain(void)
{
Init();
SSIAPIInit();
#ifdefSOP_ENABLE
SOPSTL=0;/*bumpwatchdog*/
#end
if
LED=0;//switchledon
Waiting(150);//waits150safter
ret-nsorneedsit
SensorAlarm=0;
for(;;)//stadardoperation,waitforTicksandthenmeasure&write
{
GasValue=Measure(Gas);
ReferenceValue=Measure(Reference);
ConsumptionValue=Measure(Consumption);
if(GasValue<(ReferenceValue-Hysteresis))
{
Alarm1=0;
Alarm2=0;//delayalarms,levelisbelowtreshold
}
if(GasValue>ReferenceValue)
{
Al_enable=1;
if(GasValue>(ReferenceValue+Hysteresis))
{
Alarm2=1;//2ndalarmlevel,bigconcentration
Alarm1=0;
}
el
{
Alarm2=0;
Alarm1=1;//alarm1level
}}
if(ConsumptionValue>CurrentLimit)
{
SensorAlarm=1;//nsoralarm!
}
elif(GasValue
{
SensorAlarm=1;//nsoralarm!
}
elSensorAlarm=0;
if((SensorAlarm==0)&((Alarm1==0)&(Alarm2==0)))
{
if(MEMORY_FUN)//ifmem_funpinisopen,thendeletealarms
{Tick1=0;//noalarm,clearflags
LED=1;
OUTPUT=0;
Al_enable=0;
}
}
elif(Tick1>=WaitTime)
{
if(Alarm1)Led_on=25;
if(Alarm2)Led_on=10;
if(SensorAlarm)Led_on=1;
}
Waiting(1);
}
}
本文发布于:2023-01-03 18:22:23,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/85812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |