標(biāo)題: stc89c52單片機(jī)藍(lán)牙模塊+兩個(gè)超聲波程序出現(xiàn)問題 [打印本頁]

作者: 天空618    時(shí)間: 2019-7-30 22:51
標(biāo)題: stc89c52單片機(jī)藍(lán)牙模塊+兩個(gè)超聲波程序出現(xiàn)問題
想做一個(gè)小車,stc89c52單片機(jī)藍(lán)牙模塊+兩個(gè)超聲波程序出現(xiàn)問題,藍(lán)牙可以通信,電機(jī)可以運(yùn)轉(zhuǎn),但是超聲波沒有反應(yīng),請(qǐng)教各位教教我,程序應(yīng)該怎么改!

#include "reg52.h"   
#include<intrins.h>       
#define uchar unsigned char
#define uint  unsigned int
sbit IN1=P1^0;
sbit IN2=P1^1;
sbit IN3=P1^2;
sbit IN4=P1^3;
sbit IN5=P1^4;
sbit IN6=P1^5;
sbit IN7=P1^6;
sbit IN8=P1^7;
uchar receive_data;
unsigned int  time=0;
unsigned long S=0,S1=0,S2=0;
sbit Trig = P2^1;
sbit Echo = P2^0;
sbit Trig1 = P2^4;
sbit Echo1 = P2^5;

void delayms(unsigned int ms)
{
        unsigned char i=100,j;
        for(;ms;ms--)
        {
                while(--i)
                {
                        j=10;
                        while(--j);
                }
        }
}

void Conut(void)
        {
         time=TH0*256+TL0;
         TH0=0;
         TL0=0;
       
         S=(time*1.7)/100;     
          
               

}       
       
void go(void)
{
       
                                 P1=0xAA;
         
                  if(S1<30&&S2<30)
                    {P1=0x5A;}
                }
void stop (void)
               
                {
                                 P1=0x00;
               
                }
void  StartModule()                         
  {
          Trig=1;                                            
                 Trig1=1;       
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          _nop_();
          Trig=0;
                 Trig1=0;       
  }
       

       
void UsartConfiguration()
{       
        SCON=0X50;               
        TMOD=0X20;               
        PCON=0X00;               
        TH1=0XFd;                  
        TL1=0XFd;
        TR1=1;                               
        ES = 1;      
        EA = 1;      


}
void Com_Int(void) interrupt 4
{
       
  EA=0;
       

       
  if(RI == 1)
        {                
               
                receive_data = SBUF;
                        RI = 0;
                if(receive_data == '1')         
                {
                                 go();
                }
                if(receive_data == '2')         
                {
                                stop();
               
                }
               
                EA=1;
               
  }
}
void main(void)
{

         TMOD=0x01;                  
         TH0=0;
         TL0=0;         
         UsartConfiguration();

        while(1)
        {
                                StartModule();
             while(!Echo);               
             TR0=1;                            
             while(Echo);                       
             TR0=0;                               
         Conut();
       S1=S;               
                 delayms(10);
     StartModule();
             while(!Echo1);               
             TR0=1;                            
             while(Echo1);                       
             TR0=0;                               
         Conut();       
       S2=S;               
                 delayms(10);
               
        }
                       
}



作者: WD51H    時(shí)間: 2019-7-30 22:51
你的串口配置函數(shù) UsartConfiguration()中 的TMOD=0X20;     這句中把定時(shí)器0關(guān)掉了;改成 TMOD|=0X20; 就行了   
作者: kikyo52    時(shí)間: 2019-7-31 16:35
超聲波型號(hào)和驅(qū)動(dòng)程序貼出來,你貼出來的程序沒有。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1