#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
void io_init(void);
void timer1_init(void);
unsigned int i1,i2,i3,i4;
void main()
{
io_init();
timer1_init();
EIMSK|=(1<<INT4); //使用外部中断0和1
EICRB = 0x03; //外部中断0和1为上升沿中断
sei();//开总中断
while(1)
{
// i=0;
}
}
void io_init(void)
{
DDRB=0Xff;
PORTB = 0xff;
DDRC = 0x00;
PORTC =0xff;
}
void timer1_init(void)
{
TCCR1A = 0xa8; //两路PWM相位频率可调,计数上限ICR1
//COM1A1 COM1A0 COM1B1 COM1B0 :1010
TCCR1B = 0x12; //预分频8
TCNT0=0;
ICR1=10000;
}
SIGNAL(SIG_INTERRUPT4)
{
cli();
while(PINC&0x01)
{i1++;}
OCR1A=(i1>>1)-300;
//OCR1A=(i1>>1)-300;
i1=0;
EIMSK=0x00;
EICRB = 0x30;
EIMSK=0x40;
sei();
}
SIGNAL(SIG_INTERRUPT5)
{
cli();
while(PINC&0x02)
{i2++;}
OCR1B=(i2>>1)-300;
i2=0;
EIMSK=0x00;
EICRB = 0x03;
EIMSK=0x10;
sei();
}
SIGNAL(SIG_INTERRUPT6)
{
cli();
while(PINC&0x04)
{i3++;}
OCR1C=(i3>>1)-300;
i3=0;
EIMSK=0x00;
EICRB = 0x0C;
EIMSK=0x20;
sei();
}