找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1987|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

跪求基于51單片機(jī)藍(lán)牙控制小車的源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:184239 發(fā)表于 2017-3-28 19:38 來自觸屏版 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
迫切的需要。!跪求!
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:255476 發(fā)表于 2017-12-5 15:52 | 只看該作者
簡(jiǎn)單實(shí)現(xiàn)前后左右

#include<AT89x51.H>

//HL-1小車驅(qū)動(dòng)接線定義
#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                          //重定義無符號(hào)整數(shù)類型
#define uchar   unsigned char                         //重定義無符號(hào)字符類型

#define led P0_0

/************************************************************************/        
//延時(shí)函數(shù)        
   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; // 函數(shù)變量
char temp;

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


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

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表