while (1) // Endlosschleife { switch (State) // "switch" wertet die Variable "state" aus { case 0: // Fall 0 if((PINB & (1 << 7)) && Cnt < 254) // PB7 gedrückt und Zählerstand kleiner 254 { // PB7 UP wenn kleiner als 254 Cnt++; // inkrementiert +1 PORTC = ~Cnt; // Zählerstand wird ausgegeben State = 1; // Zustand 1 } else if((PINB & (1 << 6)) && Cnt > 0) // PB6 und Zählstand größer 0 { // PB6 DOWN wenn größer 0 Cnt--; // dekrementiert -1 PORTC = ~Cnt; State = 2; // Zustand 2 } else if((PINB & (1 << 6)) && (PINB & (1 << 7))) // PB6 und PB7 betätigt { State = 3; // Zustand 3 } break; case 1: // Fall 1 if(PINB == 0x00) // PB6==OFF,PB7==OFF { State = 0; // Zustand 1 } else if((PINB & (1 << 6))) // PB6==ON, PB7==OFF { State = 2; } else if((PINB & (1 << 6)) && (PINB & (1 << 7))) // PB6==ON, PB7==ON { State = 3; // Zustand 3 } break; case 2: // Fall 2 if(PINB == 0x00) // PB6==OFF, PB==OFF { State = 0; } if((PINB & (1 << 7))) // PB6==OFF, PB6==ON { State = 1; } else if((PINB & (1 << 6)) && (PINB & (1 << 7))) //PB6==ON, PB7==OFF { State = 3; } break; case 3: if(PINB == 0x00) //PB6=OFF, PB7==OFF { State = 0; } else if((PINB & (1 << 7))) { State = 1; } else if((PINB & (1 << 6))) { State = 2; } break; } } }