<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統 > 設計應用 > 51單片機外部中斷程序

          51單片機外部中斷程序

          作者: 時間:2016-11-18 來源:網絡 收藏
          /*以下是能在keilC 中變異的源碼,直接粘貼過去就行,外部中斷0(INT0)和外部中斷1都有(INT1)*/

          /*程序很簡單,但是對新手來說還是很實用的*/

          本文引用地址:http://www.ex-cimer.com/article/201611/315862.htm

          /*******************************************************************/
          /* */
          /* 單片機開發(fā)系統演示程序 - INT0 INT1 中斷計數 */
          /* */
          /* 6位數碼管顯示 */
          /* */
          /* */
          /*******************************************************************/

          #include < reg51.h >
          #include

          #define uchar unsigned char
          #define uint unsigned int

          unsigned char code LEDData[ ] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,
          0x82,0xF8,0x80,0x90,0xff};

          unsigned char data display[8] = {0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00};

          unsigned char code scan_bit[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

          unsigned char count0,count1,temp=0 ;

          /********************************************************
          * *
          * 延時函數 *
          * *
          ********************************************************/
          void delay(uint ms)
          // 延時子程序
          {
          uchar k;
          while(ms--)
          {
          for(k = 0; k < 100; k++);
          }
          }

          /********************************************************
          * *
          * 數據處理與顯示函數 *
          * *
          ********************************************************/
          void disp_count()
          {
          char n;

          temp=count0;

          display[2]=temp/100; //數據處理
          temp=temp%100;
          display[1]=temp/10;
          display[0]=temp%10;

          if(display[2]==0) //高位為0,不顯示
          {
          display[2]=0x0a;
          if(display[1]==0)
          display[1]=0x0a;
          }

          temp=count1;

          display[7]=temp/100; //數據處理
          temp=temp%100;
          display[6]=temp/10;
          display[5]=temp%10;

          if(display[7]==0) //高位為0,不顯示
          {
          display[7]=0x0a;
          if(display[6]==0)
          display[6]=0x0a;
          }

          for(n=0;n<8;n++)
          {
          P0 =LEDData[display[n]] ; //顯示段碼
          P2 =scan_bit[n]; //輸出位碼
          delay(1);
          P2 = 0xff; //關閉顯示
          }
          }

          /********************************************************
          * *
          * 主程序 *
          * *
          ********************************************************/
          void main(void)
          {
          P0=0xff;
          P1=0xff;
          P2=0xff;

          IT0=0; //低電平觸發(fā)
          // IT0=1; //下降沿觸發(fā)
          IT1=0; //低電平觸發(fā)
          // IT1=1; //下降沿觸發(fā)
          PX0=1;
          EA=1;
          EX1=1;
          EX0=1;

          while(1)
          {
          disp_count();
          }
          }

          /********************************************************
          * *
          * INT0中斷函數 *
          * *
          ********************************************************/
          void counter0(void) interrupt 0
          {
          uchar x;
          EX0=0;
          count0++;

          for(x=0;x<10;x++)
          {
          disp_count();
          }
          EX0=1;
          }

          /********************************************************
          * *
          * INT1中斷函數 *
          * *
          ********************************************************/
          void counter1(void) interrupt 2
          {
          uchar x;
          EX1=0;
          count1++;

          for(x=0;x<10;x++)
          {
          disp_count();
          }
          EX1=1;
          }

          /********************************************************/



          關鍵詞: 51單片機外部中

          評論


          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();