#include <msp430x14x.h>
//unsigned char Data[6];使用P1.0的中断
unsigned char flag = 0;
void Init_spi(void);
void GSM(void);
void Delay(unsigned int z);
void Send_Cmd(unsigned char *s);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
Init_spi();
_EINT();
}
void Init_spi(void)
{
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME2|= UTXE0 + URXE0; // Enabled USART0 TXD/RXD
IE2|=URXIE0+UTXIE0;//使能RX,TX的中断
U0CTL |= CHAR; // 8-bit character
U0TCTL |= SSEL1;
UBR00 = 0x50; //3MHz--9600
UBR10 = 0x01;
UMCTL0 = 0x00;//
UCTL0&=~SWRST;
P2DIR=0XFF;
P2OUT=0X00;
P1DIR&=~BIT0;
P1IES|=BIT0;
P1IFG&=~BIT0;
P1IE|=BIT0;//中断使能
}
#pragma vector=PORT1_VECTOR
__interrupt void P1_ZHONGDUAN0 (void)
{unsigned int i=50000;
if((P1IFG&0X01)==BIT0)
P2OUT =0XAA;// 向P2OUT送数据//为什么写为取反时是来回动
while(i--);i=50000; while(i--);
GSM();
P1IFG=0;
Delay(5);
P2OUT=0XFF;
}
//发送短信函数
void GSM(void)
{
P2OUT|=~0X01;
Send_Cmd("AT+CSCS="GSM"
");
Delay(3);
P2OUT=0X00;
P2DIR|=0XFF;
P2OUT|=~0x02;//发送GSM成功
Delay(3);
Send_Cmd("AT+CMGF=1
");
Delay(3);
P2OUT=0X00;
P2OUT|=~0x04;//格式选择成功
Delay(3);
Send_Cmd("AT+CMGS="18434361976"
");
Delay(5);
P2OUT=0X00;
P2OUT|=0x08;//输入号码成功
Delay(3);
Send_Cmd("success
");
Delay(5);
TXBUF0 =0x1A; //发送
P2OUT=0X00;//信息成功
while((U0TCTL&0x01)==0x00);
Delay(5);
}
//延时函数
void Delay(unsigned int z)
{
unsigned int i , j= 0;
for(i=0; i<z; i++)
for(j=0; j<65535; j++);
}
//发送函数
void Send_Cmd(unsigned char *s)
{
while(*s != ' ')
{
P2OUT=0X77;
while ((IFG1 & UTXIFG0) == 0); // USART0 TX 缓存器准备好?
TXBUF0 = *s;
// while((U0TCTL&0x01)==0x00); //判断缓冲区是否为空,1为空
s++;
}
//TXBUF0 = ' ';
// while((U0TCTL&0x01)==0x00);
为什么收不到短信,望告知,谢谢喽
此帖出自
小平头技术问答
一周热门 更多>