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

QQ登錄

只需一步,快速開始

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

紅外人流量計(jì)數(shù)程序(數(shù)碼管顯示)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:451448 發(fā)表于 2019-1-6 17:07 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
做課設(shè)可以用的紅外人流計(jì)數(shù)

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

  2.     sbit led1    =P2^0;
  3.     sbit led2    =P2^1;
  4.     sbit led3    =P2^2;
  5.     sbit led4    =P2^3;

  6.     unsigned code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};          //數(shù)碼管斷碼
  7.         unsigned code dis[]  ={0xfe,0xfd,0xfb,0xf7};                                      //掃描數(shù)碼管客值
  8.     unsigned char disbuff[5]={0};                                                                                                  //顯示緩存
  9.            unsigned char  i =0;                  //定義掃描數(shù)碼管字?jǐn)?shù)
  10.         unsigned int   count1=0;         //計(jì)左電機(jī)碼盤脈沖值

  11. /************************************************************************/
  12. //顯示數(shù)碼管字程序
  13.                  void Display_SMG(void)
  14. {
  15.       if(++i>=4)i=0;
  16.           P0=table[disbuff[i]];

  17.            if(i==0)
  18.           {P2_0=0;P2_1=1;P2_2=1;P2_3=1;}
  19.           if(i==1)
  20.           {P2_0=1;P2_1=0;P2_2=1;P2_3=1;}
  21.           if(i==2)
  22.           {P2_0=1;P2_1=1;P2_2=0;P2_3=1;}
  23.           if(i==3)
  24.           {P2_0=1;P2_1=1;P2_2=1;P2_3=0;}
  25.          
  26. }

  27. /***************************************************/
  28. ///*TIMER0中斷服務(wù)子函數(shù)產(chǎn)生PWM信號(hào)*/
  29.         void timer0()interrupt 1   using 2
  30. {
  31.      TH0=0XF8;          //1Ms定時(shí)
  32.          TL0=0X30;
  33.      Display_SMG();                        //中斷服務(wù)子程序掃描數(shù)碼管
  34. }       
  35. /***************************************************/
  36.         void main(void)
  37. {

  38.         TMOD=0X01;
  39.         TH0= 0XF8;                  //1ms定時(shí)
  40.         TL0= 0X30;
  41.         TR0= 1;
  42.         ET0= 1;
  43.         EA = 1;

  44.         count1=0;                  //初始化人數(shù)為1
  45.         disbuff[0]=count1/1000;
  46.     disbuff[1]=count1%1000/100;
  47.         disbuff[2]=count1%1000%100/10;
  48.         disbuff[3]=count1%1000%100%10;

  49.         while(1)                                                        /*無限循環(huán)*/
  50.         {        
  51.          if(P2_7==0)
  52.          {
  53.            while(!P2_7);
  54.            count1++;
  55.            if(count1>=9999) //計(jì)到99歸零
  56.            count1=0;
  57.            disbuff[0]=count1/1000;
  58.        disbuff[1]=count1%1000/100;
  59.            disbuff[2]=count1%1000%100/10;
  60.            disbuff[3]=count1%1000%100%10;
  61.          }
  62.         }
  63. }
  64.        
復(fù)制代碼

所有資料51hei提供下載:
53.紅外人流量計(jì)數(shù)(數(shù)碼管顯示).rar (11.34 KB, 下載次數(shù): 32)


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

使用道具 舉報(bào)

沙發(fā)
ID:1 發(fā)表于 2019-1-13 00:38 | 只看該作者
補(bǔ)全原理圖或者詳細(xì)說明一下電路連接即可獲得100+黑幣
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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