当走到这句时”while((UTCTL0&0x01)==0x00)“就走不动了
#include <msp430x12x.h>
#include <string.h>
static unsigned char flag = 0; //标志用于延时
static unsigned char j=0; //接收数据的下标
static unsigned char RCV_Byte[100]; //用于接收AT指令返回
static unsigned char sign_r=0; // 接收标志
static unsigned char *s;
static unsigned char *ptr;
//检查硬件是否连通
const unsigned char Cmd0[] = "AT\r" ;
const unsigned char SIGN_END[] = "\r";
//定义SIMEMS GPRS指令
const unsigned char GTM900B_Cmd1[] = "AT+CMGF=1\r" ; //格式化为文本模式
const unsigned char GTM900B_Cmd2[] = "AT+CSCA=+8613800451500\r"; //设置短信中心号码
const unsigned char GTM900B_Cmd3[] = "AT+CMGS=18745045030\r"; //设置接收手机号码
const unsigned char GTM900B_Cmd4[] = "123 CTRL+Z\r"; //发送123
//const unsigned char GTM900B_Cmd5[] = "CTRL+Z\r"; //发送短信
void XT_Init(void); //使用DCO晶体
void Uart0_Init(void); //USART0 初始化
void Send_Cmd(const unsigned char *s);
void Clear_Rcv(void); //清除接受到的数据
void Delay(unsigned int Num); // 精确延时
void Check_Return_OK(unsigned char N1); //是否返回OK
//主程序
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
XT_Init();
sign_r=0;
_EINT();
Uart0_Init();
while(1)
{
P3DIR|=0x40;
P3OUT&=~0x40;
Delay(3276);
P3OUT|=0x40;
//Send_Cmd(Cmd0);
Delay(332768);
Send_Cmd(GTM900B_Cmd1);
Delay(32768);
Send_Cmd(GTM900B_Cmd2);
Delay(32768);
Send_Cmd(GTM900B_Cmd3);
Delay(32768);
Send_Cmd(GTM900B_Cmd4);
Delay(32768);
//Send_Cmd(GTM900B_Cmd5);
//Delay(32768);
while(1)
if(sign_r==1)
{
Delay(32768); // 延迟足够长的时间,以接到指令
}
}
}
//精确延时TIMERA中断延时服务程序
#pragma vector = TIMERA0_VECTOR
__interrupt void timera (void)
{
flag = 1;
CCTL0 &=~ CCIE;
}
//COM0口接收数据中断服务程序
#pragma vector = USART0RX_VECTOR
__interrupt void uart_rx (void)
{
RCV_Byte[j] = RXBUF0;
strstr(RCV_Byte,SIGN_END);
if(ptr)
sign_r=1;
j++;
}
//使用DCO晶震
void XT_Init(void)
{
BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL
BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe)
}
//USART0初始化
void Uart0_Init(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10;
ME2 |= UTXE0 + URXE0; // Enabled USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00;
UMCTL0 = 0x4A; // Modulation
UCTL0 &= ~SWRST; // Initalize USART state machine
IE2 |= URXIE0; // Enabled USART0 RX interrupt
}
//发送指令函数
void Send_Cmd(const unsigned char *s)
{
while(*s != '\r')
{
TXBUF0 = *s;
while((UTCTL0&0x01)==0x00);
s++;
}
TXBUF0 = '\r';
while((UTCTL0&0x01)==0x00);
}
//定时器A初始化
void TimerA_Init(void)
{
TACTL = TASSEL0 + TACLR;
}
//清除接受到的数据
void Clear_Rcv(void)
{
for(j = 100; j > 0 ; j--)
RCV_Byte[j-1] = 0;
}
//精确延时
void Delay(unsigned int Num)
{
CCTL0 |= CCIE;
CCR0 = Num;
TACTL |= MC0;
flag = 0;
}
//是否返回OK
void Check_Return_OK(unsigned char N1)
{
for(j=0; j<100; j++)
if((RCV_Byte[j]=='O')&&(RCV_Byte[j+1]=='K'))
{
sign_r=1;
}
} |