EX13AVR ATmega8A TC2 fast PWM mode

//EX13AVR ATmega8A TC2 fast PWM mode //author :QI小米粥//data :2018.3.29#include#includevoid init_tc2(void)

{

DDRB |=BIT(3);//配置OC2引脚为输出

TCCR2 |=BIT(6); //normal 选择

TCCR2 |=BIT(3);

TCCR2 &=~BIT(4);//匹配清零

TCCR2 |=BIT(5);

TCCR2 |=0x07;//1024分频1024Hz

OCR2=0X40;//匹配值为周期的四分之一

ASSR &=~BIT(3);//不选异步时钟

TIMSK |=BIT(7);//匹配中断使能

TIMSK |=BIT(6);//溢出中断使能

SREG |=BIT(7);//开全局中断

}

#pragma interrupt_handler tc2_match:4

void tc2_match(void)

{

}

#pragma interrupt_handler tc2_ov:5

void tc2_ov(void)

{

}

void main(void)

{

init_tc2();

}

你可能感兴趣的:(EX13AVR ATmega8A TC2 fast PWM mode)