WIFI实现透传+接线图

单片机通过TX接WIFI模块的RX将设置的AT代码写入WIFI模块(连接WIFI+调为设备模式(有设备,路由,双模等模式))

WIFI模块将响应信号通过TX通过CH340发给PC的RX

通过STC-ISP或安信可串口调试助手查看响应信息

PC可以通过TX给单片机的RX发送信息

cpp 复制代码
#include "reg52.h"
#include "intrins.h"
#include <string.h>


#define SIZE 12
sbit D5 = P3^0;
sbit jdq = P3^4;
sfr AUXR = 0x8e;
int mark=0;
char cmd = '1';
code char ruwang[]="AT+CWJAP=\"wifi名称\",\"密码\"\r\n";
code char ljfwq[]="AT+CIPSTART=\"TCP\",\"IP地址\",端口\r\n";
code char TCMS[]  = "AT+CIPMODE=1\r\n";
code char SJCS[]  = "AT+CIPSEND\r\n";
 
void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //????????1,REN????
	TMOD &= 0x0F;
	TMOD |= 0x20;//???1?????8?????
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600??????
	TR1 = 1;//?????
	
	EA = 1;//?????
	ES = 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 sendByte(char data_msg)
{
	SBUF = data_msg;
	while(!TI);
	TI = 0;
}

void sendString(char* str)
{
	while( *str != '\0'){
		sendByte(*str);
		str++;
	}
}
void Uart_Handler() interrupt 4
{
	if (RI)
	{
		RI = 0;
		jdq = 0;
		Delay1000ms();
		jdq = 1;
	}
}
void main()
{


	//D5 = 1;
	//??C51???????
	UartInit();
	jdq = 0;
	while(1)
	{
		if(mark==0){
		Delay1000ms();
		//??????????,????????
		//sendString("chenlichen shuai\r\n");
		sendString(ruwang);
		Delay1000ms();
		Delay1000ms();
		Delay1000ms();
		Delay1000ms();
		Delay1000ms();
		sendString(ljfwq);
		Delay1000ms();
		Delay1000ms();
		Delay1000ms();
		Delay1000ms();
		//Delay1000ms();
		sendString(TCMS);
		Delay1000ms();
		Delay1000ms();
		//Delay1000ms();
		//Delay1000ms();
		//Delay1000ms();
		sendString(SJCS);
		Delay1000ms();
		Delay1000ms();
		//Delay1000ms();
		//Delay1000ms();
		//Delay1000ms();
		mark=1;
	}
		else if (mark==1)
		{
			if (mark){
				sendString("ok");
				Delay1000ms();
				mark=3;
				ES = 1;
				jdq = 1;
			}
		}
	}
}
相关推荐
HABuo4 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
不能跑的代码不是好代码6 小时前
STM32窗口看门狗(WWDG)知识点及标准库使用指南
stm32·单片机·嵌入式硬件
bingquan33336 小时前
在 Ghidra 中分析STM32裸机固件
stm32·单片机·嵌入式硬件
羽获飞6 小时前
从零开始学嵌入式之STM32——11.STM32---USART串行通讯
stm32·单片机·嵌入式硬件
宵时待雨7 小时前
STM32笔记归纳9:定时器
笔记·stm32·单片机·嵌入式硬件
逐步前行7 小时前
STM32_新建工程(寄存器版)
stm32·单片机·嵌入式硬件
bai5459368 小时前
STM32 CubeIDE 通过PWM占空比控制舵机角度
stm32·单片机·嵌入式硬件
2401_858936889 小时前
【Linux C 编程】标准 IO 详解与实战:从基础接口到文件操作实战
linux·c语言
松涛和鸣10 小时前
72、IMX6ULL驱动实战:设备树(DTS/DTB)+ GPIO子系统+Platform总线
linux·服务器·arm开发·数据库·单片机
简单中的复杂10 小时前
【避坑指南】RK3576 Linux SDK 编译:解决 Buildroot 卡死在 host-gcc-final 的终极方案
linux·嵌入式硬件