專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

按鍵計(jì)數(shù)器

作者:佚名   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2010年10月04日   【字體:
______________________________________

功能:通過(guò)按鍵,控制2位數(shù)碼管100內(nèi)計(jì)數(shù)

時(shí)間:2010—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()
{

        EA=1;
        EX0=1;    //外部中斷0開
        IT0=1;    //邊沿觸發(fā)

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

}

void INT0_ISR(void) interrupt 0 using 1    //外部中斷函數(shù)
{
        static unsigned char second;

        second++;
        if(second==100)
                second=0;
        Dis_Shiwei=tab[second/10];
        Dis_Gewei=tab[second%10];     
}
關(guān)閉窗口

相關(guān)文章