新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)簡易秒表C51程序

單片機(jī)簡易秒表C51程序

作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏
本程序所用的原理圖下載:點(diǎn)這里,單片機(jī)芯片使用的stc89c52;找到數(shù)碼管的原理圖即可.這是一整個(gè)單片機(jī)開發(fā)板的電路圖其他的忽略.

以下是程序源代碼:
/**
*項(xiàng)目:簡易秒表
*設(shè)計(jì)任務(wù)書
*一、任務(wù)簡介:
*秒表是體育比賽常用計(jì)時(shí)工具。本設(shè)計(jì)要求利用現(xiàn)有的
*有限資源,設(shè)計(jì)具有儲存多個(gè)比賽成績功能的簡易秒表,
*并能利用鍵盤查詢歷史成績。
*二、設(shè)計(jì)要求:
*⑴ 系統(tǒng)硬件設(shè)計(jì)
*利用 ISP-III.1型用戶板完成設(shè)計(jì)要 求;
*⑵ 系統(tǒng)軟件設(shè)計(jì):
*完成控制軟件的編寫與調(diào)試;
*⑶ 基本功能:
*① 開機(jī)數(shù)碼管顯示0000;
*按下1#鍵開始計(jì)時(shí);再次按下1#鍵停止計(jì)時(shí);
*② 在停止?fàn)?態(tài)下,
*按下3#鍵清除所有計(jì)時(shí)信息,數(shù)碼管顯示0000;
*按下4#鍵啟動定時(shí)器,返回從原處計(jì)時(shí);
*(4) 附加功能:
*① 在計(jì)時(shí)狀態(tài)下,連續(xù)按下3#鍵可以連續(xù)記錄最多10個(gè) 運(yùn)動員成績,
*按下1#鍵停止計(jì)時(shí)或者計(jì)滿10次后自動停止時(shí);
*② 在停止?fàn)顟B(tài)下,
*連續(xù)按下2#鍵可以查看剛才記錄的10個(gè)成績,數(shù)碼管第 一位(0~9)顯示運(yùn)動員名
*次,數(shù)碼管后3位顯示運(yùn)動員成績;
*(5) 提高功能:
*① 按鍵時(shí)要求蜂鳴器有短暫發(fā)音;
**/
/**
*功能:簡易秒表
*作者:徐冉
*日期:2013-06-04-19:30-21:50
*備注:本程序已經(jīng)順利通過調(diào)試,并完美實(shí)現(xiàn),耗時(shí)2小時(shí)20分鐘;
**/
/****************AT89C52-RC MCU**************************/
/**********************51hei開發(fā)板**********************/
#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;

本文引用地址:http://m.butianyuan.cn/article/201612/324618.htm

uchar code table[] = {
0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F //"9"
};
//臨時(shí)表,用于存放運(yùn)動員的成績
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;
}
}
}



評論


技術(shù)專區(qū)

關(guān)閉