完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我想实现单片机和电脑串口通信,就是用串口助手发一串字符给单片机,然后单片机接到了再发给电脑。现在问题出在,我想将单片机接收到的字符串放在数组里,没放进去不知道为什么,,,求教大神,,,不胜感激 #include "msp430g2553.h" unsigned char string1[]; unsigned int i; unsigned char flag,flag1; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT while(1) { BCSCTL1 = CALBC1_1MHZ; // Set DCO DCOCTL = CALDCO_1MHZ; P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 104; // 1MHz 9600 UCA0BR1 = 0; // 1MHz 9600 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // 开收中断 _EINT(); // __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled if(flag==1) //接收完毕 { flag=0; IE2 |= UCA0TXIE; // 开发中断 } if(flag1==1) //发送完毕 { flag1=0; IE2 &= ~UCA0TXIE; // 关发中断 } } } // Echo back RXed character, confirm TX buffer is ready first #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? do{ string1[i++]=UCA0RXBUF; //接收 } while(string1[++i]!=' |