//STC15W408AS单片机程序源代码如下:
//QQ:9173002 STC15W408AS @11.0592MHZ
#include <reg52.h>
#include "intrins.h"
typedef unsigned int u16;
typedef unsigned char u8;
sfr P5 = 0xc8;
sfr AUXR = 0x8E;
sfr T2H = 0xD6;
sfr T2L = 0xD7;
sbit LED1=P1^2;
sbit LED2=P1^5;
sbit LED3=P5^5;
u8 receive[2];
u8 sign=0;
void Delay1000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 8;
j = 1;
k = 243;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Init()//115200bps@11.0592MHz
{
SCON = 0x50;
AUXR |= 0x01;
AUXR |= 0x04;
T2L = 0xE8;
T2H = 0xFF;
AUXR |= 0x10;
TR1 = 1;
}
void send(u8 value)
{
ES=0;
TI=0;
SBUF=value;
while(!TI);
TI=0;
ES=1;
}
void wifi_init()
{
u8 j=0;
u8 a[]="AT+CWMODE=2\r\n"; //1=station 2=ap 3=station+ap
u8 b[]="AT+CIOBAUD=115200\r\n";//BAND
u8 c[]="AT+CWSAP_DEF=\"My_8266\",\"1234567890\",1,0,3,0\r\n"; //set wifi
u8 d[]="AT+CIPMUX=1\r\n";
u8 e[]="AT+CIPSERVER=1,1111\r\n";
j=0;
while(a[j]!='\0')
{
send(a[j]);
j++;
}
j=0;
Delay1000ms();
while(b[j]!='\0')
{
send(b[j]);
j++;
}
Delay1000ms();
j=0;
while(c[j]!='\0')
{
send(c[j]);
j++;
}
Delay1000ms();
j=0;
while(d[j]!='\0')
{
send(d[j]);
j++;
}
Delay1000ms();
j=0;
while(e[j]!='\0')
{
send(e[j]);
j++;
}
Delay1000ms();
}
void wifi_data()
{
if(receive[0]=='A')
{
LED1=0;
}
if(receive[0]=='B')
{
LED1=1;
}
if(receive[0]=='C')
{
LED2=0;
}
if(receive[0]=='D')
{
LED2=1;
}
if(receive[0]=='E')
{
LED1=0;
LED2=0;
}
if(receive[0]=='F')
{
LED1=1;
LED2=1;
}
}
void main()
{
Init();
EA = 1;
ES = 0;
wifi_init();
while(1)
{
wifi_data();
}
}
void ZD() interrupt 4
{
LED3=~LED3;
if(RI)
{
RI=0;
if(sign==1)
{
receive[0]=SBUF;
sign=0;
}
if(SBUF==':')
{
sign=1;
}
}
}
//程序的主要算法来自 网友 a1bc2de3f
|