欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
單片機+ESP8266實現WIFI無線插座 程序+原理圖
[打印本頁]
作者:
山水愚青
時間:
2021-5-6 14:56
標題:
單片機+ESP8266實現WIFI無線插座 程序+原理圖
電路原理圖如下:
image002.gif
(37.56 KB, 下載次數: 94)
下載附件
2021-5-6 17:46 上傳
單片機源程序如下:
#include <REGX52.H>
#define uint unsigned int
#define uchar unsigned char
sbit LED0=P1^0;
sbit LED1=P1^4;
sbit LED2=P3^5;
sbit LED3=P3^6;
sbit LED4=P2^4;
sbit LED5=P2^5;
sbit LED6=P2^6;
sbit LED7=P2^7;
sbit LED8=P0^0;
sbit LED9=P0^1;
sbit LED10=P0^2;
sbit LED11=P0^3;
sbit LED12=P0^4;
sbit LED13=P0^5;
sbit LED14=P0^6;
/*****************相關變量**************/
uchar Receive,i,qj,yz,zz,ht;
uint n;
uchar Recive_table[40]; //用于接收wifi模塊反饋到MCU上的數據
/*******************************************************************
名稱:延時函數 作用:毫秒級延時,微妙級延時函數,為數據收發完成作等待.......
********************************************************************/
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--);
}
void Uart_Init() //使用定時器1作為波特率發生器(STC89C52、STC89C51、AT89C51等均可)
{
TMOD = 0x20;
SCON = 0x50; //設置串行方式
TH1 = 0xFD; //波特率9600
TL1 = TH1;
PCON = 0x00;
EA = 1; //總中斷打開
ES = 1; //開串口中斷
TR1 = 1; //啟動定時器1
}
/********************************************************************
名稱:串口發送函數 功能:MCU向無線WIFI模塊ESP8266發送數據
********************************************************************/
void Send_Uart(uchar value)
{
ES=0; //關閉串口中斷
TI=0; //清發送完畢中斷請求標志位
SBUF=value; //發送
while(TI==0); //等待發送完畢
TI=0; //清發送完畢中斷請求標志位
ES=1; //允許串口中斷
}
/********************************************************************
名稱:WIFI模塊設置函數 作用: 啟動模塊,以便可以實現無線接入和控制
********************************************************************/
void ESP8266_Set(uchar *puf) // 數組指針*puf指向字符串數組
{
while(*puf!='\0') //遇到空格跳出循環
{
Send_Uart(*puf); //向WIFI模塊發送控制指令。
us_delay(5);
puf++;
}
us_delay(5);
Send_Uart('\r'); //回車
us_delay(5);
Send_Uart('\n'); //換行
}
/********************************************************************
名稱:主函數 作用:程序的執行入口
********************************************************************/
void main()
{
Uart_Init(); //波特率發生器
ms_delay(2000);
ESP8266_Set("AT+CWMODE=2"); //設置路由器模式1 station,模式2 AP,模式3 station+AP混合模式
ms_delay(2000);
// ESP8266_Set("AT+RST "); //重新啟動wifi模塊
// ms_delay(2000);
ESP8266_Set("AT+CWSAP=\"wifi_yuan\",\"123456789\",11,4"); //AT+CWSAP="wifi_yuan","123456789",11,4 設置模塊SSID:WIFI, PWD:密碼 及安全類型加密模式(WPA2-PSK)
ms_delay(2000);
ESP8266_Set("AT+CIPMUX=1"); //開啟多連接模式,允許多個各客戶端接入
ms_delay(2000);
ESP8266_Set("AT+CIPSERVER=1,5000"); //啟動TCP/IP 實現基于網絡//控制 ESP8266_Set("AT+CIPSERVER=1,5000");
ms_delay(2000);
ESP8266_Set("AT+CIPSTO=0"); //永遠不超時
ES=1; //允許串口中斷
qj=1;
zz=1;
yz=1;
ht=1;
LED0=1;
LED1=1;
LED2=1;
LED3=1;
LED4=1;
LED5=1;
LED6=1;
LED7=1;
LED8=1;
LED9=1;
LED10=1;
LED11=1;
LED12=1;
LED13=1;
LED14=1;
while(1)
{
if((Recive_table[0]=='+')&&(Recive_table[1]=='I')&&(Recive_table[2]=='P'))//MCU接收到的數據為+IPD時進入判斷控制0\1來使小燈亮與滅
{
if((Recive_table[9]=='G')&&(Recive_table[10]=='P'))
{
/**************************一樓控制*************************************/
if(Recive_table[15]=='a' )
{
LED0=0; //
}
else
if (Recive_table[15]=='b' )
{
LED0=1; //
}
else
if (Recive_table[15]=='c' )
{
LED1=0; //
}
else
if (Recive_table[15]=='d' )
{
LED1=1; //
}
else
if (Recive_table[15]=='e' )
{
LED2=0; //
}
else
if (Recive_table[15]=='f' )
{
LED2=1; //
}
if (Recive_table[15]=='g' )
{
LED3=0; //
}
else
if (Recive_table[15]=='h' )
{
LED3=1; //
}
if (Recive_table[15]=='i' )
{
LED4=0; //
}
else
if (Recive_table[15]=='j' )
{
LED4=1; //
}
/**************************二樓控制*************************************/
if(Recive_table[15]=='0' )
{
LED5=0; //
}
else
if (Recive_table[15]=='1' )
{
LED5=1; //
}
else
if (Recive_table[15]=='2' )
{
LED6=0; //
}
else
if (Recive_table[15]=='3' )
{
LED6=1; //
}
else
if (Recive_table[15]=='4' )
{
LED7=0; //
}
else
if (Recive_table[15]=='5' )
{
LED7=1; //
}
if (Recive_table[15]=='6' )
{
LED8=0; //
}
else
if (Recive_table[15]=='7' )
{
LED8=1; //
}
if (Recive_table[15]=='8' )
{
LED9=0; //
}
else
if (Recive_table[15]=='9' )
{
LED9=1; //
}
/***********************三樓控制*************************************/
if(Recive_table[15]=='Q' )
{
LED10=0; //
}
else
if (Recive_table[15]=='W' )
{
LED10=1; //
}
else
if (Recive_table[15]=='E' )
{
LED11=0; //
}
else
if (Recive_table[15]=='R' )
{
LED11=1; //
}
else
if (Recive_table[15]=='T' )
{
LED12=0; //
}
else
if (Recive_table[15]=='Y' )
{
LED12=1; //
}
if (Recive_table[15]=='U' )
{
LED13=0; //
}
else
if (Recive_table[15]=='I' )
{
LED13=1; //
}
if (Recive_table[15]=='O' )
{
LED14=0; //
}
else
if (Recive_table[15]=='P' )
{
LED14=1; //
}
}
}
}
}
/*********************************************************************
名稱:串行通訊中斷 作用:發送或接收結束后進入該函數,對相應的標志位軟件清0,實現模塊對數據正常的收發。
********************************************************************/
void Uart_Interrupt() interrupt 4
{
static uchar i=0;
if(RI==1)
{
RI=0;
Receive=SBUF; //MCU接收wifi模塊反饋回來的數據
Recive_table[i]=Receive;
if((Recive_table[i]=='\n'))
{
i=0;
}
else i++; //遇到換行 重新裝值
}
else TI=0;
}
復制代碼
word版的原理圖如下(上面已經有一份了,這個不必下載,內容一樣的):
原理圖.docx
(49.15 KB, 下載次數: 82)
2021-5-6 14:52 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
sharehope
時間:
2021-5-20 22:05
這個確實好東西,最近也在從事無線wifi相關的編程,學習了
作者:
usaboy
時間:
2021-5-21 09:52
程序在哪下載?
作者:
longqishi57777
時間:
2021-12-27 13:31
非常給力,電路圖很贊
作者:
gongnn
時間:
2022-3-17 08:57
樓主三極管驅動繼電器部分三極管用法是錯的,應該接上臂而不是下臂。
作者:
xiaxiao1127
時間:
2022-3-25 17:04
確實是 好東西,下來好好學習下。
作者:
lvlv99
時間:
2022-3-25 18:33
PNP管5V下臂用沒問題,12V用上臂
作者:
zying
時間:
2022-3-26 17:02
請問這個怎樣控制呢?
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1