//--------------------------------------------------------------------------------------- // Programm Nr.: 04 // Content : toggle all LEDs at PORTD on pressing keys 1 to 4 // Author : digital AG Halle // Date : 14.07.2008 // System : ATmega8-16PU - Dai Hoc Hue Development Board //--------------------------------------------------------------------------------------- //--included Files----------------------------------------------------------------------- #include //--declarations------------------------------------------------------------------------- uint8_t KEYS; //8-Bit integer variable (0...255) for actual key-value uint8_t KEYS_OLD; //variable for last key-value //--MAIN PROGRAMM------------------------------------------------------------------------ int main() { //--INITIALISATION--------------------------------------------------------------- DDRC=225; //PORT C: Bit 1,2,3,4 are inputs (Keys 1 - 4) PORTC=30; //PORT C: Bit 1,2,3,4 internal Pullup-Resistors active DDRD=255; //Port D: all Bits defined as output (for the status LEDs) //--PROGRAMM CODE BEFORE MAIN LOOP (USED JUST ONE TIME)-------------------------- PORTD=255; //Every LED at PORT D is off KEYS_OLD=PINC; //initialise KEYS_OLD (PINC should be 255 at that moment) //--MAIN LOOP-------------------------------------------------------------------- while(1) { KEYS=PINC; if (KEYS_OLD!=KEYS) { //bit will be changed without touching the other bits if ((KEYS&226)==!(0x02)) //Key 1 { PORTD ^= (1<