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. They assume an LED on pin 5 and a button on pin 8 of an attiny44 microcontroller. You can change the programs to reflect your configuration.

The makefiles are written assuming that you have a working usb-tiny programmer - add other programmers as needed by referring to other makefiles. Using the AVR crosspack IDE, commands to program are:

They also assume that a 20 MHz external clock is on the board, as in the "hello.ftdi.44.echo" board. These button-push programs run fine with the microcontroller set to use the internal clock sources, but for programs where timing matters, you will need to set fuses to use the external clock source. Using the makesfiles here, for example, the command would be: "make -f button_44_a.make program-usbtiny-fuses".

References for the basics of AVR programming with c:

 

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: