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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > MSP430模擬IIC接口程序

          MSP430模擬IIC接口程序

          作者: 時間:2016-11-22 來源:網(wǎng)絡(luò) 收藏
          1-簡介
          MSP430單片機(jī)普通II模擬IIC接口程序范例。

          2-程序例程

          #include "MSP430x14x.h"

          //P3.2 SCL

          //P3.3 SDA

          #define SDA_1 P3OUT |= BIT3 //SDA = 1

          #define SDA_0 P3OUT &=~ BIT3 //SDA = 0

          #define SCL_1 P3OUT |= BIT2 //SCL = 1

          #define SCL_0 P3OUT &=~ BIT2 //SCL = 0

          #define DIR_IN P3DIR &=~ BIT3; SDA_1//I/O口為輸入

          #define DIR_OUT P3DIR |= BIT3 //I/0口為輸出

          #define SDA_IN ((P3IN >> 3) & 0x01) //Read SDA

          unsigned int a[50];

          /
          {
          TempBit = 1;
          }
          else
          {
          TempBit = 0;
          }
          DIR_OUT;
          TempData = (TempData << 1) | TempBit;
          SCL_0;
          }
          Delay(5);
          return(TempData);
          }

          /) && (i < 255))
          {
          i++;
          }
          DIR_OUT;
          SCL_0;
          Delay(5);
          }

          /)
          {
          unsigned char HighData = 0;
          unsigned char LowData = 0;
          unsigned int TempData = 0;
          Start();
          WriteByte(0xa0);
          ReceiveAck();
          WriteByte(unit);
          ReceiveAck();
          Start();
          WriteByte(0xa1);
          ReceiveAck();
          LowData = ReadByte();
          Acknowledge();
          HighData = ReadByte();
          Stop();
          TempData = (HighData << 8) + LowData;
          Delay(1000);
          return(TempData);
          }

          /
          {
          unsigned char i;
          unsigned char HighData = 0;
          unsigned char LowData = 0;
          unsigned int TempData = 0;
          Start();
          WriteByte(0xa0);
          ReceiveAck();
          WriteByte(unit);
          ReceiveAck();
          Start();
          WriteByte(0xa1);
          ReceiveAck();
          for (i=0; i<49; i++)
          {
          LowData = ReadByte();
          Acknowledge();
          HighData = ReadByte();
          Acknowledge();
          a[i]= (HighData << 8) + LowData;
          }
          LowData = ReadByte();
          Acknowledge();
          HighData = ReadByte();
          Stop();
          a[49] = (HighData << 8) + LowData;
          Delay(1000);
          }

          /, unsigned int WriteData)
          {
          unsigned char LowData = 0;
          unsigned char HighData = 0;
          LowData = (unsigned char)WriteData;
          HighData = (unsigned char)(WriteData >> 8);
          Start();
          WriteByte(0xa0);
          ReceiveAck();
          WriteByte(unit);
          ReceiveAck();
          WriteByte(LowData);
          ReceiveAck();
          WriteByte(HighData);
          ReceiveAck();
          Stop();
          Delay(2000);
          }
          //******************************************************************************


          關(guān)鍵詞: MSP430模擬IIC接口程

          評論


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