本程序所用的原理图下载:点这里,单片机芯片运用的stc89c52;找到数码管的原理图即可.这是一整个单片机开发板的电路图其他的疏忽.
以下是程序源代码:
/**
*项目:简易秒表
*规划使命书
*一、使命简介:
*秒表是体育竞赛常用计时东西。本规划要求使用现有的
*有限资源,规划具有贮存多个竞赛成果功用的简易秒表,
*并能使用键盘查询前史成果。
*二、规划要求:
*⑴ 体系硬件规划:
*使用 ISP-III.1型用户板完结规划要 求;
*⑵ 体系软件规划:
*完结操控软件的编写与调试;
*⑶ 基本功用:
*① 开机数码管显现0000;
*按下1#键开端计时;再次按下1#键中止计时;
*② 在中止状 态下,
*按下3#键铲除一切计时信息,数码管显现0000;
*按下4#键发动定时器,回来从原处计时;
*(4) 附加功用:
*① 在计时状态下,接连按下3#键能够接连记载最多10个 运动员成果,
*按下1#键中止计时或许计满10次后主动中止时;
*② 在中止状态下,
*接连按下2#键能够检查方才记载的10个成果,数码管第 一位(0~9)显现运动员名
*次,数码管后3位显现运动员成果;
*(5) 进步功用:
*① 按键时要求蜂鸣器有时间短发音;
**/
/**
*功用:简易秒表
*作者:徐冉
*日期:2013-06-04-19:30-21:50
*补白:本程序现已顺畅经过调试,并完美完成,耗时2小时20分钟;
**/
/****************AT89C52-RC MCU**************************/
/**********************51hei开发板**********************/
#include
#include
typedef unsigned int uint;
typedef unsigned char uchar;
sbit wela = P2^7;
sbit dula = P2^6;
sbit FM = P2^3;
sbit s1 = P3^4;
sbit s2 = P3^5 ;
sbit s3 = P3^6;
sbit s4 = P3^7;
uchar code table[] = {
0x3F, //”0″
0x06, //”1″
0x5B, //”2″
0x4F, //”3″
0x66, //”4″
0x6D, //”5″
0x7D, //”6″
0x07, //”7″
0x7F, //”8″
0x6F //”9″
};
//暂时表,用于寄存运动员的成果
uint dis[10] = {0x00, 0x00, 0x00, 0x00,0x00,
0x00, 0x00, 0x00, 0x00, 0x00};
uchar mge, m, num, counter;
uint sec;
//delay:xms
void delay(uint xms)
{
uchar i, j;
for(i = 0; i < xms; i++)
for(j = 0; j < 125; j++);
}
//display:score
void display(uchar mge, uint num)
{
uchar bai, shi, ge;
bai = num / 100 % 10;
shi = num / 10 % 10;
ge = num % 10;
dula = 1;
P0 = table[mge];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
P0 = 0x00;
delay(1);
dula = 1;
P0 = table[bai];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xf7;
wela = 0;
P0 = 0x00;
delay(1);
dula = 1;
P0 = table[shi];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xef;
wela = 0;
P0 = 0x00;
delay(1);
dula = 1;
P0 = table[ge];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xdf;
wela = 0;
P0 = 0x00;
delay(1);
}
//timer0:init
void init()
{
TMOD = 0x01;
TH0 = 0xB8;
TL0 = 0x00;
TR0 = 1;
EA = 1;
ET0 = 1;
}
//keyscan:
void keyscan()
{
if(s1 == 0)
{
delay(5);
if(s1 == 0)
{
FM = 0;
TR0 = ~TR0;
while(!s1);
delay(2);
while(!s1);
FM = 1;
}
}
if(s2 == 0)
{
delay(5);
if(s2 == 0)
{
FM = 0;
if(TR0 == 0)
{
sec = dis[mge];
mge++;
if(mge >= 10)
{
sec = 0;
mge = 0;
m = 0;
}
}
while(!s2);
delay(2);
while(!s2);
FM = 1;
}
}
if(s3 == 0)
{
delay(5);
if(s3 == 0)
{
FM = 0;
if(TR0 == 0)
{
sec = 0;
mge = 0;
m = 0;
}
else
{
dis[m] = sec;
m++;
if(m >= 10)
{
TR0 = 0;
m = 0;
}
}
while(!s3);
delay(2);
while(!s3);
FM = 1;
}
}
if(s4 == 0)
{
delay(5);
if(s4 == 0)
{
FM = 0;
sec = dis[9];
TR0 = 1;
while(!s4);
delay(2);
while(!s4);
FM = 1;
}
}
}
//main:
void main(void)
{
init();
while(1)
{
display(mge, sec);
keyscan();
}
}
//timer0:int
void timer_int() interrupt 1
{
TH0 = 0xB8;
TL0 = 0x00;
counter++;
if(counter == 50)
{
counter = 0;
sec++;
if(sec >= 999)
{
sec = 0;
}
}
}