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;
			}
		}
	}
}
相关推荐
RuoZoe2 天前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
祈安_6 天前
C语言内存函数
c语言·后端
norlan_jame7 天前
C-PHY与D-PHY差异
c语言·开发语言
czy87874757 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
悠哉悠哉愿意7 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
m0_531237177 天前
C语言-数组练习进阶
c语言·开发语言·算法
Lester_11017 天前
STM32霍尔传感器输入口设置为复用功能输入口时,还能用GPIO函数直接读取IO的状态吗
stm32·单片机·嵌入式硬件·电机控制
LCG元7 天前
低功耗显示方案:STM32L0驱动OLED,动态波形绘制与优化
stm32·嵌入式硬件·信息可视化
三佛科技-187366133977 天前
120W小体积碳化硅电源方案(LP8841SC极简方案12V10A/24V5A输出)
单片机·嵌入式硬件
z20348315207 天前
STM32F103系列单片机定时器介绍(二)
stm32·单片机·嵌入式硬件