WIFI wireless communication combined with mobile phone E4A programming, a good learning routine, open source all the codes, such as the ESP8266 wireless network address is directly built into E4A, one-click access each time, the initial value is 10.10.10.208
port 5000
, those who don't know E4A can only burn the ESP8266 module according to this value. If you know E4A, just change it to your own IP
MCU source program:
/************************************************************************/
/* WIFI wireless transmission mobile phone display */
/************************************************************************/
#include #include #include #define uint unsigned int #define uchar unsigned char /*********************Related variables**************/ uint Receive,i,xm1,xm2,xm3,xm0; long s; [size=36.9444px]uchar Receive_table[40]; //Used to receive data fed back to MCU by the WiFi module[/size] uchar code ta[]="0123456789- "; //Test it uchar table[]="Temperature: 00.0 C"; //Positioning template for transmission sbit dq=P3^7; //18B20 bus interface. DQ bit tflag; //Define a temperature flag. +, - uint tvalue; //define a global variable to combine high and low 8-bit temperature //display temperature void delay (int a) // millisecond delay { int x,y; for(x=a;x>0;x--) for(y=110;y>0;y--); } void delayus(int t) // microsecond delay { while(t--); } /*********************************************************************** Name: Delay function Function: millisecond delay, microsecond delay function, waiting for data transmission and reception to complete....... ************************************************************************/ void ms_delay(uint t) { uint i,j; for(i=t;i>0;i--) for(j=110;j>0;j--); } void us_delay(uchar t) { while(t--); } /*------------------------------------------------ uS delay function, with input parameter unsigned char t, no return value unsigned char is used to define an unsigned character variable, whose value range is 0~255 Here we use a 12M crystal oscillator. Please use assembly for accurate delay. Approximate delay The length is as follows: T=tx2+5 uS ------------------------------------------------*/ void DelayUs2x(unsigned char t); /*------------------------------------------------ mS delay function, with input parameter unsigned char t, no return value unsigned char is used to define an unsigned character variable, whose value range is 0~255 Here we use a 12M crystal oscillator. Please use assembly code for accurate delay. ------------------------------------------------*/ void DelayMs(unsigned char t); /*------------------------------------------------ uS delay function, with input parameter unsigned char t, no return value unsigned char is used to define an unsigned character variable, whose value range is 0~255 Here we use a 12M crystal oscillator. Please use assembly for accurate delay. Approximate delay The length is as follows: T=tx2+5 uS ------------------------------------------------*/ void DelayUs2x(unsigned char t) { [size=36.9444px] while(--t);[/size] } /*------------------------------------------------ mS delay function, with input parameter unsigned char t, no return value unsigned char is used to define an unsigned character variable, whose value range is 0~255 Here we use a 12M crystal oscillator. Please use assembly code for accurate delay. ------------------------------------------------*/ void DelayMs(unsigned char t) { [size=36.9444px] while(t--) //roughly delay 1mS[/size] [size=36.9444px] {[/size] DelayUs2x(245); DelayUs2x(245); [size=36.9444px] }[/size] } [size=36.9444px]void Uart_Init() //Use timer 1 as the baud rate generator (STC89C52, STC89C51, AT89C51, etc.) [/size] { TMOD = 0x21; SCON = 0x50; //Set the serial mode TH1 = 0xFD; //Baud rate 9600 TL1 = TH1; PCON = 0x00; EA = 1; //General interruption enabled ES = 1; //Open serial port interrupt TR1 = 1; //Start timer 1 } /******************************************************************** Name: Serial port sending function Function: MCU sends data to the wireless WIFI module ESP8266 ************************************************************************/ void Send_Uart(uchar value) { ES=0; //Disable serial port interrupt TI=0; // Clear the interrupt request flag when sending is completed SBUF=value; //send while(TI==0); //Wait for sending to complete TI=0; // Clear the interrupt request flag when sending is completed ES=1; //Enable serial port interrupt TH0=0; TL0=0; } /******************************************************************** Name: WIFI module setting function Purpose: Start the module so that wireless access and control can be achieved ************************************************************************/ [size=36.9444px]void ESP8266_Set(uchar *puf) //Array pointer *puf points to string array [/size] { while(*puf!='') //jump out of loop when encountering a space { Send_Uart(*puf); //Send control instructions to the WIFI module. us_delay(5); puf++; } us_delay(5); Send_Uart('r'); //Enter us_delay(5); Send_Uart('n'); //line break } void ds18b20rst() // reset { dq=1; delay(5); dq=0; delayus(400); dq=1; delayus(50); } uchar ds18b20rd() // read data { uchar i=0; uchar dat=0; //Use DAT to store the read data for(i=0;i<8;i++) { dq=0; dat>>=1; //DAT not only shifts right by one bit, but also delays by one microsecond dq=1; if(dq==1)//You can also write (if(dq)) dat|=0x80; //DAT or 0X80 delayus(15); } return(dat); //Call DAT } uchar ds18b20wr (uchar com) // write data/command { uchar i=0; for (i=0; i<8; i++) { dq=0; dq=com&0x01; //Compare the written number with 0x01 delayus(15); dq=1; com>>=1;//data } } uint read_temp() //Read temperature, if it is greater than 256, use uint { uchar a,b; //Define two numbers as binary temperature. ds18b20rst(); // reset ds18b20wr(0xcc); //skip reading ROM ds18b20wr(0x44); //Send temperature conversion command ds18b20rst(); // reset ds18b20wr(0xcc); //skip reading ROM ds18b20wr(0xbe); //Read register a=ds18b20rd(); //A can only read the lower 8 bits. b=ds18b20rd(); //B can only read the upper 8 bits. tvalue=b; tvalue=tvalue<<8;//Shift left by 8 bits//Remove the upper 8 bits of the data in B. It can also be written as (tvalue=tvalue<<8;)//tvalue=tvalue*256;//tvalue<<=8; tvalue|=a; // OR with A, the complete tvalue value is read away if(tvalue<0xffff) tflag=0; else { tvalue=~tvalue+1; //get the original data tflag=1; } tvalue=tvalue*0.625; //Multiply the data by precision=temperature. To display, it needs to be enlarged 10 times. (0.0625) return(tvalue); //Return tvalue value } /******************************************************************** Name: Main function Function: The execution entry of the program ************************************************************************/ void main() [size=36.9444px]{ [/size] Uart_Init(); //Baud rate generator ms_delay(10); ESP8266_Set("AT+CWMODE=2"); //Set router mode 1 to station, mode 2 to AP, mode 3 to station+AP mixed mode ms_delay(500); [size=36.9444px]// ESP8266_Set("AT+RST"); //Restart the wifi module [/size] // ms_delay(1000); ESP8266_Set("AT+CWSAP="wifi_yuan","123456789",11,4"); //AT+CWSAP="wifi_yuan","123456789",11,4 Set module SSID:WIFI, PWD: password and security type encryption mode (WPA2-PSK) ms_delay(500); ESP8266_Set("AT+CIPMUX=1"); // Enable multi-connection mode to allow multiple clients to access ms_delay(500); ESP8266_Set("AT+CIPSERVER=1,5000"); //Start TCP/IP to realize network-based //control ESP8266_Set("AT+CIPSERVER=1,5000"); ms_delay(500); ESP8266_Set("AT+CIPSTO=0"); //Never time out ms_delay(500); ES=1; //Enable serial port interrupt while(1) { read_temp(); //Read temperature ms_delay(500); s=tvalue; xm0=(s/100)%10; //Store the hundreds digit [size=36.9444px] xm1=(s/10)%10; //Store ten-digit data[/size] [size=36.9444px] xm2=s%10; //Store single digit data[/size] table[6]=ta[xm0]; [size=36.9444px] table[7]=ta[xm1];[/size] [size=36.9444px] table[9]=ta[xm2]; [/size] ESP8266_Set(table); //Send the distance data ms_delay(500); } } /************************************************************************ Name: Serial communication interrupt Function: Enter this function after sending or receiving is completed, clear the corresponding flag bit by software to 0, and realize the normal sending and receiving of data by the module. ************************************************************************/ void Uart_Interrupt() interrupt 4 { static uchar i=0; if(RI==1) { RI=0; Receive=SBUF; //MCU receives the data fed back by the wifi module Receive_table[i]=Receive; if((recive_table[i]=='n')) { i=0; } else i++; //Reload value when encountering line break } else TI=0; }
Previous article:NRF24L01 wireless module multi-machine communication MCU program host computer + slave computer
Next article:51 single chip temperature control alarm and time display program + Proteus simulation
- Popular Resources
- Popular amplifiers
- Intelligent computing systems (Chen Yunji, Li Ling, Li Wei, Guo Qi, Du Zidong)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Schematic diagram - What is the function of the enable pin of the PA chip?
- Friends who make power supplies, please take a look. TI chips can reduce the size of power supplies and charging time by half
- Shanghai Hangxin ACM32F070 Development Board + Touch Function Evaluation Board Evaluation - Part 3 Clock and Temperature Display Interface
- How to integrate electromagnetic compatibility (EMC) design into product development process
- [Silicon Labs Development Kit Review] + Driving the VEML6035 Ambient Light Sensor
- Development of Switching Power Supply for Deuterium Lamp
- [Ateli Development Board AT32F421 Review] + USART Development
- Integrated circuit technology lecture notes.
- What should I do if the USB is too long and there is a voltage drop?
- What do you think of my fingerprint lock?