#include<iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uint num=0;
void delay(void)
{
uint a;
for(a=0;a<3000;a++);
}
void port_init(void)
{
PORTB = 0xff;
DDRB = 0xFF;
}
void timer2_init(void)
{
TCNT2 = 0x3d ;//初值设为6
TCCR2 = 0x05; //8分频
TIMSK|=BIT(6);//
SREG|=BIT(7);//
}
#pragma interrupt_handler timer2_isr:5//中断服务函数
void timer2_isr(void)
{
num++;
while(num==10)
{
TCNT2=0X3d;
num=0;
PORTB = 0x00;
delay();
PORTB=0XFF;
}
}
void main(void)
{
timer2_init();
port_init();
while(1);
}
定时 0.25s 每次溢出 25ms 溢出10次 大神看看对吗
|