想了大半天 和51对比都晕死了 跪求各位大佬
Yao Zhuang:
void UARTSend(const char *str)//串口0发送{ unsigned int i=8; while(i–) { while (!(UCA0IFG&UCTXIFG));//等闲 UCA0TXBUF=*str++;//发数据 }} 这个算串口的字符串传送可以吗
灰小子:
回复 Yao Zhuang:
可以。你可以自己封装一个printf
Yao Zhuang:
回复 灰小子:
#include<msp430f5529.h>void SerialSendChars(char *str) //传送字符串{
while(*str!='\r') { UCA0TXBUF=*str; while(!(UCA0IFG&UCTXIFG)); str++; }
}void UartPrintASCII(unsigned char c) //发送一个字符{
while(UCTXIFG==0); UCA0TXBUF=c;}void delay_50ms(int t){ int j; for(;t>0;t–) for(j=6245;j>0;j–) ;}void main(){ WDTCTL = WDTPW + WDTHOLD; // Stop WDT P3SEL = BIT3+BIT4; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 6; // 1MHz 9600 (see User's Guide) UCA0BR1 = 0; // 1MHz 9600 UCA0MCTL = UCBRS_0 + UCBRF_13 + UCOS16; // Modln UCBRSx=0, UCBRFx=0, // over sampling UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UCA0IE |= UCTXIE; // Enable USCI_A0 RX interrupt
SerialSendChars("AT\r\n");//先发AT,让GSM模块自动获取波特率为9600 delay_50ms(1000); SerialSendChars("AT+CMGF=1\r\n"); delay_50ms(1000);
SerialSendChars("AT+CSCS=\"GSM\"\r\n"); delay_50ms(1000);
SerialSendChars("AT+CMGS=\"18559061451\"\r\n"); //替换为需要接收短信的号码 delay_50ms(1000);
SerialSendChars("SIM800 MSG SEND TEST"); //英文短信内容 delay_50ms(1000);
UartPrintASCII(0x1a); while(1); __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled}
#pragma vector=USCI_A0_VECTOR__interrupt void USCI_A0_ISR(void){ switch(__even_in_range(UCA0IV,4)) { case 0:break; // Vector 0 – no interrupt case 2: // Vector 2 – RXIFG while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = UCA0RXBUF; // TX -> RXed character break; case 4:break; // Vector 4 – TXIFG default: break; }}
这个怎么不行?