?? getkey.c
字號:
/*************************************************************/
/***********獲取按鍵程序**************************************/
/*************************************************************/
void GETKEY()
{
key =P2IN;
key &= 0xc0;
if(key==key_pre)
{
key_cnt++;
if(key_cnt>=5)
{
if(key_pre == 0x40) // p2.7口作為開門按鍵
{
FLAG |=gb_lock;
cardnum = 0x00;
recordbuf = 0x00;
REMARK = 0X03;
STATUS =0X00;
GETSTATUS();
FLAG |= gb_re1302;
FLAG |= gb_buzzer;
buzzer_cycle = 1;
FLAG1 |= gb_wrmsg;
buzzer_cycle = 1;
FLAG2 |= gb_doorval;
}
else if(key_pre == 0x80) //p2.6口作為布防撤防按鍵
{
FLAG1 &= ~gb_protect;
FLAG |= gb_buzzer;
buzzer_cycle = 1;
RUNBUZZER();
Delay_ms(irdly_cnt * 100);
}
}
}
else
{
key_pre =key;
key_cnt =0;
}
}
/**************************************************/
/*****獲取門的狀態(tài)*********************************/
/**************************************************/
uchar GETDOORCLOSE()
{
door =P1IN;
door &= BIT5;
if(door == door_pre)
{
door_cnt++;
if(door_cnt>=5)
{
if(door == door_close)// 門關(guān)返回1
{
return 1;
}
}
}
else
{
door_pre = door;
door_cnt =0;
}
return 0;
}
/**************************************************/
/********獲取紅外的狀態(tài)****************************/
/**************************************************/
uchar GETIRCLOSE()
{
ir = P1IN;
ir &= BIT4;
if(ir == ir_pre)
{
ir_cnt++;
if(ir_cnt>=5)
{
if(ir == ir_close)// 紅外關(guān)返回1
{
return 1;
}
}
}
else
{
ir_pre = ir;
ir_cnt =0;
}
return 0;
}
/**********************************************************/
/*************獲取紅外和門的狀態(tài)***************************/
/**********************************************************/
uchar GETIDSTATUS()
{
uchar buf = 0x03;
ir = P1IN;
ir &= 0x30;
if(ir == ir_pre)
{
ir_cnt++;
if(ir_cnt >= iren_cnt)
{
if(ir_close == (ir & BIT4))// 紅外關(guān)
{
buf &= ~BIT0;
}
if(door_close == (ir & BIT5))//門關(guān)
{
buf &= ~BIT1;
}
return buf;
//0 門和紅外都是關(guān)的
//1 門是開的,紅外是關(guān)的
//2 門是關(guān)的,紅外是開的
//3 門和紅外都是開的
}
}
else
{
ir_pre = ir;
ir_cnt =0;
}
return 4;
}
/*******************************************************/
/*********************************************************/
/********************************************************/
void msg_predeal()
{
recordbuf = 0x00;
REMARK = 0X05;
ERRORSTATUS();
FLAG |= gb_re1302;
FLAG |= gb_buzzer;
buzzer_cycle = 1;
FLAG1 |= gb_wrmsg;
buzzer_cycle = 1;
}
/**************************************************/
/**********監(jiān)控紅外和門的狀態(tài)****************************/
/**************************************************/
void GETDOOR()
{
uchar buf;
if(FLAG2 & gb_doorval) // 監(jiān)測門由于刷卡、遙控、按鍵開門
{ //后,是否關(guān)門了已經(jīng)。
if(GETDOORCLOSE())// 門關(guān)的處理程序
{
FLAG2 &= ~gb_doorval;
}
}
else if(FLAG2 & gb_concon)
{
if(FLAG2 & gb_doornval)//監(jiān)測門由于監(jiān)控門和紅外的狀態(tài)
{ //產(chǎn)生報警或門開所引起的記錄,門和紅外是否已關(guān)
if(GETDOORCLOSE())
{
FLAG2 &= ~gb_doornval;
cardnum = 0x03;
msg_predeal();
}
}
else if(FLAG2 & gb_irval)
{
if(GETIRCLOSE())
{
FLAG2 &= ~gb_irval;
cardnum = 0x01;
msg_predeal();
}
}
else if(FLAG2 & gb_concon1)//監(jiān)測時段內(nèi)的門和紅外狀態(tài)
{
buf = GETIDSTATUS();
switch(buf)
{
case 2: cardnum = 0x00; FLAG2 |= gb_irval; break;//2 門是關(guān)的,紅外是開的
case 3: //3 門和紅外都是開的
case 1: cardnum = 0x02; FLAG2 |= gb_doornval; break;//1 門是開的,紅外是關(guān)的
case 0: //0 門和紅外都是關(guān)的
case 4: goto getdoorend; // 4 程序沒有進(jìn)行完
}
msg_predeal();
}
else //由上位機(jī)所進(jìn)行的監(jiān)測
{
buf = GETIDSTATUS();
switch(buf)
{
case 2: if(conone & BIT6){cardnum = 0x00; FLAG2 |= gb_irval;} break;//2 門是關(guān)的,紅外是開的
case 3: //3 門和紅外都是開的
case 1: if(conone & BIT7){cardnum = 0x02; FLAG2 |= gb_doornval;} break;//1 門是開的,紅外是關(guān)的
case 0: //0 門和紅外都是關(guān)的
case 4: goto getdoorend; // 4 程序沒有進(jìn)行完
}
if((FLAG2 & gb_irval) || (FLAG2 & gb_doornval))
{
msg_predeal();
}
}
}
getdoorend:
return;
}
/********************************************/
/*****獲取紅外報警狀態(tài)***********************/
/********************************************/
uchar GETIR()
{
uchar i;
uchar buf;
for(i=0; i<10; i++)
{
buf = P1IN;
}
buf &= 0x30;
if(conone & BIT6)
{
if(buf & 0x10)//紅外狀態(tài)
{
if(conone & BIT2)
{
return 1;
}
}
}
return 0;
}
/*********************************************/
/*********獲取門的開關(guān)狀態(tài)********************/
/*********************************************/
uchar GET_DOOR()
{
uchar i;
uchar buf;
for(i=0; i<10; i++)
{
buf = P1IN;
}
buf &= 0x30;
if(buf & 0x20)//門狀態(tài)
{
if(conone & BIT3)
{
return 1;
}
}
return 0;
}
/********************************************/
/******讀取監(jiān)控狀態(tài)**************************/
/********************************************/
void jiankong()
{
if(FLAG2 & gb_rejian)
{
FLAG2 &= ~gb_rejian;
uchar buf = 0;
if(conone & BIT7)
{
buf |= BIT2;
}
if(conone & BIT6)
{
buf |= BIT3;
}
if(FLAG & gb_lock)
{
buf |= BIT1;
}
if(GETIR())
{
buf |= BIT0;
}
set_tx();
TX_DATA[7] = '0';
TX_DATA[8] = '0';
TX_DATA[9] = 'C';
TX_DATA[10] = '0';
TX_DATA[11] = '0';
TX_DATA[12] = '4';
TX_DATA[13] = c_hex((buf >> 4) & 0x0f);
TX_DATA[14] = c_hex(buf & 0x0f);
buf = 0;
if(FLAG & gb_lock)
{
buf |= BIT0;
}
if(GETIR())
{
buf |= BIT2;
}
if(GET_DOOR())
{
buf |= BIT3;
}
TX_DATA[15] = c_hex((buf >> 4) & 0x0f);
TX_DATA[16] = c_hex(buf & 0x0f);
jisuanhe(17);
}
}
/******************************************************/
/*************讀取控制信息*****************************/
/******************************************************/
void conmsg()
{
if(FLAG2 & gb_conmsg)
{
FLAG2 &= ~gb_conmsg;
set_tx();
TX_DATA[7] = '0';
TX_DATA[8] = '0';
TX_DATA[9] = '6';
TX_DATA[10] = '0';
TX_DATA[11] = '0';
TX_DATA[12] = 'A';
TX_DATA[13] = c_hex((conone >> 4) & 0x0f);
TX_DATA[14] = c_hex(conone & 0x0f);
TX_DATA[15] = c_hex((delay_cnt >> 4) & 0x0f);
TX_DATA[16] = c_hex(delay_cnt & 0x0f);
TX_DATA[17] = c_hex((wait_cnt >> 4) & 0x0f);
TX_DATA[18] = c_hex(wait_cnt & 0x0f);
TX_DATA[19] = c_hex((iren_cnt >> 4) & 0x0f);
TX_DATA[20] = c_hex(iren_cnt & 0x0f);
TX_DATA[21] = '1';
TX_DATA[22] = '0';
jisuanhe(23);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -