笔杆 2017-04-03 08:33 采纳率: 0%
浏览 911

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

 #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条回答 默认 最新

  • Tiger_Zhao 2017-04-03 08:41
    关注

    count 定义为 static 是不可修改的!怎么累加?

    评论

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统