新聞中心

MSP430模擬IIC接口程序

作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò) 收藏
1-簡(jiǎn)介
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接口程

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉