rendered paste body#define F_CPU 1000000UL#include <avr/signal.h>#include <avr/interrupt.h>#include <util/delay.h>int x=0;uint8_t led[4];//define times for start and end of signaluint16_t rising, falling;//this function sleeps s seconds (if F_CPU is set to frequency of processor)void sleep_sec(uint8_t s){ uint8_t i; while (s--) for (i = 0; i < 100; i++) _delay_ms(10);}//this function sleeps s micro seconds (if F_CPU is set to frequency of processor)void sleep_usec(uint8_t s){ //uint8_t i; while (s--) _delay_us(1);}//Timer1 capture interrupt service subroutineISR(TIMER1_CAPT_vect){ /*This subroutine checks was it start of pulse (rising edge) or was it end (fallingedge)and performs required operations*/ if ((bit_is_set(PIND, 6))){ //if high level //save start time rising=ICR1; led[0]=ICR1H; led[1]=ICR1L; //set to trigger on falling edge TCCR1B = _BV(ICNC1)|_BV(CS10); //DDRB = 0b11000000; //PORTB = 0b10000000;}else{ //save falling time falling=ICR1; led[2]=ICR1H; led[3]=ICR1L; //rising edge triggers next TCCR1B = _BV(ICNC1)|_BV(CS10)|_BV(ICES1); DDRB = 0b00010000; PORTB = 0b00000000; sleep_sec(1); int leda = 0b00000000; //int led2 = 0b00000000; leda = falling - rising; leda /=8; leda /=58; DDRB = 0xFF; PORTB = (uint8_t)led;//0b01010101; sleep_sec(1); PORTB = led[0]; sleep_sec(7); PORTB = led[1]; sleep_sec(7); PORTB = led[2]; sleep_sec(7); PORTB = led[3]; sleep_sec(7); } }ISR(INT0_vect){ DDRB = 0b00001111; PORTB = 0b00001010; //sleep_sec(3); //PORTB = 0b01010100; sleep_sec(1); //DDRB = 0b0000011; PORTB =0b00000000; //sleep_usec(13); //PORTB = 0b00101000;}void pulse(){ DDRD = 0b00000001; PORTD= 0b00000001; asm volatile( "ldi r16, 31\n\t" "loop: dec r16\n\t" "brne loop\n\t" ); PORTD= 0b00000000;}int main(){ //MCUCR = _BV(ISC00);//|_BV(ISC01);//int0 interrupt //GICR = _BV(INT0); //int0 interrupt TIMSK = _BV(TICIE1);//|_BV(TOIE1); TCCR1B = _BV(CS10)|_BV(ICES1);//|_BV(ICNC1) sei(); pulse(); while(1); }