rendered paste body#include <inttypes.h>#include <avr/io.h>#include <avr/interrupt.h>#include "lcd.h"volatile uint8_t pcount;volatile uint16_t paverage;volatile uint16_t period;volatile uint8_t stat; ISR (INT0_vect){TCNT0 = 0; // CLEAR TIMERstat = 1; // rising edge detected int0 //}ISR (INT1_vect){if (stat == 1) { pcount++; // count +1 // paverage += TCNT0; // counter total + counter // stat = 0; // falling edge detetected int1 // if (pcount == 16) { period = paverage/16; // average // paverage = 0; // reset @ 16 readings// pcount = 0; } }} int main(void){uint8_t dtemp;DDRD = (1 << DDD7); // Set PD7 as output //PORTD = 0X00;DDRB = 0xFF; // Set Port B as output //PORTB = 0X00;TCCR2 = (1 << WGM20)|(1 << WGM21)|(1 << COM21)|(1 << CS20)|(1 << CS22); // fast pwm, clk/128 //OCR2 = 2; // 2/255 duty cycle //MCUCR = (1 << ISC00)|(1 << ISC01)|(0 << ISC10)|(1 << ISC11); // INT0 RISING EDGE + INT1 FALLING EDGE//GICR = (1 << INT0)|(1 << INT1); // INT0/INT1 ACTIVATED //TCCR0 = (1 << CS00)|(1 << CS01); // NORMAL COUNT & START & CLOCK/64 //lcd_init(); // LCD INIT //lcd_control(1,0,0); // LCD INIT //sei(); // ENABLE INTERRUPTS //while (1) { lcd_goto(0x40); print5 (pcount); // PRINT COUNTER VALUE TO LCD // dtemp = period * 0.436608; // distance measure (inches) // lcd_goto(0x00); print3 (period); // PERIOD VALUE TO LCD // lcd_goto(0x06); print3 (dtemp); // DISTANCE VALUE TO LCD // }}