All pastes #2072718 Raw Edit

Unnamed

public c v1 · immutable
#2072718 ·published 2011-05-31 10:57 UTC
rendered paste body
  #include <inttypes.h>#include <avr/io.h>enum flagi	{		W_PRAWO = 0x01,		W_LEWO = 0x02,		DZIALAJ = 0x04		};int main(void){    uint8_t   led = 0x00;     uint8_t   flags = 0x00;        // 								   //     DDRB  = 0xff;                  // use all pins on PortB for output     DDRD  = 0x00;                  // use all pins on port D for input        PORTD = 0xff;                  // activate internal pull-up    PORTB = 0x00;                  // set output high -> turn all LEDs off        while (1) {                     // loop forever            		if ( flags == 0 && PIND & (W_PRAWO | W_LEWO) )		{			flags |= PIND;		}		else if ( flags & (W_PRAWO | W_LEWO) 					&& PIND == 0x00 					&& !(flags & DZIALAJ))		{			flags |= DZIALAJ;			if( flags & W_LEWO)				led = 0x01;			else				led = 0x80;			PORTB = led;		}		else if ( flags & DZIALAJ )		{			if ( flags & W_LEWO 				&& !(led & 0x80))				led <<= 1;			else if(flags & W_PRAWO					&& !(led & 0x01))					led >>= 1;						PORTB = led;           // Set corresponding LED if switch pressed		}    }}