//--------------------------------------------------------------------------------------- // Programm Nr.: 03 // Content : set (key 1,3) and reset (key 2,4) LED at PORTD on pressing keys // 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 if ((KEYS&226)==!(0x02)) //if key 1 was pressed (PORT C Bit 1) { PORTD=254; //set bit 0 at PORTD (LED1->on) //set the full byte } if ((KEYS&228)==!(0x04)) //if key 2 was pressed (PORT C Bit 2) { PORTD=255; //reset bit 0 at PORTD (LED1->off) //set the full byte } //mask = 1110 1000 = 232 dec. if ((KEYS&232)==!(0x08)) //if key 3 was pressed (PORT C Bit 3) { PORTD &= ~(1<on) //set single bit to low-level } //mask = 1111 0000 = 240 dec. if ((KEYS&240)==!(0x10)) //if key 4 was pressed (PORT C Bit 4) { PORTD |= (1<off) //reset single bit to high-level } } } //--PROGRAMM END------------------------------------------------------------------------ // **** examples to change single bits **** // // PORTD &= ~(1<