是这样的,我设置好了C8051F020单片机串口的配置,波特率也设置成了115200与模块对应了。但是我把两个串口连接时,模块的红灯蓝灯都一直亮着,有谁知道这是怎么了吗?
然后我比较笨,我觉得直接让单片机
printf ("AT+CWMODE=2\n");
printf ("AT+RST\n");
printf ("AT+CIPMUX=1\n");
printf ("AT+CIPSERVER=1:8080\n");
就可以将这些AT指令发给ESP8266了,我的想法对吗?
C8052F020单片机的完整代码是这样子的:
#include "ZLG7289.h"
#include <stdio.h>
unsigned char data1;
unsigned char c;
void SYSCLK_Init();
void PORT_Init();
void UART0_Init();
/*********ÑÓʱº¯Êý*********/
void DelayMs(unsigned int i)
{
unsigned int j;
for(;i>0;i--)
for(j=1000;j>0;j--) ;
}
/*********ʱÖÓ³õʼº¯Êý*********/
void SYSCLK_Init()
{
unsigned int i;
OSCXCN=0X67; //0X67=0110,0111
for(i=0;i<256;i++); //µÈ´ý>1ms
while(!(OSCXCN&0X80)); //µÈ´ýXTLVLD±äΪ1
OSCICN=0X88; //ʱÖÓʧЧ¼ì²âÆ÷£¬Ñ¡ÔñÍⲿʱÖÓÔ´×÷ΪϵͳʱÖÓ
}
/*********¶Ë¿Ú³õʼº¯Êý*********/
void PORT_Init()
{
XBR0 = 0x27; /*½»²æ¿ª¹ØÅäÖÃ,URAT×ÜÏßTX0Öõ½P0.0¿Ú,
RX0Öõ½P0.1¿Ú, SPI×ÜÏßSCKÅäÖõ½P0.2¿Ú,
MOSIΪP0.4¿Ú, NSSΪP0.5,MISOÅäÖõ½P0.3¿Ú,
IIC×ÜÏßSDAÖõ½P0.6¿Ú,SCKÖõ½P0.7,
TX1,RX1ÅäÖõ½P1.0,P1.1,
CEX0,CEX1ÅäÖõ½P1.2,P1.3,
ÍⲿÖжÏint0ÅäÖõ½P1.4 */
XBR1 = 0x04;
XBR2 = 0x44; /*ÔÊÐí¹¦ÄÜÑ¡Ôñ¿ª¹ØÓÐЧ*/
P0MDOUT = 0x1A; /*SCK¡¢MOSI?ºÍNSSΪÍÆÀʽÊä³ö,MISO????Ϊ¿ªÂ©Ê½*/
P74OUT =0xff;
}
/*********UART0³õʼº¯Êý*********/
void UART0_Init (void)
{
SCON0 = 0x50; //´®¿Ú·½Ê½1
TMOD = 0x20; //Ñ¡Óö¨Ê±Æ÷1×÷Ϊ²¨ÌØÂÊ·¢ÉúÆ÷
TH1 =-(22118400/102400/16);
TL1 =-(22118400/102400/16);
TR1 = 1; //¶¨Ê±Æ÷¿ªÆô
ES0 = 1; //¿ªÆô´®¿ÚÖжÏ0
TF1 = 0;
TI0 = 1;
CKCON |= 0x10;
PCON |= 0x80; //²¨ÌØÂʼӱ¶ ²¨ÌØÂÊΪ115200
}
/*********ÖжÏ*********/
void UART0_ISR() interrupt 4 using 1
{
if(RI0)
{
RI0=0; //ÖжϽÓÊܱêÖ¾ÇåÁã
data1=SBUF0; //½ÓÊÜÊý¾Ý
SBUF0=data1; //·¢ËÍÊý¾Ý
while(TI0==0);
TI0=0; //·¢ËͱêÖ¾ÇåÁã
}
}
/*********Ö÷º¯Êý*********/
void main()
{
WDTCN=0XDE;
WDTCN=0XAD;
SYSCLK_Init();
PORT_Init();
UART0_Init();
printf ("AT+CWMODE=2\n");
printf ("AT+RST\n");
printf ("AT+CIPMUX=1\n");
printf ("AT+CIPSERVER=1:8080\n");
EA=1;
while(1);
} |