找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1861|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

10s的秒表單片機程序+電路圖

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:520474 發(fā)表于 2019-4-24 14:58 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式


#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit K1=P3^7;  
uchar
i,Second_Counts,Key_Flag_Idx;
bit Key_State;  
uchar
DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//延時
void DelayMS(uint ms)
{
uchar t;
while(ms--) for(t=0;t<120;t++);
}
//處理按鍵事件
void Key_Event_Handle()
{
if(Key_State==0)
{
Key_Flag_Idx=(Key_Flag_Idx+1)%3;
switch(Key_Flag_Idx)
{  
case 1:EA=1;ET0=1;TR0=1;break;
case 2:EA=0;ET0=0;TR0=0;break;
case 0:P0=0x3f;P2=0x3f;i=0;Second_Counts=0;
}
}
}
//主程序
void main()
{
P0=0x3f;            //顯示 00
P2=0x3f;
i=0;
Second_Counts=0;
Key_Flag_Idx=0;          //按鍵次數(shù)(取值 0,1,2,3)
Key_State=1;      //按鍵狀態(tài)
TMOD=0x01;    //定時器 0 方式 1
TH0=(65536-40000)/256;    //定時器 0:15ms
TL0=(65536-40000)%256;
while(1)
{
if(Key_State!=K1)
{  
DelayMS(10);
Key_State=K1;
Key_Event_Handle();
}
}
}   
//T0 中斷函數(shù)
void DSY_Refresh() interrupt 1
{
TH0=(65536-40000)/256;   //恢復(fù)定時器 0 初值
TL0=(65536-40000)%256;
if(++i==2)
{
i=0;
Second_Counts++;   //50ms*2=0.1s 轉(zhuǎn)換狀態(tài)
P0=DSY_CODE[Second_Counts/10];
P2=DSY_CODE[Second_Counts%10];
if(Second_Counts==100) Second_Counts=0; //滿 100(10s)后顯示 00  
}
}

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表