下面是我写的代码,不知错在哪,敬请指正。
#include
#define uchar unsigned char
#define uint unsigned int
uchar flag,i;
uchar temp;
uchar j=0;
uchar m=0;
sbit led1=P1^0;
sbit led2=P1^1;
uchar volatile table1[100]=0;
uchar volatile tableat[100]=0;
void delay(uint count) //delay
{
uint i;
while(count)
{
i=200;
while(i0)
i--;
count--;
}
}
void SerialInit() {
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
EA=1;
ES=1;
}
void SerialSendChars(char *str)
{
while(*str!='\0')
{
SBUF=*str;
while(!TI);//等待发送完成信号(TI=1)出现
TI=0;
str++;
}
}
void main()
{
char add[2]={13,'\0'};
SerialInit();
ES=0;
SerialSendChars("ati\r");//ati初始化sim300模块
delay(550);
SerialSendChars("ati\r");//ati初始化sim300模块
delay(550);
SerialSendChars("ati\r");//ati初始化sim300模块
delay(550);
ES=1;
while(1)
{
if(flag==1)
{
if(tableat[0] == 'R' && tableat[1] == 'I' && tableat[2] == 'N' && tableat[3] == 'G')
{
led1=0;
}
if(tableat[0] == 'N' && tableat[1] == 'O' && tableat[2] == ' ' && tableat[3] == 'C' &&tableat[4] == 'A')
{
led2=0;
}
i = 0;
while(tableat[i] != 0)
{
tableat[i] = 0;
i++;
}
flag=0;
}
}
}
void ser() interrupt 4
{
if(RI == 1){
RI=0;
temp=SBUF;
table1[j]=temp;
j++;
if(j=99) j=0;
if(table1[j-2]==0x0d&&table1[j-1]==0x0a&&j=2)
{
j=0;
flag=1;
m=0;
while(table1[m]!=0){
tableat[m]=table1[m];
table1[m]=0;
m++;
}
}
}
}