/* Demo of the simplest on/off button code for Tiny44 Button connected to PA5 (physical pin 8 on tiny44) Red LED connected to PB2 (physical pin 5 of tiny44) For details on the use of the registers PORtx, DDRx, and PINx (where x = A or B) see tutorials on AVR programming. This program was written by Robert Hart as a simple demonstration of programming AVR microcontrollers. */ // ------- Preamble -------- // #include int main(void) { // -------- Inits --------- // PORTA = 0b00100000; /* initialize pullup resistor on our input pin by setting bit 5 of register PORTA high. */ DDRB = 0b00000100; /* set up pin 2 of port B for output by setting bit 2 of register DDRB high.*/ // ------ Event loop ------ // while (1) { /* look for button press */ if ((PINA & 0b00100000) == 0 ) { /* test to see if bit 5 of PINA is low */ PORTB = 0b00000100; /* turn on LED on pin 3 of port B if bit is low (button is pressed) */ } else { /* otherwise */ PORTB = 0b00000000; /* leave output low. */ } } /* End event loop */ return (0); }