行阵键盘不起作用,数码管一直显示0
时间:10-02
整理:3721RD
点击:
#include<reg52.h> #include<intrins.h>#define uchar unsigned char#define uint unsigned intuchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0};uchar num,x,y,a;uint temp;void init();void display(uint num);uint keyscan();void delay(uint z){ for(x=z;x>0;x--) for(y=110;y>0;y--);}
void main(){ while(1) { display(keyscan()); } } void display(uint num){ P1=0x00; P0=table[num];}
uint keyscan(){ temp=P2; temp=temp&0xf0; while(temp!=0xf0) { temp=P2; switch(temp) { case 0x77:num=1;break; case 0x7b:num=2;break; case 0x7d:num=3;break; case 0x7e:num=4;break; case 0xb7:num=5;break; case 0xbb:num=6;break; case 0xbd:num=7;break; case 0xbe:num=8;break; case 0xd7:num=9;break; case 0xdb:num=10;break; case 0xdd:num=11;break; case 0xde:num=12;break; case 0xe7:num=13;break; case 0xeb:num=14;break; case 0xed:num=15;break; case 0xee:num=16;break; } } return num;}
void main(){ while(1) { display(keyscan()); } } void display(uint num){ P1=0x00; P0=table[num];}
uint keyscan(){ temp=P2; temp=temp&0xf0; while(temp!=0xf0) { temp=P2; switch(temp) { case 0x77:num=1;break; case 0x7b:num=2;break; case 0x7d:num=3;break; case 0x7e:num=4;break; case 0xb7:num=5;break; case 0xbb:num=6;break; case 0xbd:num=7;break; case 0xbe:num=8;break; case 0xd7:num=9;break; case 0xdb:num=10;break; case 0xdd:num=11;break; case 0xde:num=12;break; case 0xe7:num=13;break; case 0xeb:num=14;break; case 0xed:num=15;break; case 0xee:num=16;break; } } return num;}
程序太杂了,弄好了再发上来会好点
P2口没有赋值就开始读取了,你编的矩阵键盘也有问题