51 MCU + ESP8266 lights up LED lights

Publisher:春水碧于天Latest update time:2020-07-18 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

ESP8266 module adopts STA working mode. First, use the serial port debugging assistant on the computer to set the ESP8266 module to STA mode and baud rate 9600. The specific instructions are as follows:
1. Set AP mode AT+CWMODE=2
2. Reset takes effect AT+RST
3. Configure hotspot AT+CWSAP="test","12345678",1,3
In this way, even if ESP8266 is reset, this information will not be erased. You can directly use the following instructions to
connect the microcontroller to ESP8266. Be sure to pay attention to the common ground between the two, otherwise ESP8266 will not work properly. The ESP8266 power supply must be 3.3V, and 5V does not seem to work. The EN pin of ESP8266 is connected to a 1K ohm resistor and then to a 3.3V power supply.

#include
typedef unsigned char u8;
typedef unsigned int u16;
sbit LED = P1^0;u8 dat;
void Init(void); //Serial port initialization function
void Delay_ms(u16 n);//delay sub-function
void Sent_ZF(u8 dat);//send a byte
void AT_Send_String(u8 *string);//send string
void ESP8266_Init();//ESP8266 initialization
void Init(void) //Serial port initialization function
{

        TMOD=0x20; //Timer working mode 2, 8-bit automatic reload (0010 0000)
        TL1=0xfd; //Load initial value
        TH1=0xfd;               
        TR1=1; //Start timer 1
        REN=1; //Allow serial port to receive data
        SM0=0; //Working mode 1, 10-bit asynchronous reception and transmission
        SM1=1;   
        EA=1; //Open global interrupt control
        ES=1; //Open serial port interrupt
}

void main()
{
    Init();
    ESP8266_Init();
    while(1);
}

void Sent_ZF(u8 dat) //Send a byte
{
        ES = 0;
        TI=0;
        SBUF = dat;
        while(!TI);
        TI = 0;
        ES = 1;
}
void Delay_ms(u16 n) //Delay subroutine
{
        unsigned int i,j;
        for(i=0;i        for(j=0;j<123;j++);
}

void AT_Send_String(u8 *string) //Send string
{
  while(*string!='')
  {
    Sent_ZF(*string);
        string++;
                Delay_ms(10);
  }

}
void ESP8266_Init() //ESP8266 initialization
{       
         AT_Send_String("AT+RSTrn"); //Restart moduleDelay_ms
        (10000);
        Delay_ms(10000);
    AT_Send_String("AT+CIPMUX=1rn"); //Set to multi-connection mode, start moduleDelay_ms
        (10000);
        Delay_ms(10000);
  AT_Send_String("AT+CIPSERVER=1,8080rn"); //Server port setting
          Delay_ms(10000);
        Delay_ms(10000);
}

void InterruptUART() interrupt 4 //Control the small light switch
{
        RI= 0; //Clear
        dat= SBUF; //The received data is stored in SBUF
          {
         if(dat=='o')
                                 {
                                         LED =0;   
                                 }
                                 if(dat=='f')  
                                 {                                                 
                                    LED =1;
                                 }                                         
          }
}
Download a software called Network Debug Assistant on your phone. The IP address is 192.168.4.1 (it seems to be the same port), and the port number is 8080. After the connection is successful, send f or o to control the LED light switch.

Reference address:51 MCU + ESP8266 lights up LED lights

Previous article:Design of TB6560 two-phase hybrid stepper motor driver board
Next article:The serial port controls three digital tubes via 164

Recommended ReadingLatest update time:2024-11-15 14:49

51 single chip microcomputer--LED flashing, simple experiment of running water light
1. LED flashes  /******************************************************************** Simple experiment of LED flashing ******************************************************************/ include reg51.h //This file defines some special function registers of 51 /*******Delay function***********************************
[Microcontroller]
51 single chip microcomputer--LED flashing, simple experiment of running water light
Design of automatic door based on 51 single chip microcomputer
1. Hardware Solution This design is a system that uses STC89C52 microcontroller as a controller, a stepper motor, a pyroelectric infrared sensor, an LED indicator light, and a buzzer. The pyroelectric infrared sensor transmits a detection signal to the microcontroller, which controls the motor drive and thus controls
[Microcontroller]
Design of automatic door based on 51 single chip microcomputer
Outlook for iPad Pro next year: Two key words are 5G millimeter wave and mini-LED
        On the morning of November 27, DigiTimes, a media outlet that focuses on news from the electronics industry chain, recently reported that the high-end iPad Pro model that Apple is rumored to release next year will support 5G millimeter wave technology (mmWave).   Rumors suggest that Apple plans to release a hi
[Mobile phone portable]
[MCU Framework] [app_led] Using soft timer to implement flashing and breathing lighting modes
Example: Initialize at any location: app_led_init(); app_led_indicate(light number, light type, cycle time, reload value); Note: You need to implement the corresponding PWM function first The file code is as follows app_led.c /******************************************************************************** * @
[Microcontroller]
51 MCU DS1302 clock chip simple program
 #include reg51.h  #include intrins.h  #define uchar unsigned char  #define uint unsigned int data_7seg ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, };  uchar hour,min,sec;  sbit shi=P1^0;  sbit fen=P1^1;  sbit miao=P1^2;  sbit rst=P1^4;  sbit sck=P1^5;  sbit io=P1^6 ; sbit fm=P1^7; /*Function declaration:*/
[Microcontroller]
51 MCU Experiment 5: Dynamic Digital Tube
The circuit diagram of the digital tube module of the development board is as follows: Due to the characteristics of the 74ls138 decoder, that is, only one digital tube can have a cathode level of 0, it is obviously impossible to make multiple digital tubes work at the same time. If you want to get the effect of mul
[Microcontroller]
51 MCU Experiment 5: Dynamic Digital Tube
AVR Microcontroller Tutorial - Blinking LED
Last time we turned on the LED. You may have tried to replace LED_RED with other lights, or you may have used led_on() to turn on all LEDs at once. But after the LEDs were turned on, the program exited, and the LEDs never dimmed until there was no power. This time, we use the program to control the brightness of the L
[Microcontroller]
Discussion on LED Programming in Single Chip Microcomputer
  Due to its small size, low price, powerful functions, high reliability, control orientation and low price, single-chip microcomputers have not only become intelligent control tools used in the field of industrial measurement and control, but have also penetrated into every corner of people's work and life. The cours
[Power Management]
Discussion on LED Programming in Single Chip Microcomputer
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号