共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 跳转至页
回复
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |
我要赚赏金打赏帖 |
|
|---|---|
| 在FireBeetle2ESP32-C5上实现温湿度检测和显示被打赏¥20元 | |
| 在FireBeetle2ESP32-C5上实现光照强度检测及显示被打赏¥21元 | |
| 以FireBeetle2ESP32-C5实现数据识读播报被打赏¥19元 | |
| 【STM32F103ZET6】14:实测STM32F1的串口输出任务的挂起与恢复功能被打赏¥27元 | |
| Chaos-nano在压力容器监控系统中的项目应用被打赏¥23元 | |
| 基于FireBeetle2ESP32-C5的WS2812B彩色灯带控制被打赏¥21元 | |
| SWM221CBT7显示开发板驱动TFT显示屏被打赏¥19元 | |
| SWM221CBT7显示开发板驱动OLED屏显示被打赏¥19元 | |
| SWM221CBT7显示开发板及其使用被打赏¥20元 | |
| 揭秘Chaos-nano:ArduinoProMini轻量级操作系统开发框架深度解析与实战应用被打赏¥19元 | |
我要赚赏金
