|
我也在做,单片机能将At指令通过串口发送,用串口调试助手查看了,TC35i也启动了,而且能完成打电话的的功能,就是发短信不成功。
//单片机控制GSM发短信和打电话程序
#include
#include
#include
#define uint unsigned int
#define uchar unsigned char
unsigned char xdata rec[80];
sbit D10LED=P0^0;
sbit D11LED=P0^1;
sbit SW4=P0^2;
sbit SW5=P0^3;
sbit beeper=P0^4;
sbit J1=P0^6;
sbit J2=P0^7;
sbit START_TC=P3^2; //启动TC35i的控制端
uchar code PhoneCall[]={"ATD13795568363;"};
uchar code PhoneNum[]={"AT+CMGS=\"+8613795568363\""};
uchar code CenterNum[]={"AT+CSCA=\"+8613800813500\""};
uchar code TxtMode[]={"AT+CMGF=0"};
uchar code Sms[] = {"GsmTest"};
uchar code AT[]={"AT"};
uchar ok[]={"00"};
uchar k;
void GSM_OKint() interrupt 4 using 1
{
if(RI==1)
{
RI=0;
ok[k++]=SBUF;
if(k>1)
{k=0;}
}
}
delay(uint ms)// 延时子程序
{
uchar i;
while(ms--)
{
for(i = 0; i < 120; i++);
}
}
delay_Xms(uint t)
{
uint i,j;
for(i=t;i>0;i--)
for(j=113;j>0;j--);
}
/*******************************************************/
Print_Char(uchar ch)//发送单个字符
{
SBUF = ch; //送入缓冲区
while(TI == 0); //等待发送完毕
TI = 0; //软件清零
}
Print_Str(uchar * str,uint len)//发送字符串,调用Send_Char() len字符串长度
{
while(len--)
{
Print_Char(*str++);
}
}
/********************************************************/
Ini_UART(void)//串口初始化、定时器初始化
{
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
SCON = 0x50;
PCON = 0x00;
TF1 = 1;
TR1 = 1;
ES=1;
ET0=1;
EA=1;
}
void GSM_AT()
{
Print_Str(AT,2);
Print_Char('\r');
ES=1;
delay(1000);
}
void GSM_CENTER()
{
Print_Str(CenterNum,24);
Print_Char('\r');
ES=1;
delay(1000);
}
void GSM_TXT()
{
Print_Str(TxtMode,9);
Print_Char('\r');
ES=1;
delay(1000);
}
void GSM_CMGS()
{
Print_Str(PhoneNum,24);
Print_Char('\r');
ES=1;
delay(1000);
}
void GSM_SMS()
{
Print_Str(Sms,7);
Print_Char(0x1a);
ES=1;
delay(5000);
delay(5000);
}
void phone()
{
Print_Str(PhoneCall,15);
Print_Char('\r');
ES=1;
delay(5000);
delay(5000);
}
void main()
{
uint i=0;
Ini_UART(); //串口初始化
beeper=0;
delay_Xms(500);
delay_Xms(500);
beeper=1; //蜂鸣器响一次
D10LED=0;
J1=0;
delay_Xms(2000);
D10LED=1;
J1=1;
D11LED=0;
J2=0;
delay_Xms(2000);
D11LED=1;
J2=1;
START_TC=0;//启动TC35i
delay_Xms(1500);
START_TC=1;//完成启动
while(1)
{
if(i<1)
{
/* while(1)
{
TI=0;
RI=1;
for(i=0;i<9;i++)
rec=0x00; //接收区域清零*/
GSM_AT();
delay(5000);
/*for(i=0;i<9;i++)
{
while(!RI);
rec=SBUF;
RI=0;
} */
delay(5000); //接收SBUF的内容
//if(rec[5]=='O'&&rec[6]=='K')
// break;
//}
GSM_CENTER();
delay(5000);
GSM_TXT();
delay(5000);
GSM_CMGS();
delay(5000);
GSM_SMS();
delay(5000);
delay(5000);
GSM_AT();
phone();
beeper=0;
delay_Xms(500);
delay_Xms(500);
beeper=1; //蜂鸣器响一次
D10LED=0;
delay(50000);
delay(50000);
i++;
}
}
}
|
|