共2条
1/1 1 跳转至页
msp430,i2c 【求助】关于msp430的模拟i2c
问
谁有这方面的资料或者有c的程序,不用汇编的,在此多谢
答 1:
引用:
答 2:
在此網站資料庫有下載
答 3:
楼上的,俺要一份 sir5163.com
答 4:
elthan888hotmail.com,谢谢啦
答 5:
bennyfwh365.com
答 6:
正好用到,给我也来一份啊,xie0577163.com
答 7:
能否给我一份?
答 8:
楼上各位,资料已经发送,请查收。
答 9:
楼主,我也要一份:)谢谢支持,最近做关于i2c和430的,不过我们有点不同,大家互相交流,谢谢!
答 10:
在网上看到的了,转贴这里。
通用MSP430—I2C程序
发布时间:2004年2月25日
//==================================//
//通用MSP430—I2C程序
//收藏:清风徐徐
//QQ:78779514
//EMAIL:XSL88888TOM.com
//2004.2.4
//===================================//
#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];
static void Delay(unsigned int n)
{
unsigned int i;
for (i=0; i }
void Init(void)
{
SCL_1;
Delay(5);
SDA_1;
Delay(5);
}
void Start(void)
{
SDA_1;
Delay(5);
SCL_1;
Delay(5);
SDA_0;
Delay(5);
SCL_0;
Delay(5);
}
void Stop(void)
{
SDA_0;
Delay(5);
SCL_1;
Delay(5);
SDA_1;
Delay(5);
}
void WriteByte(unsigned char WriteData)
{
unsigned char i;
for (i=0; i<8; i++)
{
SCL_0;
Delay(5);
if (((WriteData >> 7) & 0x01) == 0x01)
{
SDA_1;
}
else
{
SDA_0;
}
Delay(5);
SCL_1;
WriteData = WriteData << 1;
Delay(5);
}
SCL_0;
SDA_1;
Delay(5);
Delay(5);
}
unsigned char ReadByte(void)
{
unsigned char i;
unsigned char TempBit = 0;
unsigned char TempData = 0;
SCL_0;
Delay(5);
SDA_1;
for (i=0; i<8; i++)
{
Delay(5);
SCL_1;
Delay(5);
DIR_IN;
if (SDA_IN == 0x01 /*sda==1*/)
{
TempBit = 1;
}
else
{
TempBit = 0;
}
DIR_OUT;
TempData = (TempData << 1) | TempBit;
SCL_0;
}
Delay(5);
return(TempData);
}
void ReceiveAck(void)
{
unsigned char i = 0;
SCL_1;
Delay(5);
DIR_IN;
while ((SDA_IN == 0x01 /*sda==1*/) && (i < 255)/*调试方便,可以不要*/)
{
i++;
}
DIR_OUT;
SCL_0;
Delay(5);
}
void Acknowledge(void)
{
SCL_0;
Delay(5);
DIR_OUT;
SDA_0;
SCL_1;
Delay(5);
SCL_0;
}
unsigned int ReadWord(unsigned char unit/*address*/)
{
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);
}
void ReadWords(unsigned char unit/*address*/)
{
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);
}
void WriteWord(unsigned char unit/*address*/, 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);
} 答 11: EEPROM读写子程序
经过测试!!包得 答 12: 我不能下载,原来我的资金就是这样被扣完的?! 答 13: 正急需,给我也来一份好吗?多谢!zsj919yahoo.com.cn 答 14: 通用MSP430—I2C程序
发布时间:2004年2月25日
//==================================//
//通用MSP430—I2C程序
//收藏:清风徐徐
//QQ:78779514
//EMAIL:XSL88888TOM.com
//2004.2.4
//===================================//
此程序我试了,我把接口换为P4.1和P4.2后写的不对,读的不对。
上传程序最好是经过测试的,不然还得大家走弯路,不赞成!!1!!!
通用MSP430—I2C程序
发布时间:2004年2月25日
//==================================//
//通用MSP430—I2C程序
//收藏:清风徐徐
//QQ:78779514
//EMAIL:XSL88888TOM.com
//2004.2.4
//===================================//
#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];
static void Delay(unsigned int n)
{
unsigned int i;
for (i=0; i }
void Init(void)
{
SCL_1;
Delay(5);
SDA_1;
Delay(5);
}
void Start(void)
{
SDA_1;
Delay(5);
SCL_1;
Delay(5);
SDA_0;
Delay(5);
SCL_0;
Delay(5);
}
void Stop(void)
{
SDA_0;
Delay(5);
SCL_1;
Delay(5);
SDA_1;
Delay(5);
}
void WriteByte(unsigned char WriteData)
{
unsigned char i;
for (i=0; i<8; i++)
{
SCL_0;
Delay(5);
if (((WriteData >> 7) & 0x01) == 0x01)
{
SDA_1;
}
else
{
SDA_0;
}
Delay(5);
SCL_1;
WriteData = WriteData << 1;
Delay(5);
}
SCL_0;
SDA_1;
Delay(5);
Delay(5);
}
unsigned char ReadByte(void)
{
unsigned char i;
unsigned char TempBit = 0;
unsigned char TempData = 0;
SCL_0;
Delay(5);
SDA_1;
for (i=0; i<8; i++)
{
Delay(5);
SCL_1;
Delay(5);
DIR_IN;
if (SDA_IN == 0x01 /*sda==1*/)
{
TempBit = 1;
}
else
{
TempBit = 0;
}
DIR_OUT;
TempData = (TempData << 1) | TempBit;
SCL_0;
}
Delay(5);
return(TempData);
}
void ReceiveAck(void)
{
unsigned char i = 0;
SCL_1;
Delay(5);
DIR_IN;
while ((SDA_IN == 0x01 /*sda==1*/) && (i < 255)/*调试方便,可以不要*/)
{
i++;
}
DIR_OUT;
SCL_0;
Delay(5);
}
void Acknowledge(void)
{
SCL_0;
Delay(5);
DIR_OUT;
SDA_0;
SCL_1;
Delay(5);
SCL_0;
}
unsigned int ReadWord(unsigned char unit/*address*/)
{
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);
}
void ReadWords(unsigned char unit/*address*/)
{
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);
}
void WriteWord(unsigned char unit/*address*/, 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);
} 答 11: EEPROM读写子程序
经过测试!!包得 答 12: 我不能下载,原来我的资金就是这样被扣完的?! 答 13: 正急需,给我也来一份好吗?多谢!zsj919yahoo.com.cn 答 14: 通用MSP430—I2C程序
发布时间:2004年2月25日
//==================================//
//通用MSP430—I2C程序
//收藏:清风徐徐
//QQ:78779514
//EMAIL:XSL88888TOM.com
//2004.2.4
//===================================//
此程序我试了,我把接口换为P4.1和P4.2后写的不对,读的不对。
上传程序最好是经过测试的,不然还得大家走弯路,不赞成!!1!!!
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |