c51单片机数码管显示矩阵键盘对应数的立方值的程序

2024-11-03 17:28:36
推荐回答(1个)
回答1:

#include #define uchar unsigned char #define uint unsigned int sbit beep=P3^6; sbit elre=P3^7; sbit K1=P1^4; sbit K2=P1^5; sbit K3=P1^6; sbit K4=P1^7; uchar code tabled[]={ 0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e}; void delay(uint a) { uint i,j; for(j=a;j>0;j--) for(i=110;i>0;i--); } void key_scan() { if(K1==0) { uint a; delay(10); if(K1==0) { while(!K1); for(a=100;a>0;a--) { beep=0; delay(1); beep=1; delay(1); } } } if(K2==0) { uchar j; delay(10); if(K2==0) { while(!K2); for(j=0;j<16;j++) { P2=0; P0=tabled[j]; delay(1000); P0=0xff; } } } if(K3==0) { delay(10); if(K3==0) { while(!K3); elre=0; delay(1000); elre=1; delay(1000); } } if(K4==0) { delay(10); if(K4==0) { while(!K4); P1=0xaa; P0=~0xaa; delay(10000); P1=0xff; P0=0xff; } } } void main() { while(1) { key_scan(); } }