




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、CONFIG.H文件:/#ifndef _CONFIG_H#define _CONFIG_H/* 通用頭文件 */#include <reg52.h>#include <intrins.h>/* 數(shù)據(jù)類型定義 */*typedef signed char int8; / 8位有符號(hào)整型數(shù)typedef signed int int16; /16位有符號(hào)整型數(shù)typedef signed long int32; /32位有符號(hào)整型數(shù) */typedef unsigned char u8; / 8位無符號(hào)整型數(shù)typedef unsigned int u16; /16位無符
2、號(hào)整型數(shù)typedef unsigned long u32; /32位無符號(hào)整型數(shù)/* 全局運(yùn)行參數(shù)定義 */#define SYS_MCLK (11059200/12) /系統(tǒng)主時(shí)鐘頻率,即振蕩器頻率÷12/* IO引腳分配定義 */sbit KEY_IN_1 = P24; /矩陣按鍵的掃描輸入引腳1sbit KEY_IN_2 = P25; /矩陣按鍵的掃描輸入引腳2sbit KEY_IN_3 = P26; /矩陣按鍵的掃描輸入引腳3sbit KEY_IN_4 = P27; /矩陣按鍵的掃描輸入引腳4sbit KEY_OUT_1 = P23; /矩陣按鍵的掃描輸出引腳1sbit K
3、EY_OUT_2 = P22; /矩陣按鍵的掃描輸出引腳2sbit KEY_OUT_3 = P21; /矩陣按鍵的掃描輸出引腳3sbit KEY_OUT_4 = P20; /矩陣按鍵的掃描輸出引腳4sbit ADDR0 = P10; /LED位選譯碼地址引腳0sbit ADDR1 = P11; /LED位選譯碼地址引腳1sbit ADDR2 = P12; /LED位選譯碼地址引腳2sbit ADDR3 = P13; /LED位選譯碼地址引腳3sbit ENLED = P14; /LED顯示部件的總使能引腳#define LCD1602_DB P0 /1602液晶數(shù)據(jù)端口sbit LCD1602
4、_RS = P10; /1602液晶指令/數(shù)據(jù)選擇引腳sbit LCD1602_RW = P11; /1602液晶讀寫引腳sbit LCD1602_E = P15; /1602液晶使能引腳sbit DS1302_CE = P17; /DS1302片選引腳sbit DS1302_CK = P35; /DS1302通信時(shí)鐘引腳sbit DS1302_IO = P34; /DS1302通信數(shù)據(jù)引腳sbit I2C_SCL = P37; /I2C總線時(shí)鐘引腳sbit I2C_SDA = P36; /I2C總線數(shù)據(jù)引腳sbit BUZZER = P16; /蜂鳴器控制引腳sbit IO_18B20 =
5、P32; /DS18B20通信引腳sbit IR_INPUT = P33; /紅外接收引腳#include "Lcd1602.h"#include "UART.H"#include "TIME.H"#include "STA.H"#include "string.h"extern u8 WIFILED;#endif/TIME.C文件:/#include "config.h"u16 UART_CNT;u8 T0RH,T0RL;void delay10us()_nop_();_n
6、op_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();void delay1ms()u8 i;for(i=0;i<100;i+)_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();void delayms(u16 ms)u16 is;for(is=0;is<ms;is+)delay1ms();/*定時(shí)器0配置*/void TIME0_Init(u16 ms)unsigned long tmp
7、; /臨時(shí)變量 tmp = 11059200 / 12; /定時(shí)器計(jì)數(shù)頻率 tmp = (tmp * ms) / 1000; /計(jì)算所需的計(jì)數(shù)值 tmp = 65536 - tmp; /計(jì)算定時(shí)器重載值 tmp = tmp + 18; /補(bǔ)償中斷響應(yīng)延時(shí)造成的誤差 T0RH = (unsigned char)(tmp>>8); /定時(shí)器重載值拆分為高低字節(jié) T0RL = (unsigned char)tmp; TMOD &= 0xF0; /清零T0的控制位 TMOD |= 0x01; /配置T0為模式1 TH0 = T0RH; /加載T0重載值 TL0 = T0RL; ET
8、0 = 1; /使能T0中斷 TR0 = 1; /啟動(dòng)T0/*定時(shí)器0 中斷*/void IRQ_TIME0()interrupt 1TH0 = T0RH; /加載T0重載值 TL0 = T0RL;UART_CNT+;if(UART_CNT>=800)RX_END_FLG=1;TX_END_FLG=1;WIFI_SHOW_RX_DATA();TR0=0;/UART.C串口協(xié)議:/#include "config.h"u8 TX_BUF32;u8 RX_BUF32;u8 RX_INDEX;u8 TX_INDEX;bit RX_END_FLG;bit TX_END_FLG
9、;void UART_Init(u16 baud)SCON = 0x50; /配置串口為模式1 TMOD &= 0x0F; /清零T1的控制位 TMOD |= 0x20; /配置T1為模式2 TH1 = 256 - (11059200/12/32)/baud; /計(jì)算T1重載值 TL1 = TH1; /初值等于重載值 ET1 = 0; /禁止T1中斷 ES = 1; /使能串口中斷PT1 = 1; TR1 = 1; /啟動(dòng)T1 /*檢查期待返回值A(chǔ)CK*/bit Check_CMD(u8 *str)u8 i=0,j; for(i=0;RX_BUFi!='0'i+) /查
10、找關(guān)鍵字 if(RX_BUFi=(*str) /首字節(jié)相同,匹配后續(xù)字節(jié)for(j=1;*(str+j)!='0'j+)if(RX_BUFi+j!=(*(str+j)return 0; /關(guān)鍵字不匹配return 1; /關(guān)鍵字匹配成功 return 0; /關(guān)鍵字未找到/*發(fā)送字符串*/*檢測(cè)等待超時(shí)ms: waittime*/*檢測(cè)項(xiàng):ack*/u8 WIFI_TX_DATA(u8 *DATA,u8 *ack,u16 waittime)SBUF=*DATA; /先發(fā)送抗干擾字節(jié)while(!TX_END_FLG); /等待發(fā)送完畢TX_END_FLG=0; / 清除結(jié)束標(biāo)志
11、SBUF=*DATA; /先發(fā)送抗干擾字節(jié)while(!TX_END_FLG);TX_END_FLG=0;for(DATA=&DATA0;*DATA!='0'DATA+)/循環(huán)發(fā)送AT指令字節(jié) SBUF=*DATA; while(!TX_END_FLG); TX_END_FLG=0;SBUF=0X0D;/添加AT指令結(jié)束符while(!TX_END_FLG); TX_END_FLG=0;SBUF=0X0A;/添加AT指令結(jié)束符while(!TX_END_FLG); TX_END_FLG=0;if(*ack)&&waittime) waittime+=11
12、1;while(waittime>111)delayms(100); /延時(shí)100msif(RX_END_FLG=1)RX_END_FLG=0;if(Check_CMD(ack) /檢測(cè)ACKWIFILED&=0XEF;return 1;waittime-=100;WIFILED|=0X10;return 0; /超時(shí)檢測(cè)失敗/*接收字符串并執(zhí)行相應(yīng)操作*/void WIFI_SHOW_RX_DATA()RX_BUFRX_INDEX='0'LcdShowStr(0, 1, "RX: ");LcdShowStr(4, 1, " &quo
13、t;);LcdShowStr(4, 1, &RX_BUF11); /* UART中斷服務(wù)函數(shù) */void IRQ_UART() interrupt 4 if (RI) /接收到字節(jié) RI=0;UART_CNT=0;if(!TR0)RX_INDEX=0;UART_CNT=0;RX_END_FLG=0;TR0=1;if(RX_INDEX<=30)RX_BUFRX_INDEX+=SBUF;elseRX_END_FLG=1; /強(qiáng)制標(biāo)記接收完成RX_INDEX=0; /清零接收位置if(TI)TI=0;TX_END_FLG=1;/STA.C:STA模式/#include "c
14、onfig.h"pdata u8 name="sferhua" /熱點(diǎn)名稱pdata u8 unkey="303000000" /APCONFIG14 解鎖密匙pdata u8 TCP_IP="10.1.4.133" /TCP服務(wù)器地址pdata u8 TCP_PORT="8086" /TCP服務(wù)器端口pdata u8 UDP_IP="172.23.22.2" /UDP服務(wù)器地址pdata u8 UDP_PORT="8051" /UDP服務(wù)器端口/*AP默認(rèn)配置前綴
15、*/ 9"10NAMEpdata u8 STACONFIG48=0X41,0X54,0X2B,0X43,0X57,0X4A,0X41,0X50,0X3D,0X22; /*TCP默認(rèn)客戶端配置前綴*/ / " T C P " ,"pdata u8 STATCP48=0X41,0X54,0X2B,0X43,0X49,0X50,0X53,0X54,0X41,0X52,0X54,0X3D,0X22,0X54,0X43,0X50,0X22,0X2C,0X22;/*UDP默認(rèn)配置前綴*/ " UD P " ,"pdata u8 STAU
16、DP48=0X41,0X54,0X2B,0X43,0X49,0X50,0X53,0X54,0X41,0X52,0X54,0X3D,0X22,0X55,0X44,0X50,0X22,0X2C,0X22;/*PIN命令前綴,檢測(cè)IP是否鏈接上*/" 9pdata u8 STAPIN48=0X41,0X54,0X2B,0X50,0X49,0X4E,0X47,0X3D,0X22,0X31; /*配置生成*/void Made_Config() u8 i=10; u8* p; p=&name0; while(*p!='0') STACONFIGi+=*p+; STACO
17、NFIGi+=0X22; STACONFIGi+=0X2C; STACONFIGi+=0X22; p=&unkey0; while(*p!='0') STACONFIGi+=*p+; STACONFIGi+=0X22; STACONFIGi='0' /STA模式初始化數(shù)組 i=19; p=&TCP_IP0; while(*p!='0') STATCPi+=*p+; STATCPi+=0X22; STATCPi+=0X2C; p=&TCP_PORT0; while(*p!='0') STATCPi+=*p+;
18、 STATCPi='0' /AP-TCP模式初始化數(shù)組 i=19; p=&UDP_IP0; while(*p!='0') STAUDPi+=*p+; STAUDPi+=0X22; STAUDPi+=0X2C; p=&UDP_PORT0; while(*p!='0') STAUDPi+=*p+; STAUDPi='0' /AP-UDP模式初始化數(shù)組 i=9; p=&TCP_IP0; while(*p!='0') STAPINi+=*p+; STAPINi+=0X22; STAPINi =
19、39;0' /PIN命令初始化數(shù)組/*開啟STA-TCP服務(wù)器模式*/void STA_SER_MODE()u8 nameindex;while(!WIFI_TX_DATA("AT","OK",300)LcdShowStr(0,0 ,"ST .");/WIFI檢測(cè)while(!WIFI_TX_DATA("AT+CWMODE=1","OK",300);WIFI_TX_DATA("AT+RST",0,0);LcdShowStr(0, 0,"ST OK"
20、);while(!WIFI_TX_DATA("AT","OK",300);while(!WIFI_TX_DATA(STACONFIG,"CONNECTED",1000);/鏈接wififor(nameindex=10;STACONFIGnameindex!=0x22;nameindex+)LcdShowChar(nameindex-4,0 ,STACONFIGnameindex);/顯示名稱while(!WIFI_TX_DATA("AT+CIPMUX=1","OK",300);LcdShowSt
21、r(8,0 ," ");LcdShowStr(8,0 ,".M");/多連接while(!WIFI_TX_DATA("AT+CIPSERVER=1,8086","OK",300);LcdShowStr(13,0 ,"SER");while(!WIFI_TX_DATA("AT+CIFSR","OK",300); LcdShowStr(4, 1, " ");LcdShowStr(4, 1, &RX_BUF0);delayms(100
22、0);/*開啟STA-TCP客戶端模式*/void STA_CUS_MODE()u8 nameindex;while(!WIFI_TX_DATA("AT","OK",300)LcdShowStr(0,0 ,"ST .");/WIFI檢測(cè)while(!WIFI_TX_DATA("AT+CWMODE=1","OK",300);WIFI_TX_DATA("AT+RST",0,0);LcdShowStr(0, 0,"ST OK");while(!WIFI_TX_D
23、ATA("AT","OK",300);while(!WIFI_TX_DATA(STACONFIG,"CONNECTED",1000);/連接wififor(nameindex=10;STACONFIGnameindex!=0x22;nameindex+)LcdShowChar(nameindex-5,0 ,STACONFIGnameindex);/顯示名稱while(!WIFI_TX_DATA("AT+CIPMUX=0","OK",300);LcdShowStr(8,0 ," &quo
24、t;);LcdShowStr(8,0 ,".I");/單連接if(!WIFI_TX_DATA(STATCP,"OK",500) /TCP配置while(!WIFI_TX_DATA(STATCP,"ALREADY",500);LcdShowStr(13,0 ,"CUS");while(!WIFI_TX_DATA("AT+CIPMODE=1","OK",300); /開啟透?jìng)髂J絯hile(!WIFI_TX_DATA("AT+CIPSEND","OK
25、",300); /開始發(fā)送數(shù)據(jù)WIFI_TX_DATA("TCP OK","",0);delayms(1000); /*開啟STA-UDP模式*/void STA_UDP_MODE()u8 nameindex;while(!WIFI_TX_DATA("AT","OK",300)LcdShowStr(0,0 ,"ST .");/WIFI檢測(cè)while(!WIFI_TX_DATA("AT+CWMODE=1","OK",300);WIFI_TX_DAT
26、A("AT+RST",0,0);LcdShowStr(0, 0,"ST OK");while(!WIFI_TX_DATA("AT","OK",300);while(!WIFI_TX_DATA(STACONFIG,"CONNECTED",500);/配置wififor(nameindex=10;STACONFIGnameindex!=0x22;nameindex+)LcdShowChar(nameindex-4,0 ,STACONFIGnameindex);/顯示名稱while(!WIFI_TX_
27、DATA("AT+CIPMUX=0","OK",300);LcdShowStr(8,0 ," ");LcdShowStr(8,0 ,".I");/單連接while(!WIFI_TX_DATA(STAUDP,"ALREADY",500); /UDP配置LcdShowStr(13,0 ,"UDP");while(!WIFI_TX_DATA("AT+CIPSEND=8",">",300); /UDP配置WIFI_TX_DATA(&quo
28、t;UDP OK","",0);delayms(1000); /AP.C:AP模式/#include "config.h"pdata u8 name="SAP" /APCONFIG10 鎖pdata u8 key="888888888" /APCONFIG14 解鎖pdata u8 way="1,4" /加密方式pdata u8 TCP_IP="192.168.4.2" /TCP服務(wù)器地址pdata u8 TCP_PORT="8086" /TCP
29、服務(wù)器端口pdata u8 UDP_IP="192.168.4.2" /UDP服務(wù)器地址pdata u8 UDP_PORT="8086" /UDP服務(wù)器端口/*AP默認(rèn)配置前綴*/" 10 B " , "pdata u8 APCONFIG48=0X41,0X54,0X2B,0X43,0X57,0X53,0X41,0X50,0X3D,0X22; /*TCP默認(rèn)客戶端配置前綴*/ / " T C P " ,"pdata u8 APTCP48=0X41,0X54,0X2B,0X43,0X49,0X50
30、,0X53,0X54,0X41,0X52,0X54,0X3D,0X22,0X54,0X43,0X50,0X22,0X2C,0X22;/*UDP默認(rèn)配置前綴*/ " UD P " ,"pdata u8 APUDP48=0X41,0X54,0X2B,0X43,0X49,0X50,0X53,0X54,0X41,0X52,0X54,0X3D,0X22,0X55,0X44,0X50,0X22,0X2C,0X22;/*PIN命令前綴,檢測(cè)IP是否鏈接上*/" 9pdata u8 APPIN48=0X41,0X54,0X2B,0X50,0X49,0X4E,0X47,0
31、X3D,0X22,0X31; /*配置生成*/void Made_Config() u8 i=10; u8* p; p=&name0; while(*p!='0') APCONFIGi+=*p+; APCONFIGi+=0X22; APCONFIGi+=0X2C; APCONFIGi+=0X22; p=&key0; while(*p!='0') APCONFIGi+=*p+; APCONFIGi+=0X22; APCONFIGi+=0X2C; p=&way0; while(*p!='0') APCONFIGi+=*p+;
32、APCONFIGi='0' /AP模式初始化數(shù)組 i=19; p=&TCP_IP0; while(*p!='0') APTCPi+=*p+; APTCPi+=0X22; APTCPi+=0X2C; p=&TCP_PORT0; while(*p!='0') APTCPi+=*p+; APTCPi='0' /AP-TCP模式初始化數(shù)組 i=19; p=&UDP_IP0; while(*p!='0') APUDPi+=*p+; APUDPi+=0X22; APUDPi+=0X2C; p=&
33、UDP_PORT0; while(*p!='0') APUDPi+=*p+; APUDPi='0' /AP-UDP模式初始化數(shù)組 i=9; p=&TCP_IP0; while(*p!='0') APPINi+=*p+; APPINi+=0X22; APPINi = '0' /PIN命令初始化數(shù)組/*開啟AP-TCP服務(wù)器模式*/void AP_SER_MODE()u8 nameindex;while(!WIFI_TX_DATA("AT","OK",300)LcdShowStr(0,0
34、 ,"AR .");/WIFI檢測(cè)while(!WIFI_TX_DATA("AT+CWMODE=2","OK",300);WIFI_TX_DATA("AT+RST",0,0);LcdShowStr(0, 0,"AP OK");while(!WIFI_TX_DATA("AT","OK",300);while(!WIFI_TX_DATA(APCONFIG,"OK",500);/配置wififor(nameindex=10;APCONFIGn
35、ameindex!=0x22;nameindex+)LcdShowChar(nameindex-4,0 ,APCONFIGnameindex);/顯示名稱while(!WIFI_TX_DATA("AT+CIPMUX=1","OK",300);LcdShowStr(10,0 ,"M");/多連接while(!WIFI_TX_DATA("AT+CIPSERVER=1,8086","OK",300);LcdShowStr(13,0 ,"SER");delayms(1000);/*開
36、啟AP-TCP客戶端模式*/void AP_CUS_MODE()u8 nameindex;while(!WIFI_TX_DATA("AT","OK",300)LcdShowStr(0,0 ,"AR .");/WIFI檢測(cè)while(!WIFI_TX_DATA("AT+CWMODE=2","OK",300);WIFI_TX_DATA("AT+RST",0,0);LcdShowStr(0, 0,"AP OK");while(!WIFI_TX_DATA(&quo
37、t;AT","OK",300);while(!WIFI_TX_DATA(APCONFIG,"OK",500);/配置wififor(nameindex=10;APCONFIGnameindex!=0x22;nameindex+)LcdShowChar(nameindex-4,0 ,APCONFIGnameindex);/顯示名稱while(!WIFI_TX_DATA("AT+CIPMUX=0","OK",300);LcdShowStr(10,0 ,"I");/單連接if(!WIFI_T
38、X_DATA(APTCP,"OK",500) /TCP配置while(!WIFI_TX_DATA(APTCP,"ALREADY",500);LcdShowStr(13,0 ,"CUS");while(!WIFI_TX_DATA("AT+CIPMODE=1","OK",300); /開啟透?jìng)髂J絯hile(!WIFI_TX_DATA("AT+CIPSEND","OK",300); /開始發(fā)送數(shù)據(jù)WIFI_TX_DATA("TCP OK","",0);delayms(1000)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 德陽農(nóng)業(yè)科技職業(yè)學(xué)院《地貌學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 玉林師范學(xué)院《中國哲學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 昆玉職業(yè)技術(shù)學(xué)院《文學(xué)理論》2023-2024學(xué)年第一學(xué)期期末試卷
- 重慶工程職業(yè)技術(shù)學(xué)院《西方現(xiàn)代文論》2023-2024學(xué)年第一學(xué)期期末試卷
- 安徽省黃山市休寧縣2024-2025學(xué)年初三5月模擬(三模)物理試題文試題含解析
- 河南建筑職業(yè)技術(shù)學(xué)院《道路勘測(cè)設(shè)計(jì)A》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣州華商學(xué)院《基礎(chǔ)俄語四》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東省廣州市天河區(qū)2024-2025學(xué)年高三5月份階段性檢測(cè)試題-化學(xué)試題試卷含解析
- 白城師范學(xué)院《健身鍛煉方法與評(píng)定》2023-2024學(xué)年第二學(xué)期期末試卷
- 西安交通工程學(xué)院《平法識(shí)圖與鋼筋算量實(shí)訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 工業(yè)互聯(lián)網(wǎng)平臺(tái)的商業(yè)模式與盈利策略
- 2024年09月2024渤海銀行上海分行校園招聘筆試歷年參考題庫附帶答案詳解
- 2025年遼寧省遼漁集團(tuán)招聘筆試參考題庫含答案解析
- 《員工招聘與選拔》課件
- 南昌起義模板
- 【MOOC】體育舞蹈與文化-大連理工大學(xué) 中國大學(xué)慕課MOOC答案
- 接處警流程培訓(xùn)
- 2024年商丘職業(yè)技術(shù)學(xué)院單招職業(yè)技能測(cè)試題庫附答案
- 《園林植物病蟲害》課件
- 小紅書食用農(nóng)產(chǎn)品承諾書示例
- 空調(diào)維保服務(wù)投標(biāo)方案 (技術(shù)方案)
評(píng)論
0/150
提交評(píng)論