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

          新聞中心

          航模大賽小車程序

          作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
          #include
          #include
          #define c(x)(x*110592/120000)
          unsigned char Ir_Buf[4];
          sbit IRIN = P3^2;
          unsigned char IRCOM[7];
          char k,z;
          void IRdelay(unsigned char x);
          unsigned char keys=0xff;
          sbit m1zheng=P1^0;
          sbit m1fu=P1^1 ;
          sbit m2zheng=P1^2;
          sbit m2fu=P1^3;
          sbit SPK = P3^7;
          unsigned char frq;
          unsigned int flag; // ///////////// wendu
          #define uint unsigned int
          #define uchar unsigned char
          uint Temp_buff;
          uchar g;
          #define nop() _nop_()
          #define _Nop() _nop_()
          sbit DQ =P3^6; //定義DS18B20通信端口
          #define sled_dm_port P0 /*定義數(shù)碼管段碼的控制腳*/
          #define sled_wm_port P2 /*定義數(shù)碼管位碼的控制腳*/
          /*定義數(shù)碼管顯示字符跟數(shù)字的對應(yīng)數(shù)組關(guān)系*/
          uchar code sled_mun_to_char[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
          /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
          /*定義需要點亮的數(shù)碼管*/
          uchar code sled_bit_table[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
          uchar data sled_data[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; /*0-7號SLED緩沖值*/
          uchar data led_lighten_bit=0 ; /*LED燈點亮標(biāo)志位0-7*/
          //延時函數(shù)
          void delay(unsigned int i)
          {
          while(i--);
          }
          //初始化函數(shù)
          Init_DS18B20(void)
          {
          unsigned char x=0;
          DQ = 1; //DQ復(fù)位
          delay(8); //稍做延時
          DQ = 0; //單片機(jī)將DQ拉低
          delay(80); //精確延時 大于 480us
          DQ = 1; //拉高總線
          delay(14);
          x=DQ; //稍做延時后 如果x=0則初始化成功 x=1則初始化失敗
          delay(20);
          }
          //讀一個字節(jié)
          ReadOneChar(void)
          {
          unsigned char i=0;
          unsigned char dat = 0;
          for (i=8;i>0;i--){
          DQ = 0; // 給脈沖信號
          dat>>=1;
          DQ = 1; // 給脈沖信號
          if(DQ) dat|=0x80;
          delay(4);
          }
          return(dat);
          }
          //寫一個字節(jié)
          WriteOneChar(unsigned char dat)
          {
          unsigned char i=0;
          for (i=8; i>0; i--){
          DQ = 0;
          DQ = dat&0x01;
          delay(5);
          DQ = 1;
          dat>>=1;
          }
          }
          //讀取溫度
          ReadTemperature(void)
          {
          unsigned char a=0;
          unsigned char b=0;
          unsigned int t=0;
          float tt=0;
          Init_DS18B20();
          WriteOneChar(0xCC); // 跳過讀序號列號的操作
          WriteOneChar(0x44); // 啟動溫度轉(zhuǎn)換
          Init_DS18B20();
          WriteOneChar(0xCC); //跳過讀序號列號的操作
          WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個寄存器) 前兩個就是溫度
          a=ReadOneChar();
          b=ReadOneChar();
          t=b;
          t<<=8;
          t=t|a;
          tt=t*0.0625; //將溫度的高位與低位合并
          t= tt*10+0.5; //對結(jié)果進(jìn)行4舍5入
          return(t);
          }
          /*1MS為單位的延時程序*/
          void delay_1ms(uchar x)
          {
          uchar j;
          while(x--){
          for(j=0;j<125;j++)
          {;}
          }
          }
          ////////////////wendu
          //==中斷讀取紅外鍵值程序=========================
          void int0(void) interrupt 0
          {
          unsigned char j,k,N=0;
          IRdelay(15);
          if (IRIN==1)
          {
          return;
          }
          //確認(rèn)IR信號出現(xiàn)
          while (!IRIN) //等IR變?yōu)楦唠娖?,跳過9ms的前導(dǎo)低電平信號。
          {IRdelay(1);}
          for (j=0;j<4;j++) //收集四組數(shù)據(jù)
          {
          for (k=0;k<8;k++) //每組數(shù)據(jù)有8位
          {
          while (IRIN) //等 IR 變?yōu)榈碗娖?,跳過4.5ms的前導(dǎo)高電平信號。
          {IRdelay(1);}
          while (!IRIN) //等 IR 變?yōu)楦唠娖?/div>
          {IRdelay(1);}
          while (IRIN) //計算IR高電平時長
          {
          IRdelay(1);
          N++;
          if (N>=30)
          { return;} //0.14ms計數(shù)過長自動離開。
          } //高電平計數(shù)完畢
          IRCOM[j]=IRCOM[j] >> 1; //數(shù)據(jù)最高位補(bǔ)“0”
          if (N>=8) {IRCOM[j] = IRCOM[j] | 0x80;} //數(shù)據(jù)最高位補(bǔ)“1”
          N=0;
          }//end for k
          }//end for j
          keys=IRCOM[2];
          }
          //==0.14ms延時===============================
          void IRdelay(unsigned char x) //x*0.14MS
          {
          unsigned char i;
          while(x--)
          {
          for (i = 0; i<13; i++) {}
          }
          }
          void delayms(unsigned char ms)
          // 延時子程序
          {
          unsigned char i;
          while(ms--)
          {
          for(i = 0; i < 120; i++);
          }
          }
          上一頁 1 2 下一頁

          關(guān)鍵詞: 航模大賽小車程

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁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); })();