单片机中利用中断程序做出按键按下显示数字,逐次加一
2个回答
展开全部
#include<reg51.h>
#define uchar unsigned char;
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; //0到f
uchar number,dat;
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
{
dat++;
dat%=100;
}
main()
{
TMOD=0x61;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=0xff;
TL1=0xff;
TR1=1;
ET1=1;
TR0=1;
ET0=1;
EA=1;
while(1);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询