久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

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

QQ登錄

只需一步,快速開(kāi)始

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

基于51單片機(jī)的藍(lán)牙小車

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:723182 發(fā)表于 2020-4-22 19:29 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
目前藍(lán)牙小車還在調(diào)試
#include <STC89C5xRC.H>

#define Left_moto2_pwm     P0_4          
#define Right_moto2_pwm    P0_5          
#define Left_moto_pwm     P1_4          
#define Right_moto_pwm    P1_5          
#define uchar unsigned char
#define uint unsigned int

sbit P0_4=P0^4;                 
sbit P0_5=P0^5;                 
sbit P1_4=P1^4;               
sbit P1_5=P1^5;               
sbit IN1 = P1^2;
sbit IN2 = P1^3;
sbit IN3 = P1^6;
sbit IN4 = P1^7;
sbit IN5 = P0^2;
sbit IN6 = P0^3;
sbit IN7 = P0^6;
sbit IN8 = P0^7;

bit Right_moto_stop=1;          
bit Left_moto_stop =1;               
unsigned  int  time=0;               
int pwm=1;

#define left_motor_en        EN1 = 1       
#define left_motor_stops        EN1 = 0       
#define right_motor_en        EN2 = 1       
#define right_motor_stops        EN2 = 0

#define left_motor2_en        EN3 = 1
#define left_motor2_stops        EN3 = 0       
#define right_motor2_en        EN4 = 1       
#define right_motor2_stops        EN4 = 0       

#define left_motor_go        IN1 = 0, IN2 = 1
#define left_motor_back        IN1 = 1, IN2 = 0
#define right_motor_go        IN3 = 1, IN4 = 0
#define right_motor_back        IN3 = 0, IN4 = 1

#define left_motor2_go        IN5 = 0, IN6 = 1
#define left_motor2_back        IN5 = 1, IN6 = 0
#define right_motor2_go        IN7 = 1, IN8 = 0
#define right_motor2_back        IN7 = 0, IN8 = 1

unsigned char pwm_val_left  =0;
unsigned char push_val_left =0;
unsigned char pwm_val_right =0;
unsigned char push_val_right=0;
void delay(uint z)
{
        uint x,y;
        for(x = z; x > 0; x--)
        for(y = 114; y > 0 ; y--);
}
void UART_INIT()
{
        SM0 = 0;
        SM1 = 1;
        REN = 1;                                                                                                                 
        EA = 1;
        ES = 1;
        TMOD = 0x20;
        TH1 = 0xfd;
        TL1 = 0xfd;
        TR1 = 1;
}
     void  run(void)       
{
     push_val_left  =pwm;  
         push_val_right =pwm;         
         if(pwm==10) pwm=0;
         if(pwm==0&&pwm<0) pwm=0;
}
                void pwm_out_left_moto(void)
{  
   if(Left_moto_stop)
   {
    if(pwm_val_left<=push_val_left)
             {  Left_moto_pwm=1;
                    Left_moto2_pwm=1;  }
        else
              { Left_moto_pwm=0;Left_moto2_pwm=0;                 }

        if(pwm_val_left>=10)
        pwm_val_left=0;
   }
   else { Left_moto_pwm=0;Left_moto2_pwm=0;          }
}
   void pwm_out_right_moto(void)
{
  if(Right_moto_stop)
   {
    if(pwm_val_right<=push_val_right)
             {  Right_moto_pwm=1;
                   Right_moto2_pwm=1;           }
        else
               {Right_moto_pwm=0;
                    Right_moto2_pwm=0;}
        if(pwm_val_right>=10)
            pwm_val_right=0;
   }
   else    {Right_moto_pwm=0;Right_moto2_pwm=0;        }
}
        void timer0()interrupt 1   using 2
{
     TH0=0XF8;         
         TL0=0X30;
         time++;
         pwm_val_left++;
         pwm_val_right++;
         pwm_out_left_moto();
         pwm_out_right_moto();
}
void forward()
{
        ET0 = 1;
        run();                         
        left_motor_go;
        right_motor_go;
        left_motor2_go;
        right_motor2_go;
}
void left_go()          
{
        ET0 = 1;
        run();
        left_motor_back;
        right_motor_go;
        left_motor2_back;
        right_motor2_go;
        delay(700);
        forward();
}
void right_go()
{
        ET0 = 1;
        run();
        delay(50);
        right_motor_back;
        left_motor_go;
        right_motor2_back;
        left_motor2_go;
        delay(700);
        forward();
}
void left()
{
        ET0 = 1;
        run();
        delay(50);
        right_motor_go;                  
        left_motor_back;       
        right_motor2_go;                  
        left_motor2_back;       
}
void right()
{
        ET0 = 1;
        run();
        left_motor_go;
        right_motor_back;  
        left_motor2_go;
        right_motor2_back;
}
void back()
{
        ET0 = 1;
        run();
        left_motor_back;
        right_motor_back;       
        left_motor2_back;
        right_motor2_back;
}


void stop()
{
        ET0 = 0;
        P1=0;
        P0=0;
}

void UART_SER() interrupt 4
{
        if(RI)
        {
                RI = 0;
                switch(SBUF)
                {
                        case 'g': forward(); break;
                        case 'b': back(); break;
                        case 'l': left(); break;
                        case 'r': right(); break;
                        case 's': stop(); break;
                        case 'z': left_go(); break;
                         case 'y': right_go(); break;
                        case 'p': pwm++;break;               
                        case 'c': pwm--;break;               
                }
        }
}
void main()
{
        TMOD=0X01;
        TH0= 0XF8;                 
        TL0= 0X30;
        TR0= 1;
        ET0= 1;
        EA = 1;
        UART_INIT();
        while(1);
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 欧美日韩久久 | 五月激情婷婷在线 | 麻豆精品国产91久久久久久 | 成人a免费 | 粉嫩一区二区三区国产精品 | 在线免费观看成年人视频 | 欧美日韩久久精品 | 国产高清在线 | 国产激情小视频 | 在线观看中文字幕一区二区 | 羞羞色视频 | 久久电影一区 | 91在线视频免费观看 | 欧美日韩不卡合集视频 | 午夜影院在线观看 | 天天人人精品 | 国产区第一页 | 久久综合一区二区 | 视频一区二区三区中文字幕 | 黑人巨大精品欧美一区二区免费 | 狠狠的操 | aaaaaa大片免费看最大的 | 久久久久久亚洲国产精品 | 一级黄色片一级黄色片 | www视频在线观看 | 欧美日韩亚洲国产 | 精品中文字幕一区二区三区 | 日韩一级免费电影 | a欧美 | 毛片免费看 | 天天草视频| 国产91色在线 | 亚洲 | 国产一区二区三区四区 | xxxxx免费视频 | 蜜桃视频在线观看免费视频网站www | 免费一区二区三区 | 日韩中文字幕av | 日本精品视频一区二区 | 亚洲一区二区视频在线播放 | 91色视频在线观看 | 亚洲国产精品视频一区 |