找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

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

51單片機(jī)外部正脈沖寬度測(cè)量并顯示在LED數(shù)碼管 仿真程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
看到這類(lèi)資料比較少,拿去學(xué)習(xí)使用
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include <reg52.h>

  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. #define uLint unsigned long int

  5. void delayMs(uint x);

  6. uchar countInterrupt=0;
  7. sbit P3_3=P3^3;

  8. uchar code seg_table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  9. uint displayTable[]={0,0,0,0,0,0,0,0};

  10. void main(void)
  11. {
  12.   uchar cBitCode,i;
  13.   uLint count;
  14.         ET1=1;
  15.         EA=1;
  16.         
  17.         TH1=0;
  18.         TL1=0;
  19.         TMOD=0x90;//gate=1,method 1
  20.         
  21.         while(P3_3==1);        
  22.         
  23.         TR1=1;
  24.         while(P3_3==0);        
  25.         while(P3_3==1);        
  26.         TR1=0;
  27.         
  28.         count=(uLint)TH1*256+TL1;
  29.         count=count*2;
  30.         count=(uLint)countInterrupt*65536*2+count;
  31.         displayTable[0]=count/10000000;
  32.         displayTable[1]=count%10000000/1000000;
  33.         displayTable[2]=count%1000000/100000;
  34.         displayTable[3]=count%100000/10000;
  35.   displayTable[4]=count%10000/1000;
  36.         displayTable[5]=count%1000/100;
  37.         displayTable[6]=count%100/10;
  38.         displayTable[7]=count%10;
  39.         
  40.         while(1)
  41.         {
  42.                 cBitCode=0x01;
  43.                 for(i=0;i<8;i++)
  44.                 {
  45.                          P2= ~ seg_table[displayTable[i]];
  46.                          P1= ~cBitCode;
  47.                          delayMs(1);
  48.                          P1=0xFF;
  49.                          cBitCode<<=1;
  50.                  }
  51.          }
  52. }


  53. void delayMs(uint x)
  54. {
  55.   uchar j;
  56.   while(x--)
  57.   {
  58.      for(j=0;j<125;j++)
  59.            ;
  60.   }
  61. }

  62. void timer1_src(void) interrupt 3
  63. {
  64.         countInterrupt++;
  65. }
復(fù)制代碼

Keil代碼與Proteus仿真下載:
仿真程序.7z (76.68 KB, 下載次數(shù): 27)



評(píng)分

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

查看全部評(píng)分

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

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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