void tm1_init(void)
{
//TCCR1A COM1A1 COM1A0 COM1B1 COM1B0 FOC1A FOC1B WGM11 WGM10
//TCCR1B ICNC1 ICES1 – WGM13 WGM12 CS12 CS11 CS10
#if TM1_OVERFLOW
TCNT1 = 0xff00;
TIMSK = (0x01 << TOIE1);
TCCR1B = 0x05;
#elif TM1_CTC
TCNT1 = 0;
// TCCR1A = 0x01 << 6; //A比较
TCCR1A = 0; //
OCR1A = 0x00ff;
OCR1B = 0x01ff;
TCCR1B = 0x04 | (0x01 << 3);
TIMSK = (0x01 << OCIE1A);
#elif TM1_FPWM //--Fast PWM, 8-bit
//周期计算 0x100*1024/8e6 = 32.768ms
//频率计算 8e6/(0x100*1) = 31250.0hz
TCNT1 = 0;
OCR1A = dr1;
OCR1B = dr2;
TCCR1A = (0x00 << WGM11) | (0x01 << WGM10) | (0x2 << COM1A0) | (0x2 << COM1B0);
TCCR1B = (0x00 << WGM13) | (0x01 << WGM12) |\
0x01;
DDRE |= (0x01 << PE2);
#endif
}
|