//EX12AVR ATmega8A TC2 normal mode//author:QI小米粥//data:2018.3.28#include#includevoid init_tc2(void)
{
DDRB |=BIT(3);//OCR2引脚设置为输出
DDRB |=BIT(0);
TCCR2 &=~BIT(6); //normal 选择
TCCR2 &=~BIT(3);
TCCR2 &=~BIT(5);//匹配反转
TCCR2 |=BIT(4);
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)
{
//PORTB ^=BIT(3);
}
#pragma interrupt_handler tc2_ov:5
void tc2_ov(void)
{
PORTB ^=BIT(0);
}
void main(void)
{
init_tc2();
}
网友评论