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

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

QQ登錄

只需一步,快速開始

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

一個(gè)51單片機(jī)打箱裝置源程序(電機(jī)控制)

[復(fù)制鏈接]
ID:340753 發(fā)表于 2018-10-18 10:50 | 顯示全部樓層 |閱讀模式
#include<AT89X52.h>
/****************定義***************/
#define  uint  unsigned  int                                                                //宏定義
#define  uchar  unsigned  char

unsigned char  a=0;
unsigned char  b=0;
unsigned char  c=0;
unsigned char  d=0;
unsigned char  e=0;
unsigned char  f=0;

void delay(uint  z)                                                                                         
{
       uint x,y;
         for(x=z;x>0;x--)
            for(y=110;y>0;y--);
}

/******************電機(jī)*****************/                                                                                                
void motor1(unsigned char direction_flag)                                                                 //吸盤電機(jī)
{
        switch(direction_flag)
        {
                case 0:                                                                                                                            //吸盤電機(jī)停止
                        P1_0=0;
                        P1_1=0;
                        break;         
                case 1:                                                                                                                         //吸盤電機(jī)正轉(zhuǎn)
                        P1_0=0;
                        P1_1=1;
                        break;
                case 2:                                                                                                                         //吸盤電機(jī)反轉(zhuǎn)
                        P1_0=1;
                        P1_1=0;
                        break;
                default:
                        break;
        }        

}

void motor2(unsigned char direction_flag)                                                                    //左右電機(jī)
{
        switch(direction_flag)
        {
                case 0:                                                                                                                           //左右電機(jī)停止
                        P1_2=0;
                        P1_3=0;
                        break;
                case 1:                                                                                                                           //左右電機(jī)正轉(zhuǎn)
                        P1_2=0;
                        P1_3=1;
                        break;
                case 2:                                                                                                                           //左右電機(jī)反轉(zhuǎn)
                        P1_2=1;
                        P1_3=0;
                        break;
                default:
                        break;
        }        

}

void motor3(unsigned char direction_flag)                                                                                //前進(jìn)電機(jī)
{
        switch(direction_flag)
        {
                case 0:                                                                                                                           //前進(jìn)電機(jī)停止
                        P1_4=0;
                        P1_5=0;
                        break;
                case 1:                                                                                                                           //前進(jìn)電機(jī)正轉(zhuǎn)
                        P1_4=0;
                        P1_5=1;
                        break;
                case 2:                                                                                                                           //前進(jìn)電機(jī)反轉(zhuǎn)
                        P1_4=1;
                        P1_5=0;
                        break;
                default:
                        break;
        }        

}

void motor4(unsigned char direction_flag)                                                                                //選轉(zhuǎn)電機(jī)
{
        switch(direction_flag)
        {
                case 0:                                                                                                                           //選轉(zhuǎn)電機(jī)停止
                        P1_6=0;
                        P1_7=0;
                        break;
                case 1:                                                                                                                           //選轉(zhuǎn)電機(jī)正轉(zhuǎn)
                        P1_6=0;
                        P1_7=1;
                        break;
                case 2:                                                                                                                           //選轉(zhuǎn)電機(jī)反轉(zhuǎn)
                        P1_6=1;
                        P1_7=0;
                        break;
                default:
                        break;
        }        

}

void motor5(unsigned char direction_flag)                                             //關(guān)箱電機(jī)
{
        switch(direction_flag)
        {
                case 0:                                                                                                        //關(guān)箱電機(jī)停止
                        P3_4=0;
                        P3_5=0;
                        break;
                case 1:                                                                                                        //關(guān)箱電機(jī)正轉(zhuǎn)
                        P3_4=0;
                        P3_5=1;
                        break;
                case 2:                                                                                                         //關(guān)箱電機(jī)反轉(zhuǎn)
                        P3_4=1;
                        P3_5=0;
                        break;
                default:
                        break;
        }        

}

void motor6(unsigned char direction_flag)                                             //切刀電機(jī)
{
        switch(direction_flag)
        {
                case 0:                                                                                                        //切刀電機(jī)停止
                        P3_6=0;
                        P3_7=0;
                        break;
                case 1:                                                                                                        //切刀電機(jī)正轉(zhuǎn)
                        P3_6=0;
                        P3_7=1;
                        break;
                case 2:                                                                                                         //切刀電機(jī)反轉(zhuǎn)
                        P3_6=1;
                        P3_7=0;
                        break;
                default:
                        break;
        }        

}

/*****************主函數(shù)***************/
void main()
{
        
  P1=0Xff;
        P3=0Xff;
                        /*************過程一   平臺(tái)向右準(zhǔn)備吸箱***********/
        motor1(1);                                                                                //吸箱電機(jī)
        motor2(1);                                                                                //左右電機(jī)
        motor3(0);                                                                                //前進(jìn)電機(jī)
  motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
        motor5(0);                                                                                //關(guān)箱電機(jī)
        motor6(0);                                                                                //切刀電機(jī)

/*******************************電機(jī)部分***************************/
  while(1)
  {
        if(!P0_0)                                                                                                                                     //限位開關(guān)一
        {
                delay(10);
                if(!P0_0)                                                                                                                                 
            {

                /*************過程六    第一次將打箱裝置收回
                              過程十三    第二次將打箱裝置收回***********/
                        if(a==0)
                        {
                                   motor1(1);                                                                                //吸箱電機(jī)
                                  motor2(0);                                                                                //左右電機(jī)
                                  motor3(0);                                                                                //前進(jìn)電機(jī)
                motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
                      motor5(2);                                                                                //關(guān)箱電機(jī)
                      motor6(0);                                                                                //切刀電機(jī)
                        }
                        while(!P0_0);
                        a++;
                        if(a==1)
                        {
                                a=0;
                        }
                }
        }

        if(!P0_1)                                                                                                                                      //限位開關(guān)二
        {        
                delay(10);
                if(!P0_1)                                                                                                                                    
                {            
                           /*************過程二   平臺(tái)前進(jìn)吸箱*************/
                        if(b==0)
                        {
                                    motor1(1);                                                                                //吸箱電機(jī)
                 motor2(0);                                                                                //左右電機(jī)
                                   motor3(1);                                                                                //前進(jìn)電機(jī)
                 motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
                 motor5(0);                                                                                //關(guān)箱電機(jī)
                                   motor6(0);                                                                                //切刀電機(jī)                                 
                         }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                           /*************過程四    第一次打箱**************/                                                                              
                         if(b==1)
                         {                          
                                 motor1(1);                                                                                //吸箱電機(jī)
         motor2(0);                                                                                //左右電機(jī)
                                 motor3(0);                                                                                //前進(jìn)電機(jī)
         motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
               motor5(1);                                                                                //關(guān)箱電機(jī)
                                 motor6(0);                                                                                //切刀電機(jī)                                
                         }
                           /**************過程十一 第二次打箱*************/                                                                              
                         if(b==2&&!P0_3)
                         {                          
                                 motor1(1);                                                                                //吸箱電機(jī)
               motor2(0);                                                                                //左右電機(jī)
                                 motor3(0);                                                                                //前進(jìn)電機(jī)
         motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
         motor5(1);                                                                                //關(guān)箱電機(jī)
                                 motor6(0);                                                                                //切刀電機(jī)                                
                         }
                         while(!P0_1|!P0_3);
                         b++;
                            if(b==3)
                         {
                                  b=0;
                         }
                }
        }

    if(!P0_2)                                                                                                                                    //限位開關(guān)三
        {                  
                  delay(10);
            if(!P0_2)                                                                                                                                    
        {
                /*******************過程三   吸箱完成返回***************/
                           if(c==0)
                           {
                                motor1(1);                                                                                //吸箱電機(jī)
        motor2(0);                                                                                //左右電機(jī)
                                motor3(2);                                                                                //前進(jìn)電機(jī)
              motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
        motor5(0);                                                                                //關(guān)箱電機(jī)
                                 motor6(0);                                                                                //切刀電機(jī)                                 
                           }                        
                        while(!P0_2);
                        c++;
                           if(c==1)
                        {
                          c=0;
                        }
                }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
}

        if(!P0_3)                                                                                                                                     //限位開關(guān)四
      {                  
                  delay(10);
                if(!P0_3)                                                                                                                                 
            {
                                /*****************過程五    第一次打箱動(dòng)作完成平臺(tái)向左
                                                  過程十二    第二次打箱動(dòng)作完成平臺(tái)向左 ***********/
                           if(d==0&&P0_1)
                           {
                                motor1(1);                                                                                //吸箱電機(jī)
        motor2(2);                                                                                //左右電機(jī)
                                motor3(0);                                                                                //前進(jìn)電機(jī)
              motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
              motor5(0);                                                                                //關(guān)箱電機(jī)
                                motor6(0);                                                                                //切刀電機(jī)                                 
                                   }
                        /*****************過程七   第一次切膠帶
                                  過程十四   第二次切膠帶**************/        
                        if(d==1&&!P0_0)
                           {
                                    motor1(1);                                                                                //吸箱電機(jī)
                 motor2(0);                                                                                //左右電機(jī)
                                   motor3(0);                                                                                //前進(jìn)電機(jī)
                 motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
                 motor5(0);                                                                                //關(guān)箱電機(jī)
                             motor6(1);                                                                                //切刀電機(jī)                                 
                     }
                        while(!P0_3|!P0_0|!P0_4);
                        d++;
                                                if(d==2)
                                        {
                                                d=0;
                                        }                                                
                        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
      }

          if(!P0_4)                                                                                                                                     //限位開關(guān)五
      {                  
                  delay(10);
                   if(!P0_4)                                                                                                                              
               {
                                        /*****************過程八   切膠帶動(dòng)作完成切膠帶動(dòng)作回收***********/
                                   if(e==0&&!P0_0&&!P0_3)
                                   {        
                                            motor1(1);                                                                                //吸箱電機(jī)
                         motor2(0);                                                                                //左右電機(jī)
                                           motor3(0);                                                                                //前進(jìn)電機(jī)
             motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
             motor5(0);                                                                                //關(guān)箱電機(jī)
                                           motor6(2);                                                                                //切刀電機(jī)                                 
                                   }
                        /*****************過程九    切膠帶過程完成   旋轉(zhuǎn)紙箱*************/
                                if(e==1&&!P0_0&&!P0_3)
                                   {
                                            motor1(1);                                                                                //吸箱電機(jī)
                         motor2(0);                                                                                //左右電機(jī)
                                           motor3(0);                                                                                //前進(jìn)電機(jī)
                   motor4(1);                                                                                //旋轉(zhuǎn)電機(jī)
             motor5(0);                                                                                //關(guān)箱電機(jī)
                                           motor6(0);                                                                                //切刀電機(jī)                                 
                                   }
                 /*************** 過程十五   切膠帶動(dòng)作完成切膠帶動(dòng)作回收**********/
                                if(e==2)
                                   {
                                            motor1(1);                                                                                //吸箱電機(jī)
                         motor2(0);                                                                                //左右電機(jī)
                                           motor3(0);                                                                                //前進(jìn)電機(jī)
             motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
             motor5(0);                                                                                //關(guān)箱電機(jī)
                                           motor6(2);                                                                                //切刀電機(jī)                                 
                                   }
                         /*****************過程十六    切  膠帶過程完成   全部完成 旋轉(zhuǎn)電機(jī)旋轉(zhuǎn)歸位*************/
                                if(e==3)
                                   {
                                                 motor1(0);                                                                                //吸箱電機(jī)
                                                 motor2(0);                                                                                //左右電機(jī)
                                                 motor3(0);                                                                                //前進(jìn)電機(jī)
                                                 motor4(2);                                                                                //旋轉(zhuǎn)電機(jī)
                                                 motor5(0);                                                                                //關(guān)箱電機(jī)
                                                 motor6(0);                                                                                //切刀電機(jī)                                 
                                   }
                                while(!P0_4|!P0_6);
                                e++;
                                   if(e==4)
                                {
                                  e=0;
                                }                                       
                        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

     }

         if(!P0_5)                                                                                                                             //限位開關(guān)六
         {                  
           delay(10);
           if(!P0_5)                                                                                                                           
         {
                                /**************過程十   
                                                 過程十七   全部過程結(jié)束 ************/
                           if(f==0)
                           {        
                        /**********等待投物**bn*************/                                

                     motor1(1);                                                                                //吸箱電機(jī)
                     motor2(0);                                                                                //左右電機(jī)
                                       motor3(0);                                                                                //前進(jìn)電機(jī)
               motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
               motor5(0);                                                                                //關(guān)箱電機(jī)
                                       motor6(0);                                                                                //切刀電機(jī)

                        /*************確認(rèn)投物準(zhǔn)備二次封箱************/                        
                        }
                        while(!P0_5|!P0_6);
                         f++;
                           if(f==1)
                        {
                          f=0;
                        }                                                                                          
            }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
        }
                 /*****************紙箱旋轉(zhuǎn)完成平臺(tái)第二次向右走*************/
        if(!P0_6)
        {
                delay(10);
            if(!P0_6)                                                                                                                          
        {
                         motor1(1);                                                                                //吸箱電機(jī)
                   motor2(1);                                                                                //左右電機(jī)
                         motor3(0);                                                                                //前進(jìn)電機(jī)
             motor4(0);                                                                                //旋轉(zhuǎn)電機(jī)
             motor5(0);                                                                                //關(guān)箱電機(jī)
                         motor6(0);                                                                                //切刀電機(jī)
            }
        }
  }
}


回復(fù)

使用道具 舉報(bào)

ID:1 發(fā)表于 2018-10-18 15:59 | 顯示全部樓層
補(bǔ)全原理圖或者詳細(xì)說明一下電路連接即可獲得100+黑幣
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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