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

📄 key.c

📁 单片机实现消息队列的例子
💻 C
字号:
/*************************************************/

/********************显示与键盘接口********/

/*************2002年12月13日*******************/

/************WROTE BY WANGSW********************/
#include "reg52x2.h"
#include <intrins.h>
#include <absacc.h>

#include "define.h"

#include "key.h"

#define KEY XBYTE[0xF700]

#define KEY_SHORT_INTERVAL		2
#define KEY_LONG_INTERVAL		40

bool	g_bKeyEnable=TRUE;
byte data KeyIntervalSafeguard=0;		/*用于连续两个按键速度过快导致按键混乱*/
byte data KeyCounter=0;

static byte KeyMap(byte value);							/*键值检测*/			
/***********************************************************/

static byte KeyMap(byte value)
{
	switch(value)
	{
		case 0xFE:				
			return(1);
		case 0xFD:				
	              return(2);
		case 0xFB:				
			return(3);
		case 0xF7:				
			return(4);
		case 0xEF:				
			return(5);
		case 0xDF:				
			return(6);
		case 0xBF:				
			return(7);
		case 0x7F:				
			return(8);
			
		default:
			return(ERROR);	
	}
}

/*************************************************************/

extern void key_check(void)			/*5*5=25mS*/
{
	byte KeyWord;
	if(!g_bKeyEnable)
		return;

	KeyWord=KEY;
	if(KeyWord==0xFF)
	{
		KeyCounter=0;
		if(KeyIntervalSafeguard)	
		{
			KeyIntervalSafeguard--;
		}
		return;
	}

	KeyCounter++;

	if(KeyCounter==KEY_SHORT_INTERVAL)
	{	
		if(!KeyIntervalSafeguard)
		{
			msg_queue_in(MSG_KEY,KeyMap(KeyWord));
		}
		KeyIntervalSafeguard=3;
	}

		
	if(KeyCounter==KEY_LONG_INTERVAL)
	{
		msg_queue_in(MSG_KEY,KeyMap(KeyWord));
		KeyCounter-=4;
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -