新手上路
- 积分
- 46
- 金钱
- 46
- 注册时间
- 2019-7-15
- 在线时间
- 11 小时
|
楼主 |
发表于 2019-8-6 12:30:55
|
显示全部楼层
只能控制LED0开关,不能进行呼吸,这是为什么啊,我搞了半个多月了,现在都还没有搞出来
- u8 atk_8266_wifiap_test(void)
- {
- u8 data=1;
- u16 num=1;
- static u16 led1pwmval=0;
- static u8 dir=1;
- u8 netpro=0; //ÍøÂçģʽ
- u8 key;
- u8 timex=0;
- u8 ipbuf[16]; //IP»º´æ
- u8 *p;
- u16 t=999; //¼ÓËÙµÚÒ»´Î»ñÈ¡Á´½Ó״̬
- u8 res=0;
- u16 rlen=0;
- u8 constate=0; //Á¬½Ó״̬
- uart_init(84,115200); //´¿Ú³õʼ»¯Îª115200
- LED_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú
- Stm32_Clock_Init(336,8,2,7); //ÉèÖÃʱÖÓ,168Mhz
- delay_init(168); //ÑÓʱ³õʼ»¯
- TIM14_PWM_Init(500-1,84-1); //1MhzµÄ¼ÆÊýƵÂÊ,2KhzµÄPWM.
- usart3_init(42,115200); //´®¿Ú3³õʼ»¯
- TIM3_Int_Init(5000-1,8400-1);
- p=mymalloc(SRAMIN,32); //ÉêÇë32×Ö½ÚÄÚ´æ
- PRESTA:
- netpro=atk_8266_netpro_sel(50,30,(u8*)ATK_ESP8266_CWMODE_TBL[1]); //Ñ¡ÔñÍøÂçģʽ
- if(netpro&0X02) //UDP
- {
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- Show_Str_Mid(0,30,"ATK-ESP WIFI-AP ²âÊÔ",16,240);
- Show_Str(30,50,200,16,"ÕýÔÚÅäÖÃATK-ESPÄ£¿é,ÇëÉÔµÈ...",12,0);
- if(atk_8266_ip_set("WIFI-AP Ô¶¶ËUDP IPÉèÖÃ",(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],(u8*)portnum,ipbuf))goto PRESTA; //IPÊäÈë
- sprintf((char*)p,"AT+CIPSTART="UDP","%s",%s",ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±êUDP·þÎñÆ÷
- atk_8266_send_cmd("AT+CIPMUX=0","OK",100); //µ¥Á´½Óģʽ
- LCD_Clear(WHITE);
- while(atk_8266_send_cmd(p,"OK",500));
-
- }
- else //TCP
- {
- if(netpro&0X01) //TCP Client ͸´«Ä£Ê½²âÊÔ
- {
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- Show_Str_Mid(0,30,"ATK-ESP WIFI-AP ²âÊÔ",16,240);
- Show_Str(30,50,200,16,"ÕýÔÚÅäÖÃATK-ESPÄ£¿é,ÇëÉÔµÈ...",12,0);
- if(atk_8266_ip_set("WIFI-AP Ô¶¶ËIPÉèÖÃ",(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],(u8*)portnum,ipbuf))goto PRESTA; //IPÊäÈë
- atk_8266_send_cmd("AT+CIPMUX=0","OK",20); //0£ºµ¥Á¬½Ó£¬1£º¶àÁ¬½Ó
- sprintf((char*)p,"AT+CIPSTART="TCP","%s",%s",ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±êTCP·þÎñÆ÷
- while(atk_8266_send_cmd(p,"OK",200))
- {
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- Show_Str_Mid(0,40,"WK_UP:·µ»ØÖØÑ¡",16,240);
- Show_Str_Mid(0,80,"ATK-ESP Á¬½ÓTCP Serverʧ°Ü",12,240); //Á¬½Óʧ°Ü
- key=KEY_Scan(0);
- if(key==WKUP_PRES)goto PRESTA;
- }
- atk_8266_send_cmd("AT+CIPMODE=1","OK",200); //´«ÊäģʽΪ£ºÍ¸´«
- }
- else //TCP Server
- {
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- Show_Str_Mid(0,30,"ATK-ESP WIFI-AP ²âÊÔ",16,240);
- Show_Str(30,50,200,16,"ÕýÔÚÅäÖÃATK-ESPÄ£¿é,ÇëÉÔµÈ...",12,0);
- atk_8266_send_cmd("AT+CIPMUX=1","OK",20); //0£ºµ¥Á¬½Ó£¬1£º¶àÁ¬½Ó
- sprintf((char*)p,"AT+CIPSERVER=1,%s",(u8*)portnum);
- atk_8266_send_cmd(p,"OK",20); //¿ªÆôServerģʽ£¬¶Ë¿ÚºÅΪ8086
- }
- }
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- Show_Str_Mid(0,30,"ATK-ESP WIFI-AP ²âÊÔ",16,240);
- Show_Str(30,50,200,16,"ÕýÔÚÅäÖÃATK-ESPÄ£¿é,ÇëÉÔµÈ...",12,0);
- LCD_Fill(30,50,239,50+12,WHITE); //Çå³ý֮ǰµÄÏÔʾ
- Show_Str(30,50,200,16,"ÅäÖÃATK-ESPÄ£¿é³É¹¦!",12,0);
- delay_ms(200);
- Show_Str(30,50,200,16,"WK_UP:Í˳ö²âÊÔ KEY0:·¢ËÍÊý¾Ý",12,0);
- LCD_Fill(30,80,239,80+12,WHITE);
- atk_8266_get_wanip(ipbuf);//·þÎñÆ÷ģʽ,»ñÈ¡WAN IP
- sprintf((char*)p,"IPµØÖ·:%s ¶Ë¿Ú:%s",ipbuf,(u8*)portnum);
- Show_Str(30,65,200,12,p,12,0); //ÏÔʾIPµØÖ·ºÍ¶Ë¿Ú
- Show_Str(30,80,200,12,"״̬:",12,0); //Á¬½Ó״̬
- Show_Str(120,80,200,12,"ģʽ:",12,0); //Á¬½Ó״̬
- Show_Str(30,100,200,12,"·¢ËÍÊý¾Ý:",12,0); //·¢ËÍÊý¾Ý
- Show_Str(30,115,200,12,"½ÓÊÕÊý¾Ý:",12,0); //½ÓÊÕÊý¾Ý
- atk_8266_wificonf_show(30,180,"ÇëÓÃÉ豸Á¬½ÓWIFIÈȵã:",(u8*)wifiap_ssid,(u8*)wifiap_encryption,(u8*)wifiap_password);
- POINT_COLOR=BLUE;
- Show_Str(120+30,80,200,12,(u8*)ATK_ESP8266_WORKMODE_TBL[netpro],12,0); //Á¬½Ó״̬
- USART3_RX_STA=0;
-
- while(1)
- {
- key=KEY_Scan(0);
- if(key==WKUP_PRES) //WK_UP Í˳ö²âÊÔ
- {
- res=0;
- atk_8266_quit_trans(); //Í˳ö͸´«
- atk_8266_send_cmd("AT+CIPMODE=0","OK",20); //¹Ø±Õ͸´«Ä£Ê½
- break;
- }
- else if(key==KEY0_PRES) //KEY0 ·¢ËÍÊý¾Ý
- {
-
- if((netpro==3)||(netpro==2)) //UDP
- {
- sprintf((char*)p,"ATK-8266%s²âÊÔ%02d\r\n",ATK_ESP8266_WORKMODE_TBL[netpro],t/10);//²âÊÔÊý¾Ý
- Show_Str(30+54,100,200,12,p,12,0);
- atk_8266_send_cmd("AT+CIPSEND=25","OK",200); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
- delay_ms(200);
- atk_8266_send_data(p,"OK",100); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
- timex=100;
- }
- else if((netpro==1)) //TCP Client
- {
- atk_8266_quit_trans();
- atk_8266_send_cmd("AT+CIPSEND","OK",20); //¿ªÊ¼Í¸´«
- sprintf((char*)p,"ATK-8266%s²âÊÔ%02d\r\n",ATK_ESP8266_WORKMODE_TBL[netpro],t/10);//²âÊÔÊý¾Ý
- Show_Str(30+54,100,200,12,p,12,0);
- u3_printf("%s",p);
- timex=100;
- }
- else //TCP Server
- {
- sprintf((char*)p,"ATK-8266%s²âÊÔ%02d\r\n",ATK_ESP8266_WORKMODE_TBL[netpro],t/10);//²âÊÔÊý¾Ý
- Show_Str(30+54,100,200,12,p,12,0);
- atk_8266_send_cmd("AT+CIPSEND=0,25","OK",200); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
- delay_ms(200);
- atk_8266_send_data(p,"OK",100); //·¢ËÍÖ¸¶¨³¤¶ÈµÄÊý¾Ý
- timex=100;
- }
- }
-
- if(timex)timex--;
- if(timex==1)LCD_Fill(30+54,100,239,112,WHITE);
- t++;
- delay_ms(5);
-
- if(t==1000)//Á¬Ðø10ÃëÖÓûÓÐÊÕµ½ÈκÎÊý¾Ý,¼ì²éÁ¬½ÓÊDz»ÊÇ»¹´æÔÚ.
- {
- constate=atk_8266_consta_check();//µÃµ½Á¬½Ó״̬
- if(constate=='+')Show_Str(30+30,80,200,12,"Á¬½Ó³É¹¦",12,0); //Á¬½Ó״̬
- else Show_Str(30+30,80,200,12,"Á¬½Óʧ°Ü",12,0);
- t=0;
- }
- if((t%20)==0)LED0=!LED0;
- atk_8266_at_response(1);
-
- while(1)
- {
- if(USART3_RX_STA&0X8000) //½ÓÊÕµ½Ò»´ÎÊý¾ÝÁË
- {
- rlen=USART3_RX_STA&0x7FFF; //µÃµ½´Ë´Î½ÓÊÕµ½µÄÊý¾Ý³¤¶
- printf("%s",USART3_RX_BUF); //·¢Ë͵½´®¿Ú
- for(t=0;t<rlen;t++)
- {
- USART3->DR=USART3_RX_BUF[t]; //·¢ËÍÊý¾Ý
- while((USART3->SR&0X40)==0); //µÈ´ý·¢ËͽáÊø
- }
- data=USART3_RX_BUF[0]; //µÃµ½µÚÒ»¸öÊý¾Ý
- printf("\r\n\r\n");//²åÈë»»ÐÐ
- USART3_RX_STA=0;
-
-
- switch(data)
- {
- case 0x30: num=1;break; //°´0¹Ø±ÕLDE1
- case 0x31: num=2;break; //°´1LED1µÄÁÁ¶È×î´ó
- case 0x32: num=3;break; //°´2LED1¿ªÊ¼ºôÎü
- case 0x33: num=4;break; //°´3LED1±£³Öµ±Ç°ÁÁ¶È
-
- }
- switch(num)
- {
-
- case 1: LED1_PWM_VAL=0;break;
- case 2: LED1_PWM_VAL=400;break;
- case 3:
- delay_ms(10);
- if(dir)led1pwmval++;
- else led1pwmval--;
- if(led1pwmval>400)dir=0;
- if(led1pwmval==0)dir=1;
- LED1_PWM_VAL=led1pwmval;
- break;
- case 4:break;
-
- }
- }
- }
- }
-
- myfree(SRAMIN,p); //ÊÍ·ÅÄÚ´æ
- return res;
- }
复制代码 |
|