⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isr.c

📁 程序概述: 这是个具体产品程序
💻 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 + -