以下是程序代码,采用winavr编写.
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#define uchar unsigned char
void port_init(void)
{
PORTA =0x00;
DDRA =0xFF;
PORTB=0xFF;
DDRB=0x00;
PORTC=0xFF;
DDRC=0x00;
PORTD=0xFF;
DDRD=0x00;
}
void timer1_init(void)
{
TCCR1B=0X00;
TCNT1H = 0xC2;
TCNT1L = 0xF7;//初始值
TCCR1A = 0x00;
TCCR1B = 0x04;
TIMSK=0X04;
}
SIGNAL(SIG_OVERFLOW1)
{
TCNT1H = 0xC2;
TCNT1L = 0xF7;
PORTA=(~PORTA)&0X01;
}
int main(void)
{
cli();
port_init();
timer1_init();
sei();
while(1);
}