#include"reg52.h"
#include <absacc.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code TC_RST[]={"AT&F"};
uchar code TC_AT[]={"AT"};
uchar code TC_ATE[]={"ATE"};
uchar code TC_CNMI[]={"AT+CNMI=1,1,2;"};
uchar code TC_CMGF[]={"AT+CMGF=1"};
uchar code TC_CMGR[]={"AT+CMGR=1"};
uchar code TC_CMGD[]={"AT+CMGD=1"};
sbit FMQ=P3^6;
sbit K1=P1^4;
sbit L1=P1^0;
sbit L2=P1^1;
sbit L3=P1^2;
sbit L4=P1^3;
sbit L5=P1^5;
#define RxIn 90 //定义接收的数组长度为90
uchar Rx=0;
uchar SystemBuf[RxIn]; //储存出口接收数据 ,数组长度为90
delay_ms(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++);
}
}
void receive(void) interrupt 4 using 1
{
if(RI) //RI:串口接收数据位
{
if(Rx<RxIn)//RXIr是长度为90的数组
{
SystemBuf[Rx]=SBUF; //
Rx++;
}
RI=0;
}
}
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_RST()
{
Print_Str(TC_RST,4);
Print_Char('\r');
ES=1;
delay_ms(500);
}
void GSM_AT()
{
Print_Str(TC_AT,2);
Print_Char('\r');
ES=1;
delay_ms(500);
}
void GSM_ATE()
{
Print_Str(TC_ATE,3);
Print_Char('\r');
ES=1;
delay_ms(500);
}
void GSM_CNMI()
{
Print_Str(TC_CNMI,14);
Print_Char('\r');
ES=1;
delay_ms(500);
}
void GSM_CMGF()
{
Print_Str(TC_CMGF,9);
Print_Char('\r');
ES=1;
delay_ms(500);
}
void GSM_CMGR()
{
Print_Str(TC_CMGR,9);
Print_Char('\r');
ES=1;
delay_ms(500);
}
void GSM_CMGD()
{
Print_Str(TC_CMGD,9);
Print_Char('\r');
ES=1;
delay_ms(500);
}
GSM_ZERO()
{
for(Rx=0;Rx<RxIn;Rx++)
{
SystemBuf[Rx]=0x00; //把SystemBuf[Rx]全部清零,只是作为一个存储器使用。
}
Rx=0;
}
void main()
{
while(1)
{
Ini_UART();
FMQ=1;
P2=0xff;
GSM_RST();
delay_ms(500);
GSM_ATE();
delay_ms(500);
GSM_ZERO();
GSM_AT();
delay_ms(500);
if((SystemBuf[2]=='O')&&(SystemBuf[3]=='K'))
{
L1=0;
GSM_ZERO();
GSM_CNMI();
delay_ms(500);
if((SystemBuf[2]=='O')&&(SystemBuf[3]=='K'))
{
L2=0;
GSM_ZERO();
GSM_CMGF();
delay_ms(500);
if((SystemBuf[2]=='O')&&(SystemBuf[3]=='K'))
{
L3=0;
GSM_ZERO();
//if((SystemBuf[2]=='+')&&(SystemBuf[3]=='C')&&(SystemBuf[4]=='M')&&(SystemBuf[5]=='T')&&(SystemBuf[6]=='I'))
//{
L4=0;
GSM_ZERO();
GSM_CMGR();
delay_ms(500);
if((SystemBuf[2]=='+')&&(SystemBuf[3]=='C')&&(SystemBuf[4]=='M')&&(SystemBuf[5]=='G')&&(SystemBuf[6]=='R')&&(SystemBuf[10]=='R'))
{
L5=0;
GSM_CMGD();
GSM_ZERO();
while(K1)
{
P2=0xfe; //P2.0引脚输出低电平,DS0点亮
P0=0x83; //数字1的段码
delay_ms(15);
P2=0xfd ; //P2.1引脚输出低电平,DS1点亮
P0=0x88; //数字2的段码
delay_ms(15);
P2=0xfb; //P2.2引脚输出低电平,DS2点亮
P0=0xa1; //数字3的段码
delay_ms(15);
}
}
//}
}
}
}
L1=1;
L2=1;
L3=1;
L4=1;
L5=1;
}
}