找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 927|回复: 0
收起左侧

这个单片机+esp8266程序是哪里出问题了吗?连接不上热点

[复制链接]
ID:899080 发表于 2021-4-10 17:23 | 显示全部楼层 |阅读模式
根据程序改的单片机采集温度数据通过esp8266-01发送到网络调试助手,但是下载程序之后发现网络助手连接不上这个热点,各位大佬能帮我看看这个程序是哪里出问题了吗

单片机源程序如下:
  1. #include<intrins.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. sbit DQ=P2^4;
  5. sbit k1=P1^0;
  6. uchar aa[1]="";
  7. uint i,temp;
  8. void delay(uint i)               
  9. {
  10.         do
  11.         {
  12.                 _nop_();            
  13.                 _nop_();
  14.                 _nop_();
  15.                 i--;
  16.         }
  17.         while(i);      
  18. }
  19. void delay1(uint z)                 
  20. {
  21.         uint x,y;
  22.         for(x=z;x>0;x--)
  23.                 for(y=110;y>0;y--);
  24. }

  25. void sendChar(uchar a)                                 
  26. {
  27.         SBUF = a;
  28.         while(TI==0);
  29.         TI=0;      
  30. }

  31. void sendString(uchar *s)                        
  32. {
  33.         while(*s!='\0')
  34.         {
  35.                 sendChar(*s);
  36.                 s++;
  37.         }
  38.                
  39. }
  40. void init()
  41. {
  42.         
  43.         TMOD=0x20;                                                        
  44.         TH1=0xfd;                                                        
  45.         TL1=0xfd;
  46.         REN=1;                                                               
  47.         SM0=0;                                                               
  48.         SM1=1;                                                               
  49.         EA=1;                                                               
  50.         TR1=1;                                                               
  51.         
  52.         delay1(1000);
  53.   sendString("AT+CWMODE=2\r\n");               
  54.         delay(1000);      
  55.         
  56.         sendString("AT+CIPMUX=1\r\n");               
  57.         delay(1000);      
  58.         sendString("AT+CIPSERVER=1,8080\r\n");      
  59.         delay(1000);      
  60. }      
  61. void chuansu()                                                         
  62. {
  63.         sendString( "AT+CIPSTART=1,\"TCP\",\"192.168.4.1\",8080\r\n");
  64.   delay1(5000);
  65.   sendString("AT+CIPSEND=1,5\r\n");
  66.                   
  67.         delay1(1000);
  68.         sendString(aa);                           
  69.         delay1(1000);
  70.         
  71.         delay1(1000);               
  72.         ES=1;                                          
  73. }

  74. void DS()                  
  75. {
  76.         uchar x=0;
  77.         DQ=1;                  
  78.         delay(10);         
  79.         DQ=0;                  
  80.         delay(120);         
  81.         DQ=1;                  
  82.         delay(16);         
  83.         x=DQ;                  
  84.         delay(80);         
  85.         DQ=1;                 
  86. }
  87. uchar Read1b()                     
  88. {
  89.         uchar i=0;
  90.         uchar dat=0;
  91.         for(i=0;i<8;i++)
  92.         {
  93.                 DQ=0;                 
  94.                 delay(1);                 
  95.                 DQ=1;                        
  96.                 dat>>=1;                 
  97.                 if(DQ)                        
  98.                 dat|=0x80;                 
  99.                 delay(11);
  100.         }
  101.         return(dat);
  102. }
  103. void Write1b(uchar dat)         
  104. {
  105.         uchar i=0;
  106.         for(i=0;i<8;i++)
  107.         {
  108.                 DQ=0;
  109.                 _nop_();
  110.                 DQ=dat&0x01;
  111.                 delay(12);
  112.                 DQ=1;
  113.                 dat>>=1;
  114.                 delay(5);      
  115.         }                                                  
  116. }                                 
  117. uint Get()                                 
  118. {
  119.         uchar templ,temph,tt;
  120.         uint t;                                 
  121.         DS();                                    
  122.         Write1b(0XCC);            
  123.         Write1b(0x44);            
  124.         DS();                                
  125.         Write1b(0xcc);            
  126.         Write1b(0xbe);            
  127.         templ=Read1b();            
  128.         temph=Read1b();            
  129.         t=temph;
  130.         t<<=8;
  131.         t=t|templ;
  132.         tt=t*0.0625;                  
  133.         return(tt);               
  134. }

  135. void show(uint wd)                  
  136. {
  137.         aa[0]=wd/10+'0';         
  138.         aa[1]=wd%10+'0';
  139. }
  140. void main()
  141. {                          
  142.         init();                                 
  143.         while(1)
  144.         {
  145.                 show(Get())        ;         
  146.                 if(k1==0)                  
  147.             {      
  148.                         delay1(10);
  149.                         if(k1==0)
  150.                         {
  151.                                 chuansu();
  152.                         }
  153.                 }
  154.         }
  155. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表