标题:
利用ESP8266实现的双电子设备通信实验程序
[打印本页]
作者:
Sicinera
时间:
2019-8-12 11:14
标题:
利用ESP8266实现的双电子设备通信实验程序
功能并不复杂,会用ESP8266便能想到思路;
但是在实现wifi模块接受设备一的消息后将消息处理后发送给设备二的功能时,还是颇费脑筋的;
最后一提,当时找不到现成历程,oled字模便自己取了,这么一说没有功劳也有苦劳了哈。
以下是部分程序:
#include <reg52.h>
#include <stdio.h>
#include <string.h>
#include <intrins.h>
#define U unsigned char
sbit scl=P1^1;
sbit sda=P1^0;
sbit key1=P1^6;
sbit key2=P1^7;
U a[81]={1},st=1,sq=1;
char page=0;
U num=0,sw=1; //"Enter" controlling
U code order1[]="AT+RST\r\n";
U code order2[]="AT+CWMODE=2\r\n";
U code order3[]="AT+CWSAP=\"sPinAr\",\"22222222\",11,3\r\n";
U code order4[]="AT+CIPMUX=1\r\n";
U code order5[]="AT+CIPSERVER=1,808
void time(){
U i,j;
for(i=200;i>0;i--)
for(j=200;j>0;j--);
}
U scan(){
U i;
if(!key1){
time();while(!key1);
return 2;
}
if(!key2){
time();while(!key2);
return 2;
}
if(sw&&num>=2){
for(i=1;i<81;i++)a[i]=0;
sw=0;
return 3;
}
return 0;
}
void wificommand(U k[]){
U i,j;
ES=0;
TI=1;
puts(k);
while(!TI);
TI=0;
ES=1;
while(1){
if(a[1]){
OLED_SetPos(0,page);
for(i=1;i<81;i++){
if(a[i]>='0'&&a[i]<='9')
for(j=0;j<6;j++)dat(digital[a[i]-48][j]);
else if(a[i]=='.')
for(j=0;j<6;j++)dat(dt_pls[0][j]);
else if(a[i]>='A'&&a[i]<='Z')
for(j=0;j<6;j++)dat(alpha[a[i]-65][j]);
else if(a[i]>='a'&&a[i]<='z')
for(j=0;j<6;j++)dat(bet[a[i]-97][j]);
else if(a[i]=='+')
for(j=0;j<6;j++)dat(dt_pls[1][j]);
else dat(0x00);
}
}
if(scan()==2){
for(i=1;i<81;i++)a[i]=0;
break;
}
}
page=4*!page;
}
void doublechat(){
U i,j,l;
while(1){
if(a[3]=='+'&&a[4]=='I'&&a[5]=='P'&&a[6]=='D'&&sq){
sq=0;
l=(a[11]>='0'&&a[11]<='9')?(a[10]-48)*10+(a[11]-48):a[10]-48;
if(a[8]-48){
if(l==1){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,1\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==2){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,2\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==3){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,3\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==4){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,4\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==5){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,5\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==6){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,6\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==7){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,7\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==8){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,8\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==9){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,9\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==10){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,10\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==11){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,11\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==12){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,12\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==13){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,13\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==14){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,14\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==15){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,15\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==16){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,16\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==17){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,17\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==18){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,18\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==19){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,19\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else{
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=0,20\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
}
else{
if(l==1){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,1\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==2){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,2\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==3){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,3\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==4){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,4\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==5){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,5\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==6){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,6\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==7){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,7\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==8){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,8\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==9){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,9\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+12);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==10){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,10\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==11){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,11\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==12){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,12\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==13){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,13\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==14){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,14\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==15){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,15\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==16){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,16\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==17){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,17\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==18){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,18\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else if(l==19){
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,19\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
else{
st=0;
ES=0;
TI=1;
printf("AT+CIPSEND=1,20\r\n");
while(!TI);
TI=0;
time();
TI=1;
puts(a+13);
while(!TI);
TI=0;
ES=1;
time();
st=1;
}
}
}
if(a[1]){
OLED_SetPos(0,page);
for(i=1;i<81;i++){
if(a[i]>='0'&&a[i]<='9')
for(j=0;j<6;j++)dat(digital[a[i]-48][j]);
else if(a[i]=='.')
for(j=0;j<6;j++)dat(dt_pls[2][j]);
else if(a[i]>='A'&&a[i]<='Z')
for(j=0;j<6;j++)dat(alpha[a[i]-65][j]);
else if(a[i]>='a'&&a[i]<='z')
for(j=0;j<6;j++)dat(bet[a[i]-97][j]);
else if(a[i]=='+')
for(j=0;j<6;j++)dat(dt_pls[1][j]);
else if(a[i])for(j=0;j<6;j++)dat(0x00);
}
}
switch(scan()){
case 1:
case 3:for(i=1;i<81;i++)a[i]=0;
sq=1;
goto lop;
case 2:for(i=1;i<81;i++)a[i]=0;
OLED_clear();
sq=page=0;
}
}
lop:
page+=2;
if(page==8){
time();time();time();time();time();time();
time();time();time();time();time();time();
OLED_clear();
page=0;
}
}
main(){
TMOD=0x21;
TH1=TL1=0xfd;
TH0=0x4c;
TL0=0xd0;
EA=ET0=ES=SM1=TR1=REN=1;
SM0=TR0=0;
iic_init();
OLED_Init();
wificommand(order1);
wificommand(order2);
wificommand(order3);
wificommand(order4);
wificommand(order5);
wificommand(order6);
time();time();time();time();time();time();
time();time();time();time();time();time();
TR0=1;
page=-2;
OLED_clear();
while(1)doublechat();
}
复制代码
0.png
(6.68 KB, 下载次数: 28)
下载附件
2019-8-13 01:32 上传
全部资料51hei下载地址(有乱码,谨慎下载):
programme.7z
(10.25 MB, 下载次数: 7)
2019-8-13 01:32 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1