利用51單片機和光敏模塊 、ESP8266WiFi模塊結合,制作的智能窗簾,控制步進電機正反轉三圈,但程序不知道有什么問題,可以正常編譯,但下載到單片機上,手機顯示無法連接,之前一直都是可以連接成功的。麻煩哪位大神可以幫忙看一下?
- #include "reg51.h"
- #define uint unsigned int
- #define uchar unsigned char
- //單片機的引腳定義
- sbit gm=P1^1;
- sbit wd1=P1^2;
- sbit wd2=P1^3;
- sbit zsd1=P0^0;
- sbit zsd2=P0^1;
- //步進電機的正反轉代碼
- unsigned char kongzhi=0;
- unsigned char code RUN1[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};//正轉
- unsigned char code RUN2[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1};//反轉
- //初始化程序
- void chushihua()
- {
- IE=0x90;
- SCON=0x50;
- TMOD=0x20; //
- TH1=0xfd; //波特率設置為9600
- TL1=0xfd;
- TCON=0x40;
- TR1=1;
- ES = 1; //開串行口中斷
- EA=1; //開總中斷
- }
- //串行口連續發送char型數組,遇到終止號/0將停止
- void fasongshuju(uchar *str)
- {
- while(*str!='\0')
- {
- SBUF=*str;
- while(!TI);//等待發送完成信號(TI=1)出現
- TI=0;
- str++;
- }
- }
- //延時函數
- void yanshi(uint ttt)
- {
- while(ttt--);
- }
- //ESP8266上電初始化
- void wifichushihua()
- {
- fasongshuju("AT+CIPMUX=1\r\n");
- yanshi(50000);
- fasongshuju("AT+CIPSERVER=1,8080\r\n");
- }
- JC
- /***********延時函數***********/
- void delay(unsigned int t)
- {
- unsigned int k;
- while(t--)
- {
- for(k=0; k<60; k++)//用for的空循環延長程序的執行時間
- { }
- }
- }
- //步進電機驅動 正轉
- void zz(uchar n)
- {
- unsigned char i,j;
- for(j=0;j<5*n;j++)
- for (i=0; i<8; i++)
- {
- P2 = RUN1[i]&0x1f; //取數據
- delay(2); //調節轉速
- zsd1=0;
- zsd2=1;
- }
- }
- //步進電機驅動 反轉
- void fz()
- {
- unsigned char i,j;
- for(j=0;j<5*n;j++)
- for (i=0; i<8; i++)
- {
- P2 = RUN2[i]&0x1f; //取數據
- delay(2); //調節轉速
- zsd1=1;
- zsd2=0;
- }
- }
- //傳感器自動控制的
- void zidong()
- {
- if(gm==0)//有光的時候電機正轉
- {
- zz(N);
- }
- if(gm==1)//無光的時候電機反轉
- {
- fz(N);
- }
- }
- void main()
- {
- yanshi(50000);
- yanshi(5000);
- chushihua();
- wifichushihua();
- uchar N=3
- while(1)
- {
- if(kongzhi==1)
- {
- zz(N);
- }
- if(kongzhi==2)
- {
- fz(N);
- }
- if(kongzhi==3)
- {
- P2=0xff;
- zsd1=1;
- zsd2=1;
-
- }
- if(kongzhi==4)
- {
- zidong();
- }
- if(wd1==0||wd2==0)
- {
- kongzhi=3;
- }
-
- }
- }
- /*
- 串口服務子函數
- */
- void time() interrupt 4
- {
- if(RI)
- {
- RI=0; //接收中斷信號清零,表示將繼續接收
- switch(SBUF)
- {
- case 'a':kongzhi=1; break;//接收到安卓端的'a'字符
- case 'b':kongzhi=2; break;//接收到安卓端的'b'字符
- case 'c':kongzhi=3;break;//接收到安卓端的'c'字符
- case 'd':kongzhi=4;break;//接收到安卓端的'd'字符
- }
- }
- }
復制代碼
|