欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 跪求基于51單片機藍牙控制小車的源程序 [打印本頁]

作者: why1111    時間: 2017-3-28 19:38
標題: 跪求基于51單片機藍牙控制小車的源程序
迫切的需要。!跪求!
作者: 雨林木木風    時間: 2017-12-5 15:52
簡單實現前后左右

#include<AT89x51.H>

//HL-1小車驅動接線定義
#define A_left_moto_go  {P2_0 = 1,P2_1 = 0;}
#define A_left_moto_back {P2_0 = 0,P2_1 = 1;}
#define A_left_moto_stop {P2_0 = 0,P2_1 = 0;}
#define A_right_moto_go {P2_2 = 1,P2_3 = 0;}
#define A_right_moto_back {P2_2 = 0,P2_3 = 1;}
#define A_right_moto_stop {P2_2 = 0,P2_3 = 0;}

#define B_left_moto_go {P1_0 = 1,P1_1 = 0;}
#define B_left_moto_back {P1_0 = 0,P1_1 = 1;}
#define B_left_moto_stop {P1_0 = 0,P1_1 = 0;}
#define B_right_moto_go {P1_2 = 1,P1_3 = 0;}
#define B_right_moto_back {P1_2 = 0,P1_3 = 1;}
#define B_right_moto_stop {P1_2 = 0,P1_3 = 0;}                    

#define uint    unsigned int                          //重定義無符號整數類型
#define uchar   unsigned char                         //重定義無符號字符類型

#define led P0_0

/************************************************************************/        
//延時函數        
   void delay(unsigned int k)
{   
     unsigned int x,y;
         for(x=0;x<k;x++)
           for(y=0;y<2000;y++);
}

/************************************************************************/
void run()
{
        A_left_moto_go;
        A_right_moto_go;
        B_left_moto_go;
        B_right_moto_go;
}

void back_run()
{
        A_left_moto_back;
        A_right_moto_back;
        B_left_moto_back;
        B_right_moto_back;
}

void stop_run()
{
        A_left_moto_stop;
        A_right_moto_stop;
        B_left_moto_stop;
        B_right_moto_stop;
}

void left_run()
{
        A_left_moto_back;
        A_right_moto_go;
        B_left_moto_back;
        B_right_moto_go;
}

void right_run()
{
        A_left_moto_go;
        A_right_moto_back;
        B_left_moto_go;
        B_right_moto_back;
}



char uart_data; // 函數變量
char temp;

void main(void) //主函數
{        
        SCON=0X50; //設置串口方式為1 方式1
        TMOD=0X20;//設置為定時器1,
        TH1= 0x0FD; //賦初值
        TL1= 0x0FD;
        ES=1; //開串口中斷
        EA=1; //開中中斷
        TR1=1; //啟動定時器1
        led = 1; //p2.0置1,燈滅
        while(1);
}


void serial_IT(void) interrupt 4 //中斷程序
{
        if(RI==1) //R1置1.向cpu 申請中斷,循環
{
        RI=0; //軟件清零,取消申請
        uart_data = SBUF; //藍牙輸入數據賦值
        SBUF = uart_data; //返回終端
        temp = uart_data; //賦值
        if(temp == 0x00 ) led = ~led;
        switch(temp)
        {
                case 'a'         :        run();                 break;// 前進
                case 'b'        :         back_run();        break;//后退
                case 'c'        :        left_run();        break;//左轉
                case 'd'        :        right_run();break;//右轉
                case 'e'        :        stop_run();        break;//停止
        }
        }
        else T1 = 0; //中斷關閉






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