📄 inout.c
字号:
#include "reg58.h"
#include "intrins.h"
#define _INOUT_C_
#include "inout.h"
#include "bus.h"
#include "timer.h"
#include "373.h"
#include "system.h"
#include "sram.h"
#include "event.h"
#include "define.h"
#include "lcd.h"
#include "setup.H"
bit exitfirst,aux1first,aux2first,contactfirst,tamperfirst,duressflag;
bit exitlowfirst,aux1lowfirst,aux2lowfirst,contactlowfirst,tamperlowfirst;
unsigned char data exitchktimer,aux1chktimer,aux2chktimer,contactchktimer,tamperchktimer;
unsigned char data instate,refreshtimer,contactovertimer;//
//unsigned char xdata tblinout[16][5];
/////////////////////////////////////////////////////////////////////////////
unsigned char code tblinoutcode[16][5]=
{
{3,0,0,0,0},
{0,3,3,3,3},
{0,3,3,3,3},
{3,0,3,3,3},
{0,99,99,99,99},
{3,0,0,0,0},
{0,3,0,0,0},
{0,3,0,0,0},
{0,3,0,0,0},
{3,0,0,0,0},
{0,3,0,0,0},
{0,3,0,0,0},
{0,3,0,0,0},
{3,3,3,3,3},
{0,0,0,0,0},
{0,0,0,0,0},
};
/////////////////////////////////////////////////////////////////////////////////
void clearoutput()
{
doorunlockflag=0;
alarmonflag=0;
ttl1onflag=0;
ttl2onflag=0;
beeponflag=0;
doorontimer=0;
alarmontimer=0;
ttl1ontimer=0;
ttl2ontimer=0;
beepontimer=0;
//clr_373(DOORPORT);
lockdoor();
clr_373(ALARMPORT);
clr_373(TTL1PORT);
clr_373(TTL2PORT);
clr_373(BEEPPORT);
}
/////////////////////////////////////////////////////////////////////////////////
void cleariodef()
{
unsigned char i;
for(i=0;i<80;i++)
{
ram_writep0(i,*(tblinoutcode[0]+i));
}
}
/////////////////////////////////////////////////////////////////////////////////
void exitchk()
{
if(!EXIT)
{
if(!exitfirst)exitlowfirst=0;
else
{
if(exitlowfirst)
{
exitlowfirst=0;
exitchktimer=timerl;
}
else
{
if((timerl-exitchktimer)<TEXITDELAYTIME)return;
exitfirst=0;
//here add the code when exit button is pressed
instate|=bittbl[EXITCOUNT];
if(setflag)return;
accessevent(EVENTINPUT|MESSAGEEXIT);
}
}
}
else
{
if(exitfirst)exitlowfirst=1;
else
{
//if(exitlowfirst) //051126
if(!exitlowfirst) //051126
{
exitlowfirst=1;
exitchktimer=timerl;
}
else
{
if((timerl-exitchktimer)<TEXITDELAYTIME)return;
exitfirst=1;
instate&=~bittbl[EXITCOUNT];
}
}
}
}
/////////////////////////////////////////////////////////////////
void aux1chk()
{
if(!AUX1)
{
if(!aux1first)aux1lowfirst=0;
else
{
if(aux1lowfirst)
{
aux1lowfirst=0;
aux1chktimer=timerl;
}
else
{
if((timerl-aux1chktimer)<TAUX1DELAYTIME)return;
aux1first=0;
instate|=bittbl[AUX1COUNT];
if(setflag)return;
accessevent(EVENTINPUT|MESSAGEAUX1);
}
}
}
else
{
if(aux1first)aux1lowfirst=1;
else
{
//if(aux1lowfirst) //051126
if(!aux1lowfirst) //051126
{
aux1lowfirst=1;
aux1chktimer=timerl;
}
else
{
if((timerl-aux1chktimer)<TAUX1DELAYTIME)return;
aux1first=1;
instate&=~bittbl[AUX1COUNT];
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
void aux2chk()
{
if(!AUX2)
{
if(!aux2first)aux2lowfirst=0;
else
{
if(aux2lowfirst)
{
aux2lowfirst=0;
aux2chktimer=timerl;
}
else
{
if((timerl-aux2chktimer)<TAUX2DELAYTIME)return;
aux2first=0;
instate|=bittbl[AUX2COUNT];
if(setflag)return;
accessevent(EVENTINPUT|MESSAGEAUX2);
}
}
}
else
{
if(aux2first)aux2lowfirst=1;
else
{
//if(aux2lowfirst) //051126
if(!aux2lowfirst) //051126
{
aux2lowfirst=1;
aux2chktimer=timerl;
}
else
{
if((timerl-aux2chktimer)<TAUX2DELAYTIME)return;
aux2first=1;
instate&=~bittbl[AUX2COUNT];
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
void contactchk()
{
if(!CONTACT)
{
if(!contactfirst)contactlowfirst=0;
else
{
if(contactlowfirst)
{
contactlowfirst=0;
contactchktimer=timerl;
}
else
{
if((timerl-contactchktimer)<TCONTACTDELAYTIME)return;
contactfirst=0;
instate|=bittbl[CONTACTCOUNT];
if(setflag)
{
contactovertimer=100;
return;
}
if(!doorunlockflag)
{
accessevent(EVENTINPUT|MESSAGECONTACT);
contactovertimer=20;
}
else
{
contactovertimer=100;
}
}
}
}
else
{
if(contactfirst)contactlowfirst=1;
else
{
//if(contactlowfirst) //051126
if(!contactlowfirst) //051126
{
contactlowfirst=1;
contactchktimer=timerl;
}
else
{
if((timerl-contactchktimer)<TCONTACTDELAYTIME)return;
contactfirst=1;
instate&=~bittbl[CONTACTCOUNT];
if(!beeponflag)clr_373(BEEPPORT);
accessevent(EVENTINPUT|MESSAGEDOORCLOSED);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
void tamperchk()
{
if(!TAMPER)
{
if(!tamperfirst)tamperlowfirst=0;
else
{
if(tamperlowfirst)
{
tamperlowfirst=0;
tamperchktimer=timerl;
}
else
{
if((timerl-tamperchktimer)<TTAMPERDELAYTIME)return;
tamperfirst=0;
instate|=bittbl[TAMPERCOUNT];
//Here add codes when tamper switch opened
if(setflag)return;
accessevent(EVENTINPUT|MESSAGETAMPER);
}
}
}
else
{
if(tamperfirst)tamperlowfirst=1;
else
{
//if(tamperlowfirst) //051126
if(!tamperlowfirst) //051126
{
tamperlowfirst=1;
tamperchktimer=timerl;
}
else
{
if((timerl-tamperchktimer)<TTAMPERDELAYTIME)return;
tamperfirst=1;
instate&=~bittbl[TAMPERCOUNT];
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
bit getiodata(unsigned char ioindex)
{
unsigned char i;
if(ioindex>=16)return FALSE;
ioindex*=5;
for(i=0;i<5;i++)
{
tempbuff[i]=ram_readp0(ioindex+i);
if(tempbuff[i]>99)
{
tempbuff[i]=0;
ram_writep0(ioindex+i,0);
}
}
}
/////////////////////////////////////////////////////////////////////////
void checksaveio(unsigned char ioindex)
{
unsigned char i;
if(ioindex>=16)return;
ioindex*=5;
for(i=0;i<5;i++)
{
tempbuff[i]=(dispbuff[LINE2][tblsetioposi[i*2]]-0x30)*10+dispbuff[LINE2][tblsetioposi[i*2+1]]-0x30;
if(tempbuff[i]>99)return;
}
for(i=0;i<5;i++)
{
ram_writep0(ioindex+i,tempbuff[i]);
}
}
/////////////////////////////////////////////////////////////////////////
void init_inout()
{
exitfirst=1;
aux1first=1;
aux2first=1;
contactfirst=1;
tamperfirst=1;
}
/////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -