?? ps2keyboard.c
字號:
#include "Target\44blib.h"
#include "Target\44b.h"
#include "ps2keytest\KeyNumTab.h"
#define SetIn_PC15 (0x3FFFFFFF) //set rPCONC,PC15 Input
#define En_Eint2 (0x0030) //set rPCONG,enable EINT4
#define Setout_PG4 (0x0100) //set rPCONG,PG4 Output
#define FallTrig (0x00000200) //set rEXTINT,Falling trigger
#define KeysNum (71) //display KeyBoard keys number
void __irq Eint2Isr(void);
volatile char which_int=0;
volatile int IntNum=0,KeyV=0;
void Disp_KeyDat(void)
{
int Key_Dat=0,n;
unsigned char m[4];
Uart_Printf("Wait KeyBoard key.....\n");
do
{
Key_Dat=PS2_GetKeyDat();
//Uart_Printf("KeyNum=0x%x\n",Key_Dat);
for(n=0;n<=KeysNum;n++)
{
if(UnShifted[n][0]==Key_Dat)
{ m[0]=UnShifted[n][1];
m[1]=UnShifted[n][2];
m[2]=UnShifted[n][3];
m[3]=0;
Uart_Printf("%s",m);
}
Delay(10);
}
}while(!(Key_Dat==0x5a));
}
int PS2_GetKeyDat(void)
{
unsigned int save_G,save_PG,save_C,save_PC,KeyV1=0; //use save I/O Register
unsigned int i,Key_temp=0,High_Num=0;
rINTCON=0x1; //disable fiq, enable irq
rINTMOD=0x0; //IRQ mode
pISR_EINT2=(int)Eint2Isr; //convection address
rINTMSK=~(BIT_GLOBAL|BIT_EINT2); //ex_interrupt 2 service available
rEXTINT=FallTrig; //Falling edge mode ,Falling trigger
save_G=rPCONG;
save_PG=rPUPG;
save_C=rPCONC;
save_PC=rPUPC;
rPCONC=SetIn_PC15; //PC15 Input
rPUPC=0x0; //pull up enable
rPCONG=En_Eint2; //EINT2 enable
rPUPG=0x04; //pull up enable
KeyV=0;
while(IntNum<11);
rINTMSK=BIT_GLOBAL;
//Uart_Printf("KeyNum00=0x%x\n",KeyV);
Key_temp=KeyV;
for(i=10;i>0;i--)
{
if((Key_temp & 0x1) == 1)
{
High_Num++;
Key_temp= Key_temp >> 1;
}
else
Key_temp= Key_temp >> 1;
}
if(High_Num==1||High_Num==3||High_Num==5||High_Num==7||High_Num==9)
KeyV1=KeyV & 0xff;
else
KeyV1=0;
//Uart_Printf("KeyNum01=0x%x\n",KeyV1);
//rINTMSK=BIT_GLOBAL;
rPCONG=save_G;
rPUPG=save_PG;
rPCONC=save_C;
rPUPC=save_PC;
//which_int=0;
IntNum=0;
Key_temp=0;
High_Num=0;
return KeyV1;
//rINTCON=0x5;
}
void __irq Eint2Isr(void)
{
//which_int=rEXTINTPND;
//if (which_int==1)
//{
KeyV=(rPDATC & 0x8000) | KeyV;
KeyV = KeyV >> 1; //Right move 1 bit
IntNum++;
if (IntNum==11)
{
KeyV=KeyV>>6;
KeyV=KeyV&0x1ff;
}
//}
//Uart_Printf("KeyNum=%x\n",KeyV);
rEXTINTPND=0x0f; //clear EXTINTPND reg.
rI_ISPC=BIT_EINT2; //clear pending_bit
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -