//config.h
#ifndef __CONFIG_H
#define __CONFIG_H
#include <LPC21xx.H>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
typedef float fp32;
typedef double fp64 ;
#define Fosc 11059200
#define Fcclk (Fosc*4)
#define Fcco (Fcclk*4)
#define Fpclk (Fcclk/4)*1
#endif
//Text1.c
/**********************************************************************
* 功能:不完美的ARM7 查询方式 4X4矩阵键盘
**********************************************************************/
#include "config.h"
#define row1 0x00000080
#define row2 0x00000100
#define row3 0x00000200
#define row4 0x00000400
#define col1 0x00000800
#define col2 0x00001000
#define col3 0x00002000
#define col4 0x00004000
//显示的字符数组
uint8 DispCode[]=
{
0x3f,0x06,0x5b,0x4f,0x66, //0-4
0x6d,0x7d,0x07,0xff,0x6f, //5-9
0x77,0x7c,0x39,0x5e,0x79, //A,b,C,d,E,F
0x71
};
//延时函数,消除抖动
void Delay(uint16 count)
{
uint8 i;
while(--count != 0)
for(i = 0; i < 125; i++);
}
//主函数入口
int main()
{
PINSEL0 &= 0xc0000000;//设置P0.0-P0.14为IO口
IO0DIR =0xffffffff;
while(1)
{
while(1)
{
IO0CLR = row1+row2+row3+row4;//置行为低
IO0SET = col1+col2+col3+col4;//置列为高
IO0DIR &=0x000007ff; //设置0-10为输出,11-14为输入
if(((IO0PIN & col1)==0) || ((IO0PIN & col2)==0) || ((IO0PIN & col3)==0) ||((IO0PIN & col4)==0))
{
Delay(20);//消除抖动
if(((IO0PIN & col1)==0) || ((IO0PIN & col2)==0) || ((IO0PIN & col3)==0) ||((IO0PIN & col4)==0))
{
IO0CLR = 0x7f; //清空
IO0CLR = row1;
IO0SET = row2+row3+row4;
if((IO0PIN & col1)==0) {IO0SET = DispCode[0];break;}
if((IO0PIN & col2)==0) {IO0SET = DispCode[1];break; }
if((IO0PIN & col3)==0) {IO0SET = DispCode[2];break; }
if((IO0PIN & col4)==0) {IO0SET = DispCode[3];break; }
IO0CLR = row2;
IO0SET = row1+row3+row4;
if((IO0PIN & col1)==0) {IO0SET = DispCode[4];break; }
else if((IO0PIN & col2)==0) {IO0SET = DispCode[5];break; }
else if((IO0PIN & col3)==0) {IO0SET = DispCode[6];break; }
else if((IO0PIN & col4)==0) {IO0SET = DispCode[7];break; }
IO0CLR = row3;
IO0SET = row1+row2+row4;
if((IO0PIN & col1)==0) {IO0SET = DispCode[8];break; }
else if((IO0PIN & col2)==0) {IO0SET = DispCode[9];break; }
else if((IO0PIN & col3)==0) {IO0SET = DispCode[10];break; }
else if((IO0PIN & col4)==0) {IO0SET = DispCode[11];break; }
IO0CLR = row4;
IO0SET = row1+row2+row3;
if((IO0PIN & col1)==0) {IO0SET = DispCode[12];break; }
else if((IO0PIN & col2)==0) {IO0SET = DispCode[13];break; }
else if((IO0PIN & col3)==0) {IO0SET = DispCode[14];break; }
else if((IO0PIN & col4)==0) {IO0SET = DispCode[15];break; }
}
}
}
}
}
//图片