基于51单片机的跑表

本文介绍了如何使用51单片机设计一个跑表,该跑表配备3个按钮,采用89C51芯片,并通过数码管显示,精度达到0.01秒,最大测量时间范围为60秒。
摘要由CSDN通过智能技术生成

基于51单片机的跑表,它由3个按钮,一块89c51芯片和数码管组成,精度达到0.01s,最大测量范围为60s。

#include<reg51.h>
#define DataPort P0//定义数据端口
sbit Seg = P2^1;//段锁存
sbit Bit = P2^2;//位锁存
sbit KEY1 = P1^0;//暂停按钮
sbit KEY2 = P1^1;//继续按钮
sbit KEY3 = P1^2;//复位按键

void Display(unsigned char firstbit,unsigned char NUM);
void delay_100us();//100us的延迟

unsigned char Seg_Code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79};
unsigned char Bit_Code[] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
unsigned char DISP_NUM[8];
void main()
{
	  unsigned int num,num_S1,num_S2,num_MS1,num_MS2;
	  while(1)
		{
			  num ++;
			  if(5999 == num)
				{
					  num = 0;
				}
				num_S1 = num / 1000;
				num_S2 = ( num % 1000 ) / 100;
				num_MS1 = (( num % 1000 ) % 100 ) / 10;
				num_MS2 = (( num % 1000 ) % 100 ) % 10;
				DISP_NUM[0] = Seg_Code[num_S1];
				DISP_NUM[1] = Seg_Code[num_S2] | 0x8
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值