qq_16690637
笔杆
2017-04-03 08:33

C51单片机模拟电机调速,为什么无法实现调速

  • c
  • 单片机
 #include<reg52.h>
 sbit motor_1=P2^4;
 sbit motor_2=P2^5;
 sbit motor_3=P2^6;
 sbit motor_4=P2^7; 
 static int count;
static int dc1,dc2,dc3,dc4;
 void timer0_init()   
 {

    TMOD=0x11;     //1ms    
    TH0=0Xfc;     
    TL0=0X66;             
    TR0=1;
 }
 void int_Init()

 {
    ET0=1;      
    EA=1;
 }  
  void time0_int() interrupt 1
  {
    count++;
    if(1000==count)
    {
        count=0;
    }
  }

   void pwm_motor_1(unsigned int dc1)   
 {
    if(count<(dc1*100))
        motor_1=1;
      else
        motor_1=0;      
 }
 void pwm_motor_2(unsigned int dc2)  
 {
    if(count<(dc2*100)) 
        motor_2=1;
      else
        motor_2=0;  
 }
 void pwm_motor_3(unsigned int dc3)  
 {
    if(count<(dc3*100)) 
        motor_3=1;
      else
        motor_3=0;  
 }
 void pwm_motor_4(unsigned int dc4)  
 {
    if(count<(dc4*100)) 
        motor_4=1;
      else
        motor_4=0;  
 }
 void main()
 {

    timer0_init();
    int_Init();

    while(1)
    {
        dc1=1;
        dc2=0;
        dc3=10;
        dc4=0;
        pwm_motor_1(dc1);
        pwm_motor_2(dc2);
        pwm_motor_3(dc3);
        pwm_motor_4(dc4);
    }

 }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答