Lösung: 4 Sekunden Schätzer
Quellcode
#define F_CPU 16000000UL
#include <avr/io.h>
#include <stdint.h>
int main(void)
{
DDRD |= 0b11111111;
DDRB &= ~0b00000100;
PORTB |= 0b00000100;
TCCR1B = 0b00000101;
uint16_t zaehler = 0;
uint8_t LEDout;
while (1)
{
while (PINB & 0b00000100)
{
}
PORTD = 0b00000000;
LEDout = 0b11111111;
for (uint8_t i = 0; i<=8; i++)
{
PORTD=LEDout;
TCNT1 = 0;
while (TCNT1 < 15625)
{
}
LEDout = LEDout/2;
}
TCNT1 = 0;
while (PINB & 0b00000100)
{
}
zaehler = TCNT1;
if (zaehler < 43750)
{
PORTD = 0b00000011;
}
else
{
if (zaehler > 50000)
{
PORTD = 0b11000000;
}
else
{
PORTD = 0b00011000;
}
}
while (TCNT1 < 65000)
{
}
}
}
Hinweise und Tipps
Warten auf einen Tastendruck
|