采用12MHZ时钟频率的单片机,通过一个开关输入,触发定时计数。按下开关10次,计算按键的平均时间,并通过数码管显示出来。
程序代码:
#include<reg51.h>
sbit P1_0=P1^0;
unsigned char numcode[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88};
unsigned char sepcoed[4]={0x01,0x02,0x04,0x08};
unsigned int num=0;
void int1() interrupt 1
{
num++;
TL0=0xb0;
TH0=0x3c;
}
void DelayMS(unsigned int ms)
{
unsigned char i;
while(ms--) for(i=0;i<120;i++);
}