笔杆 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 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?