|
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
protues.png (262.73 KB, 下載次數(shù): 54)
下載附件
2019-10-25 16:07 上傳
單片機(jī)源程序如下:
- /************************************************************************************************************\
- **文件名稱:xx.c
- **功能描述:計(jì)算一秒鐘延時(shí)瞬間脈沖數(shù)量
- **日期:2019.10.25
- **版本:v1
- ***************************************************************************************************************/
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code numtab[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//定義共陽(yáng)數(shù)碼管0-9
- uint pulse_time; //定義一個(gè)定時(shí)中斷變量
- uint pulse_count; //定義脈沖低電平變量
- uint pulse; //定義1秒脈沖數(shù)變量
- /***************************************************************************************************\
- **函數(shù)名稱;初始化定時(shí)和外部中斷
- **
- ****************************************************************************************************/
- void MCU_init()
- {
- EX0=1;//開外部中斷0
- PX0=1;// 外部中斷0高優(yōu)先級(jí)
- IT0=1;//觸發(fā)模式0= 電平 1=邊沿觸發(fā)
- TMOD = 0x11;
- ET1=1;
- TR1=1;
- TH1 = (65535-25000)/256; //載入初值,設(shè)置定時(shí)器1 25ms中斷一次
- TL1 = (65535-25000)%256;
- EA=1;
-
-
- }
- /*******************************************************************************************\
- **函數(shù)名稱:定時(shí)器1入口
- **功能:50us中斷一次
- ***************************************************************************************************/
- void TIME1() interrupt 3
- {
-
- pulse_time++;
- if(pulse_time==40) //達(dá)到1000ms,即1s鐘
- {
- pulse_time=0; //定時(shí)中斷變量復(fù)位
- pulse=pulse_count/2; //一個(gè)周期脈沖有兩次低電平信號(hào),所以1秒鐘脈沖數(shù)量為總低電平次數(shù)除以2
- pulse_count=0; //復(fù)位脈沖低電平變量
- }
-
-
- }
- /*******************************************************************************************\
- **函數(shù)名稱:外部中斷入口
- **功能:檢測(cè)沒(méi)沖低電平信號(hào)
- ***************************************************************************************************/
- void IINT0() interrupt 0
- {
-
- pulse_count++; //當(dāng)脈沖信號(hào)低電平時(shí)候+1;
-
- }
- /*********************************************************************\
- **函數(shù)名稱:delay(uint m)
- **功能:延時(shí)函數(shù)
- **********************************************************************/
- void delay(uchar m)
- {
- uchar i,y;
- for(i=m;i>0;i--)
- for(y=110;y>0;y--);
- }
- /*********************************************************************\
- **函數(shù)名稱:display(uint xx)
- **功能:4位數(shù)碼管顯示程序
- **********************************************************************/
- void display(uint xx)
- {
- if(xx>=0&&xx<10)
- {
- P2=0X08;
- P0=numtab[xx];
- delay(3);
- P0=0XFF;
- }
- if(xx>=10&&xx<100)
- {
- P2=0X04;
- P0=numtab[xx/10];
- delay(3);P0=0XFF;
- P2=0X08;
- P0=numtab[xx%10];
- delay(3);P0=0XFF;
- }
- if(xx>=100&&xx<1000)
- {
- P2=0X02;
- P0=numtab[xx/100];
- delay(3);P0=0XFF;
- P2=0X04;
- P0=numtab[xx%100/10];
- delay(3);P0=0XFF;
- P2=0X08;
- P0=numtab[xx%100%10];
- delay(3);P0=0XFF;
- }
- if(xx>=1000&&xx<10000)
- {
- P2=0X01;
- P0=numtab[xx/1000];
- delay(3);P0=0XFF;
- P2=0X02;
- P0=numtab[xx%1000/100];
- delay(3);P0=0XFF;
- P2=0X04;
- P0=numtab[xx%1000%100/10];
- delay(3);P0=0XFF;
- P2=0X08;
- P0=numtab[xx%1000%100%10];
- delay(3);P0=0XFF;
- }
-
- }
- //主函數(shù)入口
- void main()
- {
- MCU_init(); //初始化
- delay(1000);
- while(1)
- {
-
- display(pulse);
- }
- }
復(fù)制代碼
0.png (10.87 KB, 下載次數(shù): 59)
下載附件
2019-10-25 16:36 上傳
所有資料51hei提供下載:
脈沖計(jì)數(shù).zip
(79.66 KB, 下載次數(shù): 51)
2019-10-25 16:06 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|