#include "msp430x24x.h"
#include "intrinsics.H"
char i;
char j;
int addr;
char RES;
void delay (char t)
{
for(i=100;i>0;i--)
{
for(j=100;j>0;j--);
}
}
void PUTCHAR()
{
while(!(IFG2&UCA0TXIFG));
UCA0TXBUF=addr;
delay(15);
while((IFG2&UCA0TXIFG)==0);
}
int UART_Rev()
{
//while((IFG2&UCA0TXIFG)==0);//接收等待
RES=UCA0RXBUF ;//返回接受值
return RES;
}
void init(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3OUT &= ~(BIT4+BIT5);
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600; (104)decimal = 0x068h
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
//UCA0MCTL =0x08;
IE2 |= UCA0RXIE;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
}
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
init();
_EINT();
while(1)
{
for(addr=1;addr<=2;addr++)
{
PUTCHAR();
__delay_cycles(100);
delay(100);
UART_Rev();
delay(10);
if(RES==0X00)
{
PUTCHAR();
}
}
}
}
主机可以发送,从机应答的数据主机没有接受