Download: Teeuhr.zip
#include <avr/io.h>
#define F_CPU 1000000UL
#include <avr/interrupt.h>
#include <util/delay.h>
int overflow=0;
int kraut=0;
int ostfr=0;
int blink(char x) {
while(1){
for (int i=0;i<50;i++){ //Ton 1 erzeugen
PORTB |= (1<<PB0); //Summer an
PORTB |= (1<<x); //LED x an
_delay_us(500);
PORTB &= ~(1<<PB0); //Summer aus
PORTB &= ~(1<<x); //Led x aus
_delay_us(500);
}
_delay_ms(50);
for (int i=0;i<50;i++){ //Ton 2 erzeugen
PORTB |= (1<<PB0); //Summer an
PORTB |= (1<<x); //LED x an
_delay_us(600);
PORTB &= ~(1<<PB0); //Summer aus
PORTB &= ~(1<<x); //Led x aus
_delay_us(600);
}
_delay_ms(2000);
}
return 0;
}
int main(void)
{
DDRB |= (1<<PB4)|(1<<PB3)|(1<<PB0);//3 Ausgänge
PORTB = 0x00; //alles aus
PORTB |= (1<<PB1)|(1<<PB2); //2 Taster, Pull-Up an
_delay_ms(10);
sei(); //Timerinizialisierung
TCCR0B = (1<<CS02);
TCNT0 = 0x00;
while (1) {
if (bit_is_clear(PINB,1)){ //Taste Kräuter?
TIMSK0 =(1<<TOIE0); //Timer Start
PORTB |= (1<<PB4); //LED an
kraut=1;
while (1) {
}
}
if (bit_is_clear(PINB,2)){ //Taste Ostfriese?
TIMSK0 =(1<<TOIE0); //Timer Start
PORTB |= (1<<PB3); //LED an
ostfr=1;
while (1) {
}
}
}
return 0;
}
ISR(TIM0_OVF_vect){ //Timerüberlauf auswerten
char a = PB3;
char b = PB4;
overflow++; //Überläufe mitzählen
if ((overflow==3060)&&(ostfr==1)){ //3 Minuten ziehen
PORTB &= ~(1<<PB3); //LED aus
blink(a); //Fertigsignal
}
if ((overflow==6120)&&(kraut==1)){ //6 Minuten ziehen
PORTB &= ~(1<<PB4); //LED aus
blink(b); //Fertigsignal
}
}