📄 motor.c
字号:
//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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -