ps2.c

来自「这个事51各个模块的驱动程序」· C语言 代码 · 共 106 行

C
106
字号
// PS2.c 

#include "config.h"

uint8 dat ;
uint8 count;
uint8 num;
uint8 temp[2];
uint8 OS_Q_MEM_SEL Key_ASCII[16]; 

uint8 code NoShift[128] = 
{
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,

	
};
uint8 code AddShift[128] = 
{
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,
	1,2,3,4,6,7,8,9,0,

};


void PS2Init(void)
{
	IE0 = 1;
	EX0 = 1;
	// EA = 1;
}

void PS2Decode(void) 
{
	uint8 Key;
	PS2Init();
	OSQCreate(Key_ASCII, 16);
	while (1)
	{
		OSWait(K_SIG, 0);
		IE &= 0XFE;
		if(temp[1] == 0xf0 && temp[0] != 0xe0)
			Key = NoShift[temp[0]];
		else if(temp[0] == 0xe0 && temp[1] != 0xf0)
			Key = NoShift[temp[1]];
		else if(temp[0] == 0x12 || temp[0] == 0x59)
			Key = AddShift[temp[1]];
		OSWait(K_TMO, 5);
		IE0 = 0;
		IE |= 0x01;
		OSQPost(Key_ASCII, Key);
	}
}

void PS2Receive(void) interrupt 0
{
	IE = 0;
	dat >>= 1;
	if (sda)
	{
		dat |= 0x80;
	}
	count++;
	if (count == num)
	{
		if (num == 9)
		{
			temp[0] = dat;
			num = 20;
		}
		else
		{
			temp[1] = dat;
			IE &=0xfe;
			count = 0;
			num = 9;
			OSIntSendSignal(PS2Decode_ID);
			OSIntExit();
		}
	}
}

⌨️ 快捷键说明

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