下面是一个atmega128定时器0的程序,通过定时器来控制led闪烁。可下载到板子上没有任何反应,到底是哪里出了问题,求高手赐教!!!
#include <iom128v.h>
#include <macros.h>
unsigned char k;
void port_init (void)//初始化对573的控制,使输出信号可以直接控制led的亮暗
{
DDRA=0XFF;
PORTA=0XFF;
DDRE|=1<<2;
PORTE=1<<2;
}
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0x3c; //setup 0.2s
//TCNT0=0X00;
OCR0 = 0x00;
TCCR0 = 0x05; //1024分频
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
TCNT0 = 0x3c;
//TCNT0=0x00;
k=k+1;
if(k>100)
{
k=0;
PORTA ^= 0xFF;
}
}
void main (void)
{
CLI(); //disable all interrupts
port_init();
timer0_init();
MCUCR = 0x00;
TIMSK = 0x01; //T0溢出使能
SEI(); //enable interrupts
while(1);
} |