/* MCU Power Supply 3/7/2010 BEER-WARE LICENSE Garrett Fogerlie wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return AtTiny2313 @ internal 4Mhz */ #include #define F_CPU 4000000UL #include uint8_t buttons; uint8_t outPin = 1; int main(void) { while(1) { buttons = (PIND & 0x0C);// This will store the value of PD2 and PD3 (PD2=0x04, and PD3=0x08, so together it's 0x0C) _delay_ms(35);// A small debounce delay if(buttons == 0x04)// If PD2 (-) was pressed { if(outPin == 0x01)// If its at its lowest value and DOWN is pressed, { outPin = 0x10;// roll over to the highest value (0x10) } else // If its not at its lowest value { outPin >>= 1;// lower it by a power of 2 (bit shift it to the right by 1) } PORTB = outPin;// Set the output port to our outPin value (this will make it output high on the pin that corresponds to outPin's value) } if(buttons == 0x08)// If PD3 (+) was pressed { if(outPin == 0x10)// If its at its highest value and UP is pressed, { outPin = 0x01;// roll over to the lowest value (0x01) } else // If its not at its highest value { outPin <<= 1;// lower it by a power of 2 (bit shift it to the right by 1) } PORTB = outPin;// Set the output port to our outPin value (this will make it output high on the pin that corresponds to outPin's value) } } return 0; }