REN=1; //使能串口允许接收
SM0=0; //工作在串口的工作方式1
SM1=1;
ES=0; //串口中断关闭,待初始化后再打开
EA=1; //总中断打开
for (a=0; a<8000; a++);
printf ("AT+RST\n"); //SendString(esp_at);
do{
if(RI)
{
ldat=SBUF;
RI=0;
if (ldat=='K')
d=0;
}
}while (d);
d =1;
for (a=0; a<1000; a++);
printf ("AT+CWMODE=2\n"); //SendString(esp_cwmode);
do{
if(RI)
{
ldat=SBUF;
RI=0;
if (ldat=='K')
d=0;
}
}while (d);
d =1;
for (a=0; a<1000; a++);
printf ("AT+CIPMUX=1\n"); // SendString(esp_cipmux);
do{
if(RI)
{
ldat=SBUF;
RI=0;
if (ldat=='K')
d=0;
}
}while (d);
d =1;
for (a=0; a<1000; a++);
printf ("AT+CIPSERVER=1,8080\n"); //SendString(esp_cipserver);
do{
if(RI)
{
ldat=SBUF;
RI=0;
if (ldat=='K')
d=0;
}
}while (d);
d =1;
for (a=0; a<10000; a++);
ES=1; //串行口中断打开
}
void remote_control(unsigned char ldat)
{
unsigned int a;
switch(ldat)
{
case '1': //感叹号表示1楼,当然你也可以用其他表示方式,你也可以先接收到1,然后再进行其他的判断
printf ("AT+CIPSEND=0,19\n"); //发送语句的命令 //SendString(esp_cwmode);
for (a=0; a<10000; a++);
printf ("%c\nturn on the light"); //需要发送的语句
led=0X80;
break;
case '2':
printf ("AT+CIPSEND=0,20\n");
for (a=0; a<10000; a++);
printf("%c\nturn off the lights");
led=0X40;
break;
case '3':
printf ("AT+CIPSEND=0,18\n");
for (a=0; a<10000; a++);
printf("%c\nopen the window");
led=0X20;
break;
case '4':
printf("AT+CIPSEND=0,19\n");
for (a=0; a<10000; a++);
printf ("%c\nclose the window");
led=0X10;
break;
case '5':
printf ("AT+CIPSEND=0,19\n");
for (a=0; a<10000; a++);
printf ("%c\nopen the exhaust");
led=0X08;
break;
case '6':
printf ("AT+CIPSEND=0,20\n");
for (a=0; a<10000; a++);
printf ("%c\nclose the exhaust");
led=0X04;
break;
case '7':
printf ("AT+CIPSEND=0,20\n");
for (a=0; a<10000; a++);
printf ("%c\nclose the exhaust");
led=0X20;
break;
case '8':
printf ("AT+CIPSEND=0,20\n");
for (a=0; a<10000; a++);
printf("%c\nclose the exhaust");
led=0XFF;
break;
}
ES=0;
}