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

標(biāo)題: 51單片機(jī)控制步進(jìn)電機(jī)正反轉(zhuǎn) [打印本頁(yè)]

作者: 384448010    時(shí)間: 2019-11-23 23:00
標(biāo)題: 51單片機(jī)控制步進(jìn)電機(jī)正反轉(zhuǎn)
#include "reg51.h"
//Motor
unsigned char code Motor_l[]={0xfe,0xfc,0xfd,0xf9,0xfb,0xf3,0xf7,0xf6};//四相八拍,逆時(shí)針
unsigned char code Motor_r[]={0xf7,0xf3,0xfb,0xf9,0xfd,0xfc,0xfe,0xf6};//四相八拍,順時(shí)針
unsigned char MotorStep=0;
unsigned int  Speed=8,CT=0;
sbit SB1=P2^0;
sbit SB2=P2^1;
sbit SB3=P2^2;
bit a=1,b=1;
unsigned char code discode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x76,0x38,0x73,0x31,0x3e,0x6e,0x40,0x80};
/* 共陰碼:0:0; 1:1; 2:2; 3:3; 4:4; 5:5; 6:6; 7:7; 8:8; 9:9;
        10:A; 11:B; 12:C; 13:d;  14:E; 15:F; 16:H; 17:L; 18:P; 19:R;
        20:U; 21:Y; 22:-;23:.;*/
//#define speed 8   // 調(diào)整速度 數(shù)值不要設(shè)的太低 低了會(huì)引起震動(dòng)。
void delay(unsigned int i)
        {
                unsigned int k;
                for(k=0;k<i;k++);
        }
void system_Ini()
{
    TMOD= 0x01;
                TH0 =(65536-100)/256;  
                TL0 =(65536-100)%256;
                IE  = 0x8A;       
    TR0 = 1;
}
void main()
{ system_Ini();
   P1=0xff;//         初始化馬達(dá)
    while(1)
        {
                 if(a==0)P0=~discode[Speed-7];
                else P0=0xff;
                 if(SB1==0)
                {
                delay(1000);
                if(SB1==0)
                {
                        while(!SB1);
                        a=!a;
                }}
                if(SB2==0)
                {
                delay(1000);
                if(SB2==0)
                {
                        while(!SB2);
                        b=!b;
                }
        }
                        if(SB3==0)
                {
                delay(1000);
                if(SB3==0)
                {
                        while(!SB3);
                        Speed++;
                        if(Speed==14)Speed=8;
                }
        }
                if(a==0&&b==1)
                P1=Motor_l[MotorStep];
         else if(a==0&&b==0)
                 P1=Motor_r[MotorStep];
         else P1=0xff;
         }}
  void int_tim0(void) interrupt 1
{
   TH0 =(65536-100)/256;  
        TL0 =(65536-100)%256;
        if( CT++==Speed)
          {MotorStep++;
                if(MotorStep==8)MotorStep=0;       
           CT=0;
         
                }
}       
               






歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1