日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]/* 名稱:10s 的秒表 說明:首次按鍵計(jì)時(shí)開始,再次按鍵暫停,第三次按鍵清零。*/#include<reg51.h>#define uchar unsigned char#define uint unsigned intsbit K1=P3^7; uchari,Second_Counts,Key_Flag_Idx

/*  名稱:10s 的秒表

        說明:首次按鍵計(jì)時(shí)開始,再次按鍵暫停,第三次按鍵清零。

*/

#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};

//延時(shí)

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;    //定時(shí)器 方式 1

TH0=(65536-50000)/256;    //定時(shí)器 015ms 

TL0=(65536-50000)%256;

while(1)

{

if(Key_State!=K1)

DelayMS(10); 

Key_State=K1;

Key_Event_Handle();

}

}

 

/T0 中斷函數(shù)

void DSY_Refresh() interrupt 1

{

TH0=(65536-50000)/256;   //恢復(fù)定時(shí)器 初值

TL0=(65536-50000)%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; //滿 10010s)后顯示 00 

  }

}

 

擴(kuò)展閱讀:TIMER0與TIMER1控制條形LED

 

 

 

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉