//--------------------------------------------------------------------------------------- // Programm Nr.: 06 // Content : LED blinking with big loop and change timing with keys // Author : digital AG Halle // Date : 14.07.2008 // System : ATmega8-16PU - Dai Hoc Hue Development Board //--------------------------------------------------------------------------------------- //--included Files----------------------------------------------------------------------- #include //--declarations------------------------------------------------------------------------- #ifndef F_CPU #define F_CPU 8000000 //CPU frequency = 8 MHz #endif uint8_t KEYS; //8-Bit integer variable (0...255) for actual key-value uint8_t KEYS_OLD; //variable for last key-value uint8_t TIME; //Variable for controlling the blinking frequency uint16_t loop_count1; //counter 1 for delay loop uint8_t A; //calculation variable //--MAIN PROGRAMM------------------------------------------------------------------------ int main(void) { //--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) TIME=20; //init-value for time (25 ms *20 = 0.5 sec) //--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; //read input byte from PORT C into variable KEYS if (KEYS_OLD!=KEYS) //check of a change at PORT C inputs //it also works against chatter at the keys { if ((KEYS&226)==!(0x02)) //if key 1 was pressed { TIME=TIME+5; //increase TIME with 5 } if ((KEYS&228)==!(0x04)) //if key 2 was pressed { TIME=TIME-5; //decrease TIME with 5 } } PORTD ^= (1<