stc8單片機串口2與esp8266連接 我給模塊發at指令的字符串 模塊閃了藍燈,應該是發送到了 但是模塊并沒有執行想要的at指令,求救
#include "stc8.h"
#include "intrins.h"
#define FOSC 11059200UL
#define BRT (65536 - FOSC / 115200 / 4)
sbit LED1=P5^5;
bit busy;
char wptr;
char rptr;
char buffer[16];
void Uart2Isr() interrupt 8 using 1
{
if (S2CON & 0x02)
{
S2CON &= ~0x02;
busy = 0;
}
if (S2CON & 0x01)
{
S2CON &= ~0x01;
buffer[wptr++] = S2BUF;
wptr &= 0x0f;
}
}
void Uart2Init()
{
S2CON = 0x50;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void Uart2Send(char dat)
{
while (busy);
busy = 1;
S2BUF = dat;
}
void Uart2SendStr(char *p)
{
while (*p)
{
Uart2Send(*p++);
}
}
void delay(unsigned int m) //????
{
int a=0,b=0;
for(a=0;a<500;a++)
for(b=0;b<m;b++);
}
void main()
{
Uart2Init();
IE2 = 0x01;
EA = 1;
delay(2000);
Uart2SendStr("AT+CWMODE=2");
Uart2Send('\r');
Uart2Send('\n');
LED1=0;
delay(5000);
Uart2SendStr("AT+CWSAP=\"521\",\"123465789\",1,4");
Uart2Send('\r');
Uart2Send('\n');
delay(5000);
Uart2SendStr("AT+RST");
Uart2Send('\r');
Uart2Send('\n');
while (1)
{
LED1=1;
}
}
|