keyboard16.c

来自「ARM AD接口实验的例子」· C语言 代码 · 共 77 行

C
77
字号
#include "..\startup\44b.h"
#include "..\inc\def.h"
#include "..\inc\Keyboard16.h"

U16 FunctionKey=0xffff;//功能键扫描吗,0有效
U8 keyBoard_KeyMap[]={1,4,7,10,2,5,8,0,3,6,9,11,12,13,14,15};//10-退格,11-*/.,12-↑,13-↓,14-确定,15-取消;
U16 GetScanKey()
{
	U16 key;
	U32 i,temp;
	for(i=1;i<0x10;i<<=1){
		rPDATE|=0xf0;
		rPDATE&=~(i<<4);
		key<<=4;
		Delay(1);
		temp=rPDATC;
		key|=(temp&0xf);
	}
	return key;
}
U32 GetKey()
{
	int i;
	U16 key,tempkey=1;
	static U16 oldkey=0xffff;
	static U8 keystatus=0;
	U8 keycnt=0;
	U32 temp;
	while(1){
		key=0xffff;
		while(1){
			key=GetScanKey();
			if((key&FunctionKey)!=FunctionKey)//有按键按下
				break;
			Delay(200);
			oldkey=0xffff;
		}
		//Delay(800);
		Delay(500);
		if(key!=GetScanKey())
			continue;

		if(oldkey!=key){
			keystatus=0;
		}
		if(keystatus==0){	//第一次按下此键
			keycnt=0;
			keystatus=1;
		}
		else if(keystatus==1){	//第二次重复此键
			keycnt++;
			if(keycnt==20)
				keystatus=2;
			else
				continue;
		}

		oldkey=key;
		break;
	}
	
	for(i=0;i<16;i++){	//查找按键,不包括功能键
		if((key&tempkey)==0 && (FunctionKey&tempkey)!=0)
			break;
		tempkey<<=1;
	}
	temp=~(key|FunctionKey);
	return (temp<<16)|keyBoard_KeyMap[i];
}

void SetFunctionKey(U16 Fnkey)	//设定功能键扫描码,1有效 比如ctrl alt
{
	FunctionKey&=~Fnkey;
}
			

⌨️ 快捷键说明

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