用ARM编写的4*4键盘
#include "config.h"
#define KEY_COL1 1<12
#define KEY_COL2 1<13
#define KEY_COL3 1<14
#define KEY_COL4 1<15
#define KEY_ROW1 1<8
#define KEY_ROW2 1<9
#define KEY_ROW3 1<10
#define KEY_ROW4 1<11
#define KEYO KEY_ROW1|KEY_ROW2|KEY_ROW3|KEY_ROW4 //行,设置为输出口
#define KEYI KEY_COL1|KEY_COL2|KEY_COL3|KEY_COL4 //列,设置为输入口
//按键抬起,则将相应的键值返回
uint16 get_key(void)
{
uint16 scc,re;
IO0SET=KEYI;
IO0CLR=KEYO;
while((IO0PIN&0xf000)==0xf000);
delay(10);
if((IO0PIN&0xf000)!=0xf000)
{
scc=0xfe00;
while((scc&0x1000)!=0)
{
IO0SET=scc;
IO0CLR=((~scc)&0xff00);
if((IO0PIN&0xf000)!=0xf000)
{
re=((IO0PIN&0xf000)|0x0fff);
while((IO0PIN&0xf000)!=0xf000);//等待按键抬起,返回键值
return (~(scc|0x00ff)|(~re));
}
else scc=(scc<1)|0x0100;
}
}
return 0;
}
//按键在LCD上显示相应的字符
#include "config.h"
#define KEY_COL1 1<12
#define KEY_COL2 1<13
#define KEY_COL3 1<14
#define KEY_COL4 1<15
#define KEY_ROW1 1<8
#define KEY_ROW2 1<9
#define KEY_ROW3 1<10
#define KEY_ROW4 1<11
#define KEYO KEY_ROW1|KEY_ROW2|KEY_ROW3|KEY_ROW4 //行,设置为输出口
#define KEYI KEY_COL1|KEY_COL2|KEY_COL3|KEY_COL4
#define uchar unsigned char
#define UART0_BPS 115200
uchar keynum;
void uart0_int(void)
{
uint16 Fdiv;
U0LCR=0x83;
Fdiv=(Fpclk/16)/UART0_BPS;
U0DLM=Fdiv/256;
U0DLL=Fdiv%256;
U0LCR=0x03;
}
void uart0(uchar keynum)
{
PINSEL0=0x05;
uart0_int();
U0THR=keynum;
while(!(U0LSR&0x40));
}
int main()
{
extern uint16 get_key();
uint16 key;
IO0DIR|=KEYO;
int_lcd();
while(1)
{ PINSEL0=0;
PINSEL1=0;
key=get_key();
delay(10);
switch(key)
{
case 0x1100:clear();send_str("0");keynum=0; break;
case 0x2100:clear();send_str("1");keynum=1; break;
case 0x4100:clear();send_str("2");keynum=2; break;
case 0x8100:clear();send_str("3");keynum=3; break;
case 0x1200:clear();send_str("4");keynum=4; break;
case 0x2200:clear();send_str("5");keynum=5; break;
case 0x4200:clear();send_str("6");keynum=6; break;
case 0x8200:clear();send_str("7");keynum=7; break;
case 0x1400:clear();send_str("8");keynum=8; break;
case 0x2400:clear();send_str("9");keynum=9; break;
case 0x4400:clear();send_str("A");keynum=A; break;
case 0x8400:clear();send_str("B");keynum=B; break;
case 0x1800:clear();send_str("C");keynum=C; break;
case 0x2800:clear();send_str("D");keynum=D; break;
case 0x4800:clear();send_str("传输");uart0(keynum); break;
case 0x8800:clear();send_str("转换"); break;
default:break;
}
}
}
ARM4*4键 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)