专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
关于msp430g2231控制外部eeprom
2019-03-24 13:34
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
4721
11
1410
我选用的外部eeprom是24c64,之前所用单片机是使用usci模块完成的,但是在g系列只有usi模块,
请问只种情况下如何控制外部eeprom,能否提供一些关键代码,谢谢
此帖出自
小平头技术问答
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
11条回答
457887107
2019-03-25 07:31
#include "msp430g2553.h"
//#include "5110/nokia_5110.h"
#include "stdio.h"
char str[100];
void delay(unsigned int ms)
{
unsigned int x,y;
for(x=ms;x>0;x--)
for(y=1140;y>0;y--);
}
unsigned char rx1,rx2;
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// LCD_init();
// LCD_clear();
// LCD_write_english_string(0,0,"TEST");
// sprintf(str, "%x", 255);
// LCD_write_english_string(0,1,str);
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x50; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
// IE2 |= UCB0RXIE; // Enable RX interrupt
// IE2 |= UCB0TXIE;
//TACCTL0 = CCIE; // TACCR0 interrupt enabled
//TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
while(1)
{
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x0f6;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x00f;
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
//__delay_cycles(1000);
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x0f6;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x000;
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x001;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x0ab;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x002;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x0cd;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x001; //eeprom 00h-3fh
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0CTL1 &= ~UCTR;
IFG2 &= ~UCB0TXIFG;
UCB0CTL1 |= UCTXSTT; //接收模式
//_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();
while (UCB0CTL1 & UCTXSTT);
while ( (IFG2 & UCB0RXIFG)==0 );
rx1 = UCB0RXBUF;
//IFG2 &=~ UCB0RXIFG;
//while ( (IFG2 & UCB0RXIFG)==0 );
UCB0CTL1 |= UCTXSTP;
rx2 = UCB0RXBUF;
__delay_cycles(100);
if((rx1 == 0xab)&&(rx2 == 0xab))
{
P1DIR |= BIT0;
P1OUT |= BIT0;
}
else
{
P1DIR |= BIT0;
P1OUT &= ~BIT0;
}
}
return 0;
}
加载中...
查看其它11个回答
一周热门
更多
>
相关问题
相关文章
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
//#include "5110/nokia_5110.h"
#include "stdio.h"
char str[100];
void delay(unsigned int ms)
{
unsigned int x,y;
for(x=ms;x>0;x--)
for(y=1140;y>0;y--);
}
unsigned char rx1,rx2;
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// LCD_init();
// LCD_clear();
// LCD_write_english_string(0,0,"TEST");
// sprintf(str, "%x", 255);
// LCD_write_english_string(0,1,str);
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x50; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
// IE2 |= UCB0RXIE; // Enable RX interrupt
// IE2 |= UCB0TXIE;
//TACCTL0 = CCIE; // TACCR0 interrupt enabled
//TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
while(1)
{
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x0f6;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x00f;
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
//__delay_cycles(1000);
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x0f6;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x000;
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x001;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x0ab;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x002;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0TXBUF = 0x0cd;
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0CTL1 |= UCTXSTP;
delay(100);
UCB0CTL1 |= UCTR + UCTXSTT;
UCB0TXBUF = 0x001; //eeprom 00h-3fh
while (UCB0CTL1 & UCTXSTT);
__delay_cycles(100);
UCB0CTL1 &= ~UCTR;
IFG2 &= ~UCB0TXIFG;
UCB0CTL1 |= UCTXSTT; //接收模式
//_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();
while (UCB0CTL1 & UCTXSTT);
while ( (IFG2 & UCB0RXIFG)==0 );
rx1 = UCB0RXBUF;
//IFG2 &=~ UCB0RXIFG;
//while ( (IFG2 & UCB0RXIFG)==0 );
UCB0CTL1 |= UCTXSTP;
rx2 = UCB0RXBUF;
__delay_cycles(100);
if((rx1 == 0xab)&&(rx2 == 0xab))
{
P1DIR |= BIT0;
P1OUT |= BIT0;
}
else
{
P1DIR |= BIT0;
P1OUT &= ~BIT0;
}
}
return 0;
}
一周热门 更多>