找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

單片機(jī)外部中斷顯示按鍵次數(shù)源程序+Proteus仿真

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:585660 發(fā)表于 2019-7-19 08:43 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
學(xué)會用中斷方式實現(xiàn)開發(fā)板按鍵K3和按鍵K4按鍵次數(shù)顯示
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)

學(xué)習(xí)了解中斷的結(jié)構(gòu)特點,設(shè)計并編程實現(xiàn)中斷次數(shù)顯示。
二、實驗要求
1.設(shè)計出STC89C51的中斷次數(shù)顯示電路。
2.編程實現(xiàn)按鍵次數(shù)顯示,觀察實驗現(xiàn)象。
三、可供選擇實驗儀器
51開發(fā)板、LED燈、USB轉(zhuǎn)串口下載線、Keil軟件等
四、實驗提示
要求用中斷方式實現(xiàn)開發(fā)板按鍵K3和按鍵K4按鍵次數(shù)顯示。
五、實驗電路


//你可以自己寫一些其他的中斷東西

0對應(yīng)定時器1
1對應(yīng)中斷1
2對應(yīng)定時器2
3對應(yīng)中斷2
4對應(yīng)串口


#include <reg51.h>
#include <intrins.h>
sbit Key3=P3^2;
sbit Key4=P3^3;
unsigned char duan[8]={0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0};
unsigned char code wei[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//共陽極數(shù)碼管                                   //0    1    2    3    4    5    6    7    8    9    A    b    C    d    e    F
unsigned char code DIG_CODE_CA[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//共陽極數(shù)碼管
//共陰極數(shù)碼管                                   //0    1    2    3    4    5    6    7    8    9    A    b    C    d    e    F
unsigned char code DIG_CODE_CC[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共陰極數(shù)碼管
//子函數(shù)
unsigned char i=0,j=0;
void display( );
void Delay1ms();
void DelayNms(unsigned int n);
//主函數(shù)
void main()
{
        TCON=0x05;//0000 0101
        EA=1;EX0=1;EX1=1;
        while(1)
        {
           display();
        }
}
void display()
{
  unsigned int n;
        duan[7]=DIG_CODE_CA[i%10];
        duan[6]=DIG_CODE_CA[i/10];
        duan[5]=DIG_CODE_CA[j%10];
        duan[4]=DIG_CODE_CA[j/10%10];
        duan[3]=DIG_CODE_CA[j/100];
  for(n=0;n<8;n++)
        {
                P2=wei[n];
                P1=duan[n];
                DelayNms(5);        
        }

}

//2 中斷函數(shù)
void Timer0_ISR() interrupt 0
{
        i++;
        if(i==100)
        i=0;        
}
void Timer1_ISR() interrupt 2
{
        j++;
        if(j==1000)
        j=0;        
}
//子函數(shù)聲明
void Delay1ms()                //@12.000MHz
{
        unsigned char i, j;

        i = 2;
        j = 239;
        do
        {
                while (--j);
        } while (--i);
}
void DelayNms(unsigned int n)
{
        while(n--)
        Delay1ms();
}

全部資料51hei下載地址:
中斷顯示次數(shù).zip (372.2 KB, 下載次數(shù): 11)

評分

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

查看全部評分

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

使用道具 舉報

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

本版積分規(guī)則

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

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

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