矩阵键盘.docx
- 文档编号:28772958
- 上传时间:2023-07-19
- 格式:DOCX
- 页数:23
- 大小:15.17KB
矩阵键盘.docx
《矩阵键盘.docx》由会员分享,可在线阅读,更多相关《矩阵键盘.docx(23页珍藏版)》请在冰豆网上搜索。
矩阵键盘
[在此处输入文章标题]
基于xs128的矩阵键盘c程序
(23人评价)|670人阅读|51次下载|举报文档
基于xs128的矩阵键盘c程序
#include
/* common defines and macros */
#include "derivative.h"
/* derivative-specific definitions */
#define TESTPORT PORTA
uchar temp=0;
uchar key=0xff;
uchar key_1;
void delay_0(uchar i) {
uchar j=40;
while(i--)
while(j--);
}
void SetBusCLK_48M(void)
{
CLKSEL=0X00;
//disengage PLL to system
PLLCTL_PLLON=1;
//turn on PLL
SYNR =0xc0 | 0x05;
REFDV=0x80 | 0x01;
POSTDIV=0x00;
//pllclock=2*osc*(1+SYNR)/(1+REFDV)=96MHz;
_asm(nop);
//BUS CLOCK=48M
_asm(nop);
while(!
(CRGFLG_LOCK==1));
//when pll is steady ,then use it;
CLKSEL_PLLSEL =1;
//engage PLL to system;
}
uchar keyscan(void) {
delay_0(15);
DDRA=0xff;
TESTPORT=0xF0;
//
行扫描
DDRA=0x00;
delay_0(5);
temp=TESTPORT;
temp=temp&0xF0;
temp=~((temp>>4)|0xF0);//
读取列值
switch(temp)
{
case 1:
key=0;break;
case 2:
key=1;break;
case 4:
key=2;break;
case 8:
key=3;break;
default:
key=0xff;break;
}
DDRA=0xff;
TESTPORT=0x0F;
//
列扫描
DDRA=0x00;
delay_0(5);
temp=TESTPORT;
temp=temp&0x0F;
temp=~(temp|0xF0);
//
读取行值
switch(temp)
{
case 1:
key=key+0;break;
case 2:
key=key+4;break;
case 4:
key=key+8;break;
case 8:
key=key+12;break;
default:
key=0xff;break;
}
while(TESTPORT!
=0xf0) //
判断按键是否释放
{
delay_0(15);
DDRA=0xff;
TESTPORT=0xf0;
}
return key;
}
uchar key_judge()
{
DDRA=0xf0;
TESTPORT=0xF0;
DDRA=0x00;
if(TESTPORT!
=0xF0)
delay_0(15);
if(TESTPORT!
=0xF0)
{
//
是否有键按下
return 1;
}
else
{
return 0;
}
//
如果按键释放则返回键值
}
uchar i;
void main(void) {
/* put your own code here */
SetBusCLK_48M();
EnableInterrupts;
for(;;) {
key_1=keyscan();
i=key_judge();
// _FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 矩阵 键盘