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

當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀]___________________________________________功能:99秒計時時間2010—7—18___________________________________________ #include<reg52.h> code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,

___________________________________________

功能:99秒計時

時間2010&mdash;7—18

___________________________________________

 

#include<reg52.h>    


code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

unsigned char Dis_Shiwei;
unsigned char Dis_Gewei;

void delay(unsigned int cnt)
{
        while(--cnt);
}

main()
{

        TMOD |=0x01;    //10ms in 12M crystal,工作在模式一,16位定時器
        TH0=0xd8;
        TL0=0xf0;
        IE= 0x82;    //打開中斷
        TR0=1;    //打開定時開關(guān)

        while(1)    
        {
                P0=Dis_Shiwei;
                P2=0;
                delay(300);
                P0=Dis_Gewei;
                P2=1;
                delay(300);
        }

}

void tim(void) interrupt 1 using 1
{
        static unsigned char second,count;
        TH0=0xd8;        
        TL0=0xf0;

        count++;            
        if (count==100)       //100x10ms
        {
                count=0;
                second++;
                if(second==100)
                        second=0;
                Dis_Shiwei=tab[second/10];
                Dis_Gewei=tab[second%10];
   
        }

}


 /*

        定時器設(shè)定為:TH0=0xd8;TL0=0xf0;經(jīng)確定時10ms。從程序開始執(zhí)行,每當(dāng)主程序中的16位數(shù)發(fā)生溢出則觸發(fā)中斷,主程序保護現(xiàn)場并調(diào)用中斷子程序,也可以寫為:TH0=(65536-10000)/256;TL0=(65536-10000)%256。秒脈沖的產(chǎn)生要求精確定時1s,實際情況可能有延誤。


 

1  0000  0000   0000  0000

    1101  1000   1111  0000

————————————

     0010  0111   0001  0000

 

Time=16(1+16+32+64+512)=16*625=10000us=10ms

 

主函數(shù)中的關(guān)于定時器和中斷的控制位:

 

        TMOD |=0x01;    //模式選擇
        TH0=0xd8;    //高8位
        TL0=0xf0;    //低8位
        IE= 0x82;    //打開中斷
        TR0=1;    //打開定時開關(guān)(定時器運行控制位,置&ldquo;1”啟動定時器0)

 

        TMOD |= 0x01;   //使用模式1,16位定時器  
        TH0=0x00;   
        TL0=0x00;
        EA=1;            //總中斷打開
        ET0=1;           //定時器中斷打開
        TR0=1;           //定時器開關(guān)打開


*/

 

 

 

______________________________________________

功能:99秒倒計時

時間:2010—7&mdash;18

______________________________________________


#include<reg52.h>


code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

unsigned char Dis_Shiwei;
unsigned char Dis_Gewei;

void delay(unsigned int cnt)
{
        while(--cnt);
}

main()
{

        TMOD |=0x01;    //10ms in 12M crystal
        TH0=0xd8;
        TL0=0xf0;
        IE= 0x82;
        TR0=1;

        while(1)
        {
                P0=Dis_Shiwei;
                P2=0;
                delay(300);
                P0=Dis_Gewei;
                P2=1;
                delay(300);
        }

}

void tim(void) interrupt 1 using 1
{
        static unsigned char second=99,count;
        TH0=0xd8;
        TL0=0xf0;
        count++;
        if (count==100)
        {
                count=0;
                second--;
                if(second==0)
                {
                        second=99;
                }
                Dis_Shiwei=tab[second/10];
                Dis_Gewei=tab[second%10];

        }
}

 

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