#include<reg51.h>
#include<string.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit led=P1^0;
sbit led2 = P1^7;
u16 Num = 0;
u8 receive[30];
u8 k;
void delay5ms(void)
{
unsigned char a,b;
for(b=19;b>0;b--)
for(a=130;a>0;a--);
}
void connectinit()
{
char *a="AT+CIPMUX=1\r\n";
char *b="AT+CIPSERVER=1,8080\r\n";
while(*a!='\0')
{
SBUF=*a;
while(!TI);
TI=0;
a++;
}
delay5ms();
while(*b!='\0')
{
SBUF=*b;
while(!TI);
TI=0;
b++;
}
}
void InitUART(void)
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFA; //??????9600
TL1 = 0xFA;
PCON=0X80;
ET1=0;
EA = 1;
ES = 1;
TR1 = 1;
}
void main()
{
int j;
InitUART();
connectinit();
led = 0;
while(1)
{
switch(k)
{
case '1':
led=1;
for(j=0; j<100; j++)
{
delay5ms();
}
break;
case '2':
led=0;
for(j=0; j<100; j++)
{
delay5ms();
}
break;
default:
led2 = 1;
for(j=0; j<100; j++)
{
delay5ms();
}
led2 = 0;
for(j=0; j<100; j++)
{
delay5ms();
}
}
}
}
void Uart() interrupt 4
{
char res;
if(RI==1)
{
res=SBUF;
RI=0;
if(res==':'||Num>0)
{
receive[Num]=res;
Num++;
if(res=='\n')
{
k=receive[1];
SBUF=k;
while(!TI);
TI=0;
Num=0;
memset(receive,0,30);
}
}
}
}
|