/* * UART_InputCapture_Mittelwert_neu.c * * Created: 17.07.2016 08:33:32 * Author : BC */ #define F_CPU 8000000UL #include #include #include #include #include #include "lcd-routines.h" #include "uart.h" #define UART_BAUD_RATE 9600L #define TRUE 1 #define FALSE 0 volatile unsigned char Overflow = 0; volatile unsigned int StartTime= 0; volatile unsigned int EndTime = 0; volatile float Erg = 0; volatile float Summe = 0; uint8_t AnzahlMessung = 50; //hier die Anzahl der Messung ändern static unsigned char UpdateDisplay = FALSE; static unsigned char ErsteFlanke = TRUE; ISR ( TIMER1_CAPT_vect) {//start ICP-Interrupt if (UpdateDisplay) {//start if-UpdateDiplay return; //zurück zu main }//end if-UpdateDisplay else {//start else UpdateDisplay for (uint8_t iMessung = 0; iMessung < AnzahlMessung; iMessung++) {//start for iMessung if (ErsteFlanke == TRUE) {//start if-ErsteFlanke StartTime = ICR1; //Timerwert in StartTime sichern Overflow = 0; ErsteFlanke = FALSE; //ErsteFlanke beendet }//end if-ErsteFlanke else {//start else-ErsteFlanke EndTime = ICR1; //Timerwert in EndTime sichern Erg = (Overflow * 65536) + EndTime - StartTime; //allg. Formel Erg = F_CPU/Erg; //f=1/t Summe += Erg; Erg = 0; ErsteFlanke = TRUE; }//end else-ErsteFlanke }//end for iMessung UpdateDisplay = TRUE; }//end else UpdateDisplay }//end ICP-Interrupt ISR( TIMER1_OVF_vect ) {//start OVF-Interrupt Overflow++; }//end OVF-Interrupt int main(void) {//start main DDRC = 0xFF; //PortC als Ausgang lcd_init(); //Initialisierung des LC-Displays uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU)); //Initialisierung der UART-Schnittstelle TCCR1B = (1<