|
|
電路原理圖如下:
程序設(shè)計(jì)流程圖:
實(shí)驗(yàn)總結(jié):
實(shí)驗(yàn)中有遇到許多問題。定義LED顯示字模時(shí)不能定義成unsigned char code類型;count不能定義成unsigned char類型等。程序中用到了外部中斷,讓我們把書本上的知識(shí)運(yùn)用到了實(shí)踐中,受益匪淺。
單片機(jī)源程序如下:
- #include<reg51.h> //包括一個(gè)51標(biāo)準(zhǔn)內(nèi)核的頭文件
- #include<intrins.h>
- sbit P3_2=P3^2; //輸出端口定義
- sbit P3_3=P3^3;
- unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //LED燈顯示字模
- char count; //定義符號(hào)變量
- void delay (unsigned int time) //延時(shí)函數(shù)
- {unsigned int j=0;
- for(;time>0;time--)
- for(j=0;j<125;j++);
- }
- void INT0_srv() interrupt 0 using 1 //外部中斷0處理程序
- {
-
- delay(10);
- if(INT0==0){ //P3^3接口按鍵按下
- count++; //計(jì)數(shù)器增1
- if(count==100) //判斷循環(huán)是否超限
- count=0;
- P1=table[count/10]; //顯示十位數(shù)字
- P2=table[count%10]; //求余,顯示個(gè)位數(shù)字
- while(P3_2==0); //等待按鍵松開,防止連續(xù)計(jì)數(shù)
- }}
- void INT1_srv() interrupt 2 using 2 { //外部中斷1處理函數(shù)
-
-
- delay(10);
- if(INT1==0){
- count--;
- if(count<0)
- count=99;
- P1=table[count/10];
- P2=table[count%10];
- while(P3_3==0);
- }}
-
- void main(){
- count=0;
- EA=1; //中斷初始化
- EX0=1;
- EX1=1;
- while(1); //無限循環(huán)體
- }
復(fù)制代碼
完整的Word格式文檔51黑下載地址:
實(shí)驗(yàn)二 按鍵計(jì)數(shù)LED燈數(shù)碼管顯示.docx
(351.14 KB, 下載次數(shù): 21)
2018-11-25 13:22 上傳
點(diǎn)擊文件名下載附件
|
|