#include<avr/io.h>
#include<avr/interrupt.h>
#pragma interrupt_handler time:9
unsigned char num;
int main(void)
{
TCCR1B=0x00;
DDRA=0XFF;//A端口设置输出方式
SREG=0X80;//开启总中断
TIMSK=0X40;//允许T1中断溢出
TCNT1H=0XD8;
TCNT1L=0XEF;//设定定时时间为10ms
TCCR1B|=0X01;//设定无分频模式
MCUCR=0x00;
TCCR1A=0x00;
PORTA=0xfe;
while(1)
{
PORTA=~num;
}
}
void time(void)
{
static unsigned int i=0;
TCNT1H=0XD8;
TCNT1L=0XEF;
i++;
if(i>=10000)
{
num++;
i=0;
}
}
|