TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) ;
//TCNT1 = 0; // clear the timer count
// Set the value of TOP, which generate 50HZ frequency (20ms per cycle)
ICR1 = 40000 - 1;
// Map the angle value to counter, then set counter, begin count
unsigned int counter = map(angle, 0, 180, MIN_PULSE_WIDTH/0.0005, MAX_PULSE_WIDTH/0.0005);
OCR1A = counter;
最最最核心的代码就是这些啦
我可以把328P 手册 TIME1的设置啥的研究了个遍,才写出这段代码的