设计要求:
制作一个LED数码管显示的秒表,用2位数码管显示时间,最小计时单位为“百毫秒”,计时范围0.1~9.9s。第一次按下并松开按键,开启计时功能;第二次按下并松开按键,停止计时,数码管显示当前计数值;第三次按下,秒表清零,等待下一次按下按键再一次开启计时功能。
外部硬件电路连接
程序设计
#include<reg52.h>
sbit key = P3^7;
unsigned char code table0[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,
0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1}; //共阴段码表(含点)
unsigned char code table2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴段码表(不含点)
//count1对小数点前变换次数进行计数判断,count2对小数点后变换次数进行计数判断,timer单次定时时间次数
unsigned char timer;
unsigned char count,num;
void delay(unsigned char xms)
{
unsigned char i, j;
while(xms)
{
i =