找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1709|回复: 0
收起左侧

蓝牙遥控小车程序

[复制链接]
ID:191600 发表于 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();

  
}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表