/* * If_elseif_C_Test.c * * SW1 und SW2 statische Signale * SW3 1Hz pulsierend * * Created: 30.08.2015 18:15:11 * Author: Joerg */ #define F_CPU 1000000 #include #include int main(void) { // output Pin DDRB |= (1 << PB0)|(1 << PB1)|(1<< PB2); // LEDs an PB0-PB2 // input Pin DDRD &= ~(1 << PD0)|(1 << PD1)|(1 << PD2); // SW an PD0-PD2 PORTD |= (1 << PD0)|(1 << PD1)|(1 << PD2); // Pull up PD0-PD2 on int x = 0; int z = 0; while(1) { x = PIND; //SW einlesen if (( x & 0x07 ) == 6) { // ist sw1 close? PORTB = 0b11111110 ; // LED1 an } else if (( x & 0x07 ) == 4) { // ist SW1 und SW2 close? PORTB = 0b11111100 ; // LED1 und LED2 aon } else if (( x & 0x07 ) == 2) { // ist SW1 und SW3 close? PORTB = 0b11111010 ; // LED1 und LED3 an z = 0 ; // Zähler zurück setzen for (; z<=4; z++) { //_delay_ms(200); // warte 200ms if (( x & 0x07 ) == 3) { // ist SW3 noch an? z = 0; // ja, Zähler zurück setzen } } } else { PORTB = 255; } } }