|
學(xué)會用中斷方式實現(xiàn)開發(fā)板按鍵K3和按鍵K4按鍵次數(shù)顯示
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png (138.57 KB, 下載次數(shù): 46)
下載附件
2019-7-19 15:37 上傳
學(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ù)顯示。
五、實驗電路
//你可以自己寫一些其他的中斷東西
CM1M1V~%W5[D7RU]HG$D[T6.png (32.08 KB, 下載次數(shù): 59)
下載附件
2019-7-19 08:40 上傳
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)
2019-7-19 08:39 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|