找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2136|回復(fù): 0
收起左側(cè)

藍牙遙控小車程序

[復(fù)制鏈接]
ID:191600 發(fā)表于 2017-4-22 13:00 | 顯示全部樓層 |閱讀模式
#include<AT89x51.H>
#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 B_left_moto_go {P2_2 = 1,P2_3 = 0;}  //  
#define B_left_moto_back {P2_2 = 0,P2_3 = 1;} //
#define B_left_moto_stop {P2_2 = 0,P2_3 = 0;}   //

#define A_right_moto_go {P1_0 = 1,P1_1 = 0;}  //右前輪向前
#define A_right_moto_back {P1_0 = 0,P1_1 = 1;}  //右前輪向后
#define A_right_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                         //??????????
sbit BZ=P3^7;
a=0;
void delay(uchar z)//??????????
{
int i,j;//??????
for(i=10;i>0;i--)
for(j=z;j>0;j--);//???z???j
}

void uart_init()
{
  TMOD = 0x20;
  PCON = 0x00;
  SCON = 0x50;
  TH1 = 0xFd;  //????? 9600
  TL1 = 0xFd;
  TR1 = 1;     //?????1
  ES = 1;      //?????
  EA = 1;      //????
  BZ=1;
}

/************************************************************************/
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;
}

void uart() interrupt 4
{
if(RI==1)
RI=0;
a=SBUF;
}

void main()
{
//P0=0XFF;
uart_init();
while(1)
{
  if(BZ==0)   stop_run();
  if(a==0x00) stop_run();
  if(a==0x3f) run();
  if(a==0x4f) back_run();
  if(a==0x1f) left_run();
  if(a==0x2f) right_run();
  if(a==0x5f) left_run();
  if(a==0x6f) right_run();
  if(a==0x7f) left_run();
  if(a==0x8f) right_run();

  
}
}
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

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