?? isr.c
字號:
// Copyright (c)2005 - 2006 by Laser Electronics, All Rights Reserved.
/*----------------------------------------------------------------------------+
| File Name: ISR.c, v1.0.1 |
| Author: |
| Date: |
+-----------------------------------------------------------------------------+
| Description: 聯網型智能樓宇對講系統 -- 管理中心機中斷服務函數 |
| 器件選擇 -- STC89C58RD+, PQFP-44 |
| 時鐘頻率 -- 24.000 MHz |
+-----------------------------------------------------------------------------+
/*----------------------------------------------------------------------------+
| Include files |
+----------------------------------------------------------------------------*/
#include "Main.h"
#include "KeyProcess.h"
/*----------------------------------------------------------------------------+
| External Variables |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| Internal Variables |
+----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------+
| General Subroutines |
+----------------------------------------------------------------------------*/
void Delay_us(BYTE timer)
{
timer -= 4;
while ( --timer ) ;
}
/*----------------------------------------------------------------------------+
| Interrupt Service Routines |
+----------------------------------------------------------------------------*/
// External Interrupt 0
void extern0_ISR(void) interrupt 0
{
// reset Timer0 counter
TR0 = DISABLE;
TH0 = LineIdleWaitTime >> 8;
TL0 = LineIdleWaitTime & 0xFF;
TR0 = ENABLE;
}
// Timer0 Interrupt 1
void timer0_ISR(void) interrupt 1
{
LineIdle = TRUE; // set LineIdle flag
}
// Timer1 Interrupt
void timer1_ISR(void) interrupt 3
{
// not used
}
// timer2 interrupt
void timer2_ISR(void) interrupt 5
{
UINT temp;
static UINT T2Counter; // T2計數器,計數到100時產生一個消息,
TF2 = 0; // 清除中斷標志, 只能靠軟件清除
if (WDT_Counter < 0x10)
{
RESET_WDT;
WDT_Counter ++;
}
SendMessage(MSG_TIMER_OVER); // 每10ms產生一次心跳信號
if ((++T2Counter) >= 1000)
{
T2Counter = 0;
SendMessage(MSG_TIMER_TEN_SECOND); // 每10秒鐘產生一次心跳信號
}
// 掃描按鍵狀態
KEY_ROW1 = 0; // 掃描第1行
temp <<= 4;
temp |= (P0 & 0x0F); // 得到第1行按鍵的電平
KEY_ROW1 = 1;
KEY_ROW2 = 0; // 掃描第2行
temp <<= 4;
temp |= (P0 & 0x0F); // 得到第2行按鍵的電平
KEY_ROW2 = 1;
KEY_ROW3 = 0; // 掃描第3行
temp <<= 4;
temp |= (P0 & 0x0F); // 得到第3行按鍵的電平
KEY_ROW3 = 1;
KEY_ROW4 = 0; // 掃描第4行
temp <<= 4;
temp |= (P0 & 0x0F); // 得到第4行按鍵的電平
KEY_ROW4 = 1;
PostMessage(MSG_KEY_ROUTINE, temp);
// 檢測手柄是拿起還是放下
if (bKey_Hand_1 != bKey_Hand_2)
{
bKey_Hand_1 = bKey_Hand_2;
if (bKey_Hand_2 == KEY_HANDLE)
{
if (KEY_HANDLE == 1 ) // 摘機
{
PostMessage(MSG_KEY_DOWN, Key_HandUp);
}
else if (KEY_HANDLE == 0 ) // 掛機
{
PostMessage(MSG_KEY_DOWN, Key_HandDown);
}
}
}
bKey_Hand_2 = KEY_HANDLE;
// 檢測壓簧按鍵按下
if (PKey_Hand_1 != PKey_Hand_2)
{
PKey_Hand_1 = PKey_Hand_2;
if (PKey_Hand_2 == KEY_CALL)
{
if (KEY_CALL == 0) // 壓簧呼叫按鍵按下
PostMessage(MSG_KEY_DOWN, Key_PCall);
}
}
PKey_Hand_2 = KEY_CALL;
if (PKey_Unlock_1 != PKey_Unlock_2)
{
PKey_Unlock_1 = PKey_Unlock_2;
if (PKey_Unlock_2 == Key_UNLOCK)
{
if (Key_UNLOCK == 0) //壓簧開鎖按鍵按下
PostMessage(MSG_KEY_DOWN, Key_Unlock);
}
}
PKey_Unlock_2 = Key_UNLOCK;
}
/*----------------------------------------------------------+
| |
+----------------------------------------------------------*/
void extern2_ISR(void) interrupt 6 //讀卡
{
bit OldEA;
BYTE temp,i,j;
UINT t;
OldEA = EA;
EA = DISABLE; // 關閉所有中斷,在接收主機數據的時候不能被中斷打斷
CardBuffer[0] = 0x00;
for ( i=0; i<7; i++ )
{
t=1000;
while ( ReadBit ) //等待起始位
{
if ( --t == 0 )
{
EA = OldEA;
return; //錯誤返回
}
}
Delay_us(78); //wait for 78us
temp = 0x00;
for ( j=0; j<8; j++ )
{
temp >>= 1;
if ( ReadBit )
{
temp |= 0x80;
}
Delay_us(49); //wait for 49us
}
if ( i>2 && i<7 )
{
CardBuffer[++CardBuffer[0]] = temp ;
}
}
if( SystemStatus.Status == Status_SetupAddTempCardByCard
| SystemStatus.Status == Status_SetupDelTempCardByCard)//只有在加卡和刪卡的狀態下才發送刷卡信息
{
SendMessage(MSG_RX_CARDNUMBER);
}
else
{
}
EA = OldEA;
}
/*----------------------------------------------------------------------------+
| End of source file |
+----------------------------------------------------------------------------*/
/*------------------------ Nothing Below This Line --------------------------*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -