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

標(biāo)題: 求個(gè)大佬幫我調(diào)一下占空比,讓小車速度慢一點(diǎn),萬分感謝 [打印本頁]

作者: QYYY    時(shí)間: 2018-12-27 15:37
標(biāo)題: 求個(gè)大佬幫我調(diào)一下占空比,讓小車速度慢一點(diǎn),萬分感謝
#include<AT89X52.H>  //????52?????????
//????????С?????????????IO
sbit IN1 = P1^2; // ????1 ??????????
sbit IN2 =  P1^3; // ????1 ??????????
sbit IN3 = P1^6; // ????1 ??????????
sbit IN4 =  P1^7; // ????1 ??????????
sbit EN1 = P1^4;   // ???????
sbit EN2 =  P1^5; // ???????
sbit BUZZ=P2^3;
    #define Left_1_led        P3_3  // ??????      
#define Right_1_led       P3_2  //???????
    #define Left_moto_pwm   P1_5  //PWM????
#define Right_moto_pwm   P1_4   //PWM????     
//???????
   void delay(unsigned int k)
{   
     unsigned int x,y;
  for(x=0;x<k;x++)
    for(y=0;y<2000;y++);
}
//С?????????
void run(void)
{
     IN1=0;  //????
  IN2=1;
  IN3=1;  //????
  IN4=0;
  EN1=0.01;
  EN2=0.01;
}
//С?????????
void backrun(void)
{
     IN1=1;  //????
  IN2=0;
  IN3=0;  //????
  IN4=1;
  EN1=0.01;
  EN2=0.01;
}
//С?????????
void leftrun(void)
{
     IN1=0;  //????
  IN2=0;
  IN3=1;  //????
  IN4=0;
  EN1=0.01;
  EN2=0.01;
}
  //С?????????
void rightrun(void)
{
     IN1=0;  //????
  IN2=1;
  IN3=0;  //????
  IN4=0;      
  EN1=0.01;
  EN2=0.01;
}
   //С????????
void stopruo(void)
{
     IN1=0;  //????
  IN2=0;
  IN3=0;  //????
  IN4=0;
  EN1=0.01;
  EN2=0.01;
}
//??????
void main(void)
{  
while(1){
if(Left_1_led==1)
   if(Right_1_led==0)
   {backrun();}
    if(Right_1_led==0)
   {leftrun();delay(50);}
   else
    if(Left_1_led==0)
   {rightrun();delay(50);}
if(Left_1_led==1)
   if(Right_1_led==1)
   {run();}
} }




作者: 周超然    時(shí)間: 2018-12-27 16:49
你這個(gè)代碼,第一注釋用keil設(shè)置文本賦值,百度網(wǎng)上查
第二,if后面沒有{}么?
代碼寫出來自己和別人都需要看的,別隨手寫。習(xí)慣不好,以后坑自己也坑別人。
作者: 1092648746    時(shí)間: 2018-12-27 23:26
這個(gè)注釋,醉了,能改一下格式再發(fā)上來嗎?
這個(gè)程序是用IO口高低電平模擬PWM輸出吧,沒有用定時(shí)器的話只需控制高電平持續(xù)時(shí)間就可以控制占空比,也就可以調(diào)整小車速度了,樓主順著這個(gè)思路整理下
作者: HC6800-ES-V2.0    時(shí)間: 2018-12-28 10:19
我有一個(gè),你看看。
#include <reg51.h>

sbit ZLDJ20=P2^3;//IC的控制輸入腳5、7或10、12
sbit ZLDJ21=P2^2;
sbit EN2=P1^0;
sbit ZLDJ10=P2^1;
sbit ZLDJ11=P2^0;
sbit EN1=P1^1;

sbit Agoto=P2^5;//遙控器按鍵輸入I/O口
sbit Bback=P2^7;
sbit Cright=P2^6;
sbit Dleft=P2^4;

unsigned char pwm=0;
unsigned char push=6;
unsigned char pwm_T=20;

void Delay10ms(unsigned int c)
{
    unsigned char a,b;
    for(c;c>0;c--)
        for(b=38;b>0;b--)
            for(a=130;a>0;a--);
}

void pwmint(void)
{
        TMOD=0X01;
        TH0= 0XFC;
        TL0= 0X66;
        TR0= 1;
        ET0= 1;
        EA = 1;
}

void pwm_out(void)
{  
        if(pwm<=push)
        {
                EN1=1;
                EN2=1;
        }
        else
        {
                EN1=0;
                EN2=0;
        }
        if(pwm>=pwm_T)
        {
                pwm=0;
        }
}

void timer0()interrupt 1
{
     TH0=0XFC;
         TL0=0X66;
         pwm++;
         pwm_out();
}       

void TC(void)
{
        ZLDJ10=0;
        ZLDJ11=0;
        ZLDJ20=0;
        ZLDJ21=0;
}

void PU(void)
{
        ZLDJ20=1;
        ZLDJ21=0;
        ZLDJ10=1;
        ZLDJ11=0;
}

void PD(void)
{
        ZLDJ20=0;
        ZLDJ21=1;
        ZLDJ10=0;
        ZLDJ11=1;
}

void RR(void)
{
        ZLDJ20=0;
        ZLDJ21=0;
        ZLDJ10=1;
        ZLDJ11=0;
}

void LL(void)
{
        ZLDJ20=1;
        ZLDJ21=0;
        ZLDJ10=0;
        ZLDJ11=0;
}

void PWMD(void)
{
        push=push+2;
        if (push>20)
        {
                push=20;
        }
}

void PWMX(void)
{
        push=push-2;
        if (push<6)
        {
                push=6;
        }
}

void main(void)
{
        unsigned char n;
        pwmint();
        TC();
        Agoto=1;
        Bback=1;
        Cright=1;
        Dleft=1;
        while(1)
        {
                if (Agoto==1)
                {
                        n=0;
                        while(Agoto)
                        {
                                n++;
                                Delay10ms(1);
                                if (n>200)
                                {
                                        break;
                                }
                        }
                        if (n>30)
                        {
                                PWMD();
                        }
                        else
                        {
                                PU();
                        }
                }
                if (Bback==1)
                {
                        n=0;
                        while(Bback)
                        {
                                n++;
                                Delay10ms(1);
                                if (n>200)
                                {
                                        break;
                                }
                        }
                        if (n>30)
                        {
                                PWMX();
                        }
                        else
                        {
                                PD();
                        }
                }
                if (Cright==1)
                {
                        RR();
                }
                if (Dleft==1)
                {
                        n=0;
                        while(Dleft)
                        {
                                n++;
                                Delay10ms(1);
                                if (n>200)
                                {
                                        break;
                                }
                        }
                        if (n>30)
                        {
                                TC();
                        }
                        else
                        {
                                LL();
                        }
                }

        }
}
功能是:通過無線電遙控器,控制小車,其中可以加速、減速,就是你說的調(diào)速。因?yàn)檫b控器只有四鍵,所以我用此程序,擴(kuò)成了八個(gè)功能,即一鍵雙功能。







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