<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        C51單片機微調SH-20504程序

        作者:周華   來源:本站原創   點擊數:  更新時間:2014年03月27日   【字體:

        /*******************************************************************************************************************
        *       版權歸huaer所有                                                                                                             **
        * 功能:SH-20504控制56BYG250C的單片機程序                                                                                         **
        * 輸出:PWM                                                                                                                           **
        * 輸入:無                                                                                                                               **
        *                                                                                                                                              **
        *電路鏈接:  共陽 (方向+/脫機+/PWM+連接在一起與電源或者是控制I/O相連)                        **
        *                                              |               |                                                                               **
        *                    方向脈沖 P1.0---|               |----P1.3 key1                                                                                    
        *                   PWM脈沖 P1.1---|               |----P1.4 key2
        *                    脫機脈沖 P1.2---|               |----P1.5 key3                                                                           
        *                                              |               |
        * 創作時間:2014.3.25
        * 創作人:  huaer  周-華
        ***************************************************************/
        #include < reg51.h >
        sbit C = P1^0; //方向脈沖
        sbit D = P1^1; //pwm脈沖
        sbit E = P1^2; //脫機脈沖
        sbit key1 = P1^3; //方向開關
        sbit key2 = P1^4; //加速開關
        sbit key3 = P1^5; //減速開關
        void delay(unsigned int d)
        {
           unsigned char i;
           for ( ; d>0; d--)
             for ( i=30; i>0; i--);
        }
        void main ( void )
        {
         unsigned char  v1 = 1;//速度標志\空占比調節
         unsigned char  z = 0;
         while( 1 )
         {
          if ( key1 == 0 )
          {
            delay(100);
            if(key1 == 0)
            {
             while( ~key1 );
           z = 1;  //反轉(默認下正轉)
            }
          }
          else z = 0;
          if( key2 == 0)
          {
             delay(100);
             if(key2 == 0)
               {
               while( ~key2 );
            ++v1;
            }
          }
          if( key3 == 0)
          {
             delay(100);
             if(key3 == 0)
               {
               while( ~key3 );
               --v1;
            }
          }
          if( z == 1)
          {
             C = 0;
             delay(1);
             D = 0;
             delay( v1 );
             D = 1;
             delay( v1 );
             /*
             D = 0;
             delay( v1 );
             E = 0;
             delay( v2 );
             E = 1;
             */
          }
          else {
         
             D = 0;
             delay( v1 );
             D = 1;
             delay( v1 );
             /*
             D = 0;
             delay( v1 );
             E = 0;
             delay( v2 );
             E = 1;
             */
         
         
          }
         }
        }

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮