motor.c
来自「智能遥控车代码」· C语言 代码 · 共 32 行
C
32 行
//ADCADC.c : source file for the SmartCar Motor
#include "Motor.h"
#include <io.h>
#include <wdt.h>
#define Max_Speed 100
void PWM_OC1_set(unsigned int Left_Run_Direct,unsigned int Left_Speed,unsigned int Right_Run_Direct,unsigned int Right_Speed)
{
cbi(TCCR1B,0);
if (Left_Speed>Max_Speed){Left_Speed=Max_Speed;}
if (Right_Speed>Max_Speed){Right_Speed=Max_Speed;}
if (Left_Run_Direct!=2)
{ if (Left_Speed>0)
{ if(Left_Run_Direct){cbi(PORTB,3); sbi(PORTB,1);OCR1A=Max_Speed-Left_Speed;}
else{ sbi(PORTB,3); cbi(PORTB,1); OCR1A=Left_Speed; }
}
else
{ OCR1A = 101; cbi(PORTB,3); cbi(PORTB,1);
}//End_if (Left_Speed>0)
}
if (Right_Run_Direct!=2)
{ if (Right_Speed>0)
{ if(Right_Run_Direct){cbi(PORTB,4); sbi(PORTB,2);OCR1B=Max_Speed-Right_Speed;}
else{ sbi(PORTB,4); cbi(PORTB,2); OCR1B=Right_Speed; }
}
else
{ OCR1B = 101; cbi(PORTB,4); cbi(PORTB,2);
}//End_if (Right_Speed>0)
}
sbi(TCCR1B,0); TCNT1=1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?