#include #include #include #include "lcd.h" #include //für itoa und dtostrf void init(void) { //Timer für das Capturen aktivieren TCCR0 |= (1< zustand_alt) //steigende Flanke { low_time=TCNT0; TCNT0=0x00; zustand_alt=zustand; } if(zustand < zustand_alt) //fallende Flanke { high_time=TCNT0; TCNT0=0x00; zustand_alt=zustand; } i=i+1; high_total+=high_time; low_total+=low_time; if(i==4) { //Es wird der Mittlwert aus 4 Messungen gebildet high_total=high_total<<2; low_total=low_total<<2; //duty cycle Berechnung temp_dtc=(high_total*100)/(high_total+low_total); //Auf den Datenbus legen PORTB=(uint8_t)temp_dtc; //lcd ausgabe lcd_clrscr(); lcd_gotoxy(0,0); dtostrf(temp_dtc,8,2,buffer); lcd_puts(buffer); } } }