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

          新聞中心

          MSP430與DS18B20之1602顯示

          作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏
          #include

          typedef unsigned char uchar;
          typedef unsigned int uint;
          /**************宏定義***************/
          #define DataDir P4DIR
          #define DataPort P4OUT
          #define Busy 0x80
          #define CtrlDir P3DIR
          #define CLR_RS P3OUT&=~BIT0; //RS = P3.0
          #define SET_RS P3OUT|=BIT0;
          #define CLR_RW P3OUT&=~BIT1; //RW = P3.1
          #define SET_RW P3OUT|=BIT1;
          #define CLR_EN P3OUT&=~BIT2; //EN = P3.2
          #define SET_EN P3OUT|=BIT2;

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

          #define DQ1 P1OUT |= BIT6
          #define DQ0 P1OUT &= ~BIT6
          #define DQ_in P1DIR &= ~BIT6
          #define DQ_out P1DIR |= BIT6
          #define DQ_val (P1IN & BIT6)
          uint tvalue;
          uchar tflag;
          uchar disdata[4];

          /*******************************************
          函數(shù)名稱:Delay5ms
          功 能:延時(shí)約5ms
          參 數(shù):無
          返回值 :無
          ********************************************/
          void Delay5ms(void)
          {
          uint i=40000;
          while (i != 0)
          {
          i--;
          }
          }
          /*******************************************
          函數(shù)名稱:DelayNus
          功 能:實(shí)現(xiàn)N個(gè)微秒的延時(shí)
          參 數(shù):n--延時(shí)長度
          返回值 :無
          說明 :定時(shí)器A的計(jì)數(shù)時(shí)鐘是1MHz,CPU主頻8MHz
          所以通過定時(shí)器延時(shí)能夠得到極為精確的
          us級(jí)延時(shí)
          ********************************************/
          void DelayNus(uint n)
          {
          CCR0 = n;
          TACTL |= MC_1; //增計(jì)數(shù)到CCR0
          while(!(TACTL & BIT0)); //等待
          TACTL &= ~MC_1; //停止計(jì)數(shù)
          TACTL &= ~BIT0; //清除中斷標(biāo)志
          }
          /*******************************************
          函數(shù)名稱:WaitForEnable
          功 能:等待1602液晶完成內(nèi)部操作
          參 數(shù):無
          返回值 :無
          ********************************************/
          void WaitForEnable(void)
          {
          P4DIR &= 0x00; //將P4口切換為輸入狀態(tài)
          CLR_RS;
          SET_RW;
          _NOP();
          SET_EN;
          _NOP();
          _NOP();

          while((P4IN & Busy)!=0); //檢測(cè)忙標(biāo)志
          CLR_EN;
          P4DIR |= 0xFF; //將P4口切換為輸出狀態(tài)
          }
          /*******************************************
          函數(shù)名稱:write_com
          功 能:向液晶模塊寫入命令
          參 數(shù):cmd--命令,
          chk--是否判忙的標(biāo)志,1:判忙,0:不判
          返回值 :無
          ********************************************/
          void write_com(uchar cmd)
          {
          WaitForEnable(); // 檢測(cè)忙信號(hào)?

          CLR_RS;
          CLR_RW;
          _NOP();
          DataPort = cmd; //將命令字寫入數(shù)據(jù)端口
          _NOP();

          SET_EN; //產(chǎn)生使能脈沖信號(hào)
          _NOP();
          _NOP();
          CLR_EN;
          }

          /*******************************************
          函數(shù)名稱:write_data
          功 能:向液晶顯示的當(dāng)前地址寫入顯示數(shù)據(jù)
          參 數(shù):data--顯示字符數(shù)據(jù)
          返回值 :無
          ********************************************/
          void write_data( uchar data )
          {
          WaitForEnable(); //等待液晶不忙
          SET_RS;
          CLR_RW;
          _NOP();
          DataPort = data; //將顯示數(shù)據(jù)寫入數(shù)據(jù)端口
          _NOP();
          SET_EN; //產(chǎn)生使能脈沖信號(hào)
          _NOP();
          _NOP();
          CLR_EN;
          }

          void zifuchuan(uchar *ch)
          {
          while(*ch!=0)
          write_data(*ch++);
          Delay5ms();
          }

          /*******************************************
          函數(shù)名稱:LcdReset
          功 能:對(duì)1602液晶模塊進(jìn)行復(fù)位操作
          參 數(shù):無
          返回值 :無
          ********************************************/
          void LcdReset(void)
          {
          CtrlDir |= 0x07; //控制線端口設(shè)為輸出狀態(tài)
          DataDir = 0xFF; //數(shù)據(jù)端口設(shè)為輸出狀態(tài)

          write_com(0x38); //規(guī)定的復(fù)位操作
          Delay5ms();
          write_com(0x38);
          Delay5ms();
          write_com(0x38);
          Delay5ms();
          write_com(0x38); //顯示模式設(shè)置
          write_com(0x08); //顯示關(guān)閉
          write_com(0x01); //顯示清屏
          write_com(0x06); //寫字符時(shí)整體不移動(dòng)
          write_com(0x0c); //顯示開,不開游標(biāo),不閃爍
          }

          /*******************************************
          函數(shù)名稱:Init_18B20
          功 能:對(duì)DS18B20進(jìn)行復(fù)位操作
          參 數(shù):無
          返回值 :初始化狀態(tài)標(biāo)志:1--失敗,0--成功
          ********************************************/
          uchar Init_18B20(void)
          {
          uchar Error;

          DQ_out;
          _DINT();
          DQ0;
          DelayNus(500);
          DQ1;
          DelayNus(55);
          DQ_in;
          _NOP();
          if(DQ_val)
          {
          Error = 1; //初始化失敗
          }
          else
          {
          Error = 0; //初始化成功
          }
          DQ_out;
          DQ1;
          _EINT();

          DelayNus(400);

          return Error;
          }


          上一頁 1 2 下一頁

          關(guān)鍵詞: MSP430DS18B201602顯

          評(píng)論


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