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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 單片機紅外遙控+步進電機+1602液晶顯示c語言源程序

          單片機紅外遙控+步進電機+1602液晶顯示c語言源程序

          作者: 時間:2012-12-05 來源:網(wǎng)絡 收藏

          }
          void int0() interrupt 0 using 1
          {
          uint i;
          for(i=0;i4;i++)
          {
          delay1000();
          if(IR_RE==1){k=~k;} //剛開始為4.5ms的引導碼,如果4ms內出現(xiàn)高電平則退出解碼程序
          }

          if(k==0)
          {
          EX0=0; //檢測到有效信號關中斷,防止干擾
          IR_decode(); //如果接收到的是有效信號,則調用解碼程序
          //解碼成功,調用顯示程序,顯示該鍵值
          }
          EX0=1; //開外部中斷,允許新的遙控按鍵
          }
          void main(void)
          {
          InitLcd();//
          DelayMs(15);

          sprintf(Test1,"STEP MOTOR SPEED");//the first line
          ShowString(0,Test1);
          ShowChar(0x19,'r');
          ShowChar(0x1a,'p');
          ShowChar(0x1b,'m');
          count = 0;
          step_index = 0;
          spcount = 0;
          stop_flag = 0;

          P1_0 = 0;
          P1_1 = 0;
          P1_2 = 0;
          P1_3 = 0;
          SP=0x60;
          EA = 1; //允許CPU中斷
          TMOD = 0x11; //設定時器0和1為16位模式1
          ET0 = 1; //定時器0中斷允許
          EX0=1;
          TH0 = 0xFE;
          TL0 = 0x0C; //設定時每隔0.5ms中斷一次
          TR0 = 1; //開始計數(shù)
          turn=0;

          speedlevel=1;

          while(1)
          {
          if(turn==0)
          ShowChar(0x14,'+');
          else
          ShowChar(0x14,'-');
          if(TR0 ==0)
          {
          ShowChar(0x15,'0');
          ShowChar(0x16,'0');
          ShowChar(0x17,'0');
          ShowChar(0x18,'0');
          }
          else
          {
          if(speedlevel==1)
          {
          ShowChar(0x15,'3');
          ShowChar(0x16,'0');
          ShowChar(0x17,'0');
          ShowChar(0x18,'0');
          }
          else if(speedlevel==2)
          {
          ShowChar(0x15,'1');
          ShowChar(0x16,'5');
          ShowChar(0x17,'0');
          ShowChar(0x18,'0');
          }
          else if(speedlevel==3)
          {
          ShowChar(0x15,'1');
          ShowChar(0x16,'0');
          ShowChar(0x17,'0');
          ShowChar(0x18,'0');
          }
          else if(speedlevel==4)
          {
          ShowChar(0x15,'0');
          ShowChar(0x16,'7');
          ShowChar(0x17,'5');
          ShowChar(0x18,'0');
          }
          else if(speedlevel==5)
          {
          ShowChar(0x15,'0');
          ShowChar(0x16,'6');
          ShowChar(0x17,'0');
          ShowChar(0x18,'0');
          }
          }
          }
          }
          //定時器0中斷處理
          void timeint(void) interrupt 1 using 0
          {
          TH0=0xFE;
          TL0=0x0C; //設定時每隔0.5ms中斷一次

          count++;

          spcount--;
          if(spcount=0)
          {
          spcount = speedlevel;
          gorun();
          }

          }

          void delay(unsigned int endcount)
          {
          count=0;
          do{}while(countendcount);
          }

          void gorun()
          {
          if (stop_flag==1)
          {
          P1_0 = 0;
          P1_1 = 0;
          P1_2 = 0;
          P1_3 = 0;
          return;
          }

          switch(step_index)
          {
          case 0: //0
          P1_0 = 1;
          P1_1 = 0;
          P1_2 = 0;
          P1_3 = 0;
          break;
          case 1: //0、1
          P1_0 = 1;
          P1_1 = 1;
          P1_2 = 0;
          P1_3 = 0;
          break;
          case 2: //1
          P1_0 = 0;
          P1_1 = 1;
          P1_2 = 0;
          P1_3 = 0;
          break;
          case 3: //1、2
          P1_0 = 0;
          P1_1 = 1;
          P1_2 = 1;
          P1_3 = 0;
          break;
          case 4: //2
          P1_0 = 0;
          P1_1 = 0;
          P1_2 = 1;
          P1_3 = 0;
          break;
          case 5: //2、3
          P1_0 = 0;
          P1_1 = 0;
          P1_2 = 1;
          P1_3 = 1;
          break;
          case 6: //3
          P1_0 = 0;
          P1_1 = 0;
          P1_2 = 0;
          P1_3 = 1;
          break;
          case 7: //3、0
          P1_0 = 1;
          P1_1 = 0;
          P1_2 = 0;
          P1_3 = 1;
          }

          if (turn==0)
          {
          step_index++;
          if (step_index>7)
          step_index=0;
          }
          else
          {
          step_index--;
          if (step_index0)
          step_index=7;
          }

          }

          紅外遙控器相關文章:紅外遙控器原理

          51單片機相關文章:51單片機教程


          c語言相關文章:c語言教程



          上一頁 1 2 下一頁

          評論


          相關推薦

          技術專區(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); })();