关于51单片机一个按键实现多个功能,51单片机按键控制这个很多人还不知道,今天小篇来为大家解答以上的问题,现在让我们一起来看看吧!

1、#include#define uchar unsigned char;uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; //0到har number,dat,dattop=10,cnt=0;it keyu=P1^0;it keyd=P1^1;void t0isr() interrupt 1{TH0=(65536-5000)/256;TL0=(65536-5000)%256;number++;if(number>1)number=0;switch(number){case 0:P2=0x02;P0=distab[dat/10];break;case 1:P2=0x01;P0=distab[dat%10];break;default:break;}}void t1isr() interrupt 3{TH1=(65536-10000)/256;TL1=(65536-10000)%256;cnt++;if(cnt>=dattop){cnt=0;dat++;dat%=100;}}main(){TMOD=0x11;TH0=(65536-5000)/256;TL0=(65536-5000)%256;TH1=(65536-10000)/256;TL1=(65536-10000)%256;TR1=1;ET1=1;TR0=1;ET0=1;EA=1;while(1){if(keyu==0){while(keyu==0);if(dattop}if(keyd==0){while(keyd==0);if(dattop>0)dattop--;}}}。

本文到这结束,希望上面文章对大家有所帮助。