//--------------------------------------------------------------------------------------- // Programm Nr.: 02 // Content : Set LED at PORTD on pressing key // Author : digital AG Halle // Date : 13.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 //--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 //--MAIN LOOP-------------------------------------------------------------------- while(1) { KEYS=PINC; //read input byte from PORT C into variable KEYS //mask = 1110 0010 = 226 dec. if ((KEYS&226)==!(02)) //if key 1 was pressed (PORT C Bit 1) { PORTD=254; //set bit 0 at PORTD (LED1->on) //(setting a full byte) } //mask = 1110 0100 = 228 dec. if ((KEYS&228)==!(04)) //if key 2 was pressed (PORT C Bit 2) { PORTD |= (1<on) //(setting only 1 bit - no touching the other bits) } } } //--PROGRAMM END------------------------------------------------------------------------