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

📄 keyboard16.c

📁 这是嵌入式软件电话本的小软件
💻 C
字号:
#include "..\startup\44b.h"
#include "..\inc\def.h"
#include "..\inc\drv\Keyboard16.h"

U16 FunctionKey=0xffff;//功能键扫描吗,0有效
//U8 keyBoard_KeyMap[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//U8 keyBoard_KeyMap[]={0,0xF,0xE,4,0xD,0xC,0xB,3,0xA,9,8,1,6,7,5,2};
U8 keyBoard_KeyMap[]={11,15,7,3,14,12,13,10,9,8,6,5,4,2,1,0};
U16 GetScanKey()
{
	U16 key;
	U32 i,temp;
	for(i=1;i<0x10;i<<=1){
		rPDATE|=0xf0;
		rPDATE&=~(i<<4);
		key<<=4;
		OSTimeDly(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;
			OSTimeDly(20);
			oldkey=0xffff;
		}
		//Delay(800);
		OSTimeDly(50);
		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;
}

U16 GetNoTaskScanKey()
{
	U16 key;
	U8 i,temp;
	for(i=1;i<0x10;i<<=1){
		rPDATE|=0xf0;
		rPDATE&=~(i<<4);
		key<<=4;
		Delay(10);
		temp=rPDATC;
		key|=(temp&0xf);
	}
	return key;
}

U32 GetNoTaskKey()
{
	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=GetNoTaskScanKey();
			if((key&FunctionKey)!=FunctionKey)//有按键按下
				break;
			Delay(200);
			oldkey=0xffff;
		}
		Delay(800);
		if(key!=GetNoTaskScanKey())
			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];
}

⌨️ 快捷键说明

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