本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include "reg52.h"
#include "string.h"
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar RsBuf[24];
uchar FlagRs = 0;
char code Init_Tc35i[] = "^SYSSTART";
char code AT_Tc35i[] = "AT+"; //连机
//char code Bps_Tc35[]="IPR=9600";
uchar code AT_CSCA[]="AT+CSCA=13800200500";
uchar code AT_CMGF[]="AT+CMGF=1";
char code Send_Tc35i[] = "CMGS="; //发送信息
char code AT_Code[]="OK";
char code SK[]=">";
char code PhonNum[] = "13535058054";
char code Test[] = "test123";
bit fa=0;
//延时t毫秒
void Delay(uchar t)
{
uint i;
while(t--)
{
for(i=0;i<125;i++)
{}
}
}
//串口初始化
void InitCom(void)
{
SCON = 0x50;//串口方式1,8位UART
TMOD = 0x20;//定时器T1,工作方式2,8位重载
PCON = 0x00;//波特率加倍
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1; //T1开始
ES = 1;
}
//发送一个ASCII
void SendASC(uchar ASC)
{
bit es;
es = ES;
ES = 0;
TI = 0;
SBUF = ASC;
while(!TI);
TI = 0;
ES = es;
}
//发送命令到Tc35i
void SendComTc35i(uchar *p,uchar Long)
{
while(Long--)
{
SendASC(*p++);
}
}
// 通讯中断接收程序
void Rs232_Rxd(void) interrupt 4 using 1
{
if(RI==1)
{
RI=0;
RsBuf[FlagRs++]=SBUF;
if(FlagRs>=sizeof(RsBuf))
{
FlagRs=0;
}
}
}
//搜索Tc35i
/*void Search_Tc35i(void)
{
uchar *p;
while(1)
{
ES = 1;
p = strstr(RsBuf,Init_Tc35i);
if(p != NULL) break;
}
}*/
//清缓冲区
void ClrRsBuf()
{
uchar len;
len = strlen(RsBuf);
while(len--)
{
RsBuf[FlagRs++] = 0;
}
}
// 发送AT连机命令
void Send_AT(void)
{
uchar *p;
while(1)
{
ClrRsBuf();
SendComTc35i(AT_Tc35i,2); //"AT"
SendASC(0x0d);
ES=1; //等待应答"OK"
Delay(1000);
Delay(1000);
p=strstr(RsBuf,AT_Code);
if(p!=NULL) break;
}
}
//发送bps连机命令
/*void Send_BPS(void)
{
SendComTc35i(AT_Tc35i,3); //"AT+"
SendComTc35i(Bps_Tc35,sizeof(Bps_Tc35)-1);//"IPR=19200"
SendASC(0x0d);
}*/
//发送短信息
void SendMsgStart(void)
{
uchar *p,i=250;
SendComTc35i(AT_Tc35i,3); //"AT+"
SendComTc35i(Send_Tc35i,sizeof(Send_Tc35i)-1);//"AT+CMGS="
SendASC(0x22);
SendComTc35i(PhonNum,sizeof(PhonNum)-1);
SendASC(0x22); //"AT+CMGS="PhonNum""
SendASC(0x0d);
ES=1;
while(i--)
{
Delay(1500); //Get">"
p=strstr(RsBuf,SK);//">"
if(p!=NULL)
{
ClrRsBuf();
Delay(1000); //Get">"
break;
}
}
}
void main(void)
{
while(1)
{
if(fa==0)
{EA = 1;
InitCom();
Delay(1000);
/*Search_Tc35i();
Delay(1000);*/
Send_AT();
Delay(1000);
//Send_BPS();
//ES=1;
//Delay(1000);
//ClrRsBuf();
SendComTc35i(AT_CSCA,19);
SendASC(0x0d);
ES=1;
Delay(1000);
ClrRsBuf();
SendComTc35i(AT_CMGF,9);
SendASC(0x0d);
ES=1;
Delay(1000);
ClrRsBuf();
SendMsgStart();
Delay(1000);
SendComTc35i(Test,sizeof(Test)-1);
SendASC(0x1a);
fa=1;}
}
} |