📄 lpc_lib_keyboard.c
字号:
/***********************************************************************
Embest Info&Tech Co., Ltd. All rights reserved.
www.embedinfo.com
file :
author : embest
establish: 2006.
modify :
notes :
***********************************************************************/
/*-------------------------------------------------------------------*/
/* include files */
/*---------------------------------------------------------------- --*/
#include "..\..\com\lpc_lib_keyboard\lpc_lib_keyboard.h"
/*-------------------------------------------------------------------*/
/* extern function/variable declare */
/*-------------------------------------------------------------------*/
void irq_eint3_svr(void);
extern irq_eint3(void);
/*-------------------------------------------------------------------*/
/* global variable define */
/*-------------------------------------------------------------------*/
INT32U key_data=255;
/*-------------------------------------------------------------------*/
/* function code */
/*-------------------------------------------------------------------*/
/*
**********************************************************************************************
* name: key_init
* func: initialize keyboard function
* para: none
* ret: none
* modify:
* comment:
**********************************************************************************************
*/
void key_init(void)
{
INT32U i;
PINSEL2 &=0xFFFFFFF7; //initialize the matrix key
IODIR1 |=0x00F00000;
IOCLR1 |=0x00F00000;
IODIR0&=0xBFFFFFFF; //before set pin to eint3,must set the pin sate
PINSEL1&=0xCFFFFFFF;
i=PINSEL1; //select eint3 pin
i &=0xCFFFFFFF;
i |=0x20000000;
PINSEL1=i;
VICVectCntl4 = 0x31; //17th channel 110001
VICVectAddr4 = (INT32U)irq_eint3;
VICIntEnable |= 0x00020000;
}
/*
**********************************************************************************************
* name: key_close
* func: disable 4*4 keyboard,close key interrupt
* para: none
* ret: none
* modify:
* comment:
**********************************************************************************************
*/
void key_close(void)
{
PINSEL2 &=0xFFFFFFF7; //restore reset value
IODIR1 &=0xFF00FFFF;
IOCLR1 &=0xFF00FFFF;
IODIR0 &=0xBFFFFFFF; //restore reset value
PINSEL1&=0xCFFFFFFF;
VICVectCntl4 = 0x0; //close int. channel
VICVectAddr4 = 0x0;
VICIntEnable &= 0xFFFDFFFF;
}
/**************************eint3 svr***********************************
Desc:The scan key interrupt service routine,after finish the scan action,put key
value to global variable "key_data".
---0-----1-----2-----3------
---4-----5-----6-----7------line
---8-----9-----a-----b------
---c-----d-----e-----f------
column
***********************************************************************/
void irq_eint3_svr(void)
{
key_data=key_read();
EXTINT=0x08;
VICVectAddr=0;
}
/*
**********************************************************************************************
* name: key_read
* func: when enter key interrupt,this routine get key value
* para: none
* ret: none
* modify:
* comment: scan line and column,get the key value
**********************************************************************************************
*/
INT8U key_read(void)
{
INT32U i; //column scan parameter,4 times
INT32U j=4; //line scan parameter,4 times
INT32U temp=0x00100000; //column scan value (1, 2, 4, 8)
INT32U temp1=0x00010000; //line scan value
INT8U data=3; //key value
for(i=0;(i<4)&&(j==4);i++) //column scan cycle
{
IOCLR1 |=temp; //clear the pin that scaned follow
IOSET1 |=0x00F00000-temp; //set non-scan pin
for(j=0,temp1=0x00010000;j<4;j++) //line scan cycle
{
if((IOPIN1&temp1)==0)
{ data=data+j*4-i; //see the pressed key,compute key value
break; //jump out cycle
}
temp1=temp1<<1; //turn next pin,also next line
}
temp*=2; //scan next colmn
}
while((IOPIN1&0x000f0000)!=0x000f0000); //wait till the key release
time_dly(20); //stability dealy
IODIR1 |=0x00F00000; //restore key bin for next int.
IOCLR1 |=0x00F00000;
if(data<16)
return data;
else
return 255;
}
/*
**********************************************************************************************
* name: get_key
* func: wait for key value change ,then return latest key value
* para: none
* ret: key value
* modify:
* comment:
**********************************************************************************************
*/
INT8U get_key(void)
{
INT8U key;
while(key_data>15);
key=key_data;
key_data=255;
return key;
}
/*
**********************************************************************************************
* name: moni_key
* func: watch key interrupt ,return the result
* para: none
* ret: 1: indicate that key was pressed 0:none key pressed
* modify:
* comment:
**********************************************************************************************
*/
INT8U moni_key(void)
{
if(key_data<16)
{
key_data=255;
return 1;
}
else
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -