单片机矩阵键盘程序 同时进行显示 绝对可用 看过就懂的
源代码在线查看: 矩阵键盘c编程.lst
C51 COMPILER V8.08 矩誣键盘C编程 08/17/2008 17:54:40 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE 矩誣键盘C编程
OBJECT MODULE PLACED IN 矩阵键盘C编程.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 矩阵键盘C编程.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*****************************************************************************
2 4*4行列式键盘的C程序编写
3
4 *****************************************************************************/
5 #include
6 #include
7 #include
8 #define uchar unsigned char
9 #define uint unsigned int
10
11 uchar code Tab[16]={
12 0xC0,/*0*/
13 0xF9,/*1*/
14 0xA4,/*2*/
15 0xB0,/*3*/
16 0x99,/*4*/
17 0x92,/*5*/
18 0x82,/*6*/
19 0xF8,/*7*/
20 0x80,/*8*/
21 0x90,/*9*/
22 0x88,/*A*/
23 0x83,/*b*/
24 0xC6,/*C*/
25 0xA1,/*d*/
26 0x86,/*E*/
27 0x8E,/*F*/
28 };
29 uchar idata com1,com2;
30
31 void delay(void)
32 {
33 1 char a,b;
34 1 for(a=20;a>0;a--)
35 1 for(b=248;b>0;b--);
36 1
37 1 }
38
39 key_scan()
40 {
41 1 uchar i;
42 1 uchar com;
43 1 com1=0x00;
44 1 com2=0x00;
45 1 delay(); //消除键盘抖动 延时10ms
46 1 P2=0xf0;
47 1 if(P2!=0xf0)
48 1 {
49 2 com1=P2;
50 2 P2=0x0f;
51 2 com2=P2;
52 2 }
53 1 P2=0xf0;
54 1 while(P2!=0xf0);
55 1 com=com1|com2;
C51 COMPILER V8.08 矩誣键盘C编程 08/17/2008 17:54:40 PAGE 2
56 1 if(com==0xee)i=0;
57 1 if(com==0xed)i=1;
58 1 if(com==0xeb)i=2;
59 1 if(com==0xe7)i=3;
60 1 if(com==0xde)i=4;
61 1 if(com==0xdd)i=5;
62 1 if(com==0xdb)i=6;
63 1 if(com==0xd7)i=7;
64 1 if(com==0xbe)i=8;
65 1 if(com==0xbd)i=9;
66 1 if(com==0xbb)i=10;
67 1 if(com==0xb7)i=11;
68 1 if(com==0x7e)i=12;
69 1 if(com==0x7d)i=13;
70 1 if(com==0x7b)i=14;
71 1 if(com==0x77)i=15;
72 1 return(i);
73 1 }
74
75 void main()
76 {
77 1 uchar dat;
78 1 while(1){
79 2 P2=0xf0;
80 2 while(P2!=0xf0){
81 3 dat=key_scan();
82 3 P0=Tab[dat];}}
83 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 166 ----
CONSTANT SIZE = 16 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 2 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)