Three simple button-LED c-programs illustrating the use of macros.

Here are three simple programs in c for the AVR tiny44 that all do the same thing: turn on an LED when a button is pressed. Refer to the datasheet for the functions of register DDRx, PORTx, and PINx, where x=A,B. Refer to c programming introductions for the use of operators that work on bits.

tiny44 pinout

There is an LED on pin PB2, physically pin 5 of the Tiny44.

There is a button on PA5.

The three programs:

1. Here is a simple program and makefile to light an LED in response to a button.

Comments:

 

2. Here is a clearer way to do it, using macros.

Comments:

 

3. Here's another way to use macros to do the same thing.

Comments: