仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- void delay1(int x){
- uint i,j;
- for(i=0;i<123;i++)
- for(j=0;j<x;j++);
- }
- //uchar led[]={0x00,0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0X77,0X7C,0X39,0X5e,0X79,0X71};
- uchar led[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0X71 };
- unsigned int num[]={0xee,0xed,0xeb,0xe7,0xde,0xdd,0xdb,0xd7,
- 0xbe,0xbd,0xbb,0xb7,0x7e,0x7d,0x7b,0x77};
- unsigned char hang[]={0xef,0xdf,0xbf,0x7f};
- uchar key_scan(){
- uchar a,i,n;
- for(a=0;a<4;a++){
- P1=hang[a];
- if(P1!=hang[a]){
- delay1(100);
- if(P1!=hang[a]){
- for(i=0;i<4;i++){
- if(P1==num[4*a+i]){
- n=4*a+i+1;
- }
- }
- }
- }
- }
- return n;
- }
- main()
- {
- P2=0XFE;
- while(1)
- {
- P0=led[key_scan()];
- }
- }
-
-
复制代码
Proteus7.5版本的dsn工程文件下载:
51单片机_矩阵键盘.zip
(66.34 KB, 下载次数: 79)
|