The program is pretty simple. It blinks an LED attached to PB0.
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main( void )
{
DDRB |= 1; // Change to 16 for ATtiny13
while( 1 )
{
PORTB &= ~1; // Change to 16 for ATtiny13
_delay_ms( 200 );
_delay_ms( 200 );
_delay_ms( 200 );
_delay_ms( 200 );
PORTB |= 1; // Change to 16 for ATtiny13
_delay_ms( 200 );
_delay_ms( 200 );
_delay_ms( 200 );
_delay_ms( 200 );
}
return 0;
}
The Makefile is also simple. This one is for Linux. Change the "-mmcu=atmega32" to whatever microcontroller you are using. Also change the "-p m32" on the avrdude command tail to match your microcontroller.
CC=/usr/bin/avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega32
OBJ2HEX=/usr/bin/avr-objcopy
LOADER=/usr/bin/avrdude -c arduino -P /dev/ttyUSB0 -p m32 -b 19200 -U flash:w:
TARGET=blink
all : $(TARGET).hex
$(LOADER)$(TARGET).hex
%.obj : %.o
$(CC) $(CFLAGS) $< -o $@
%.hex : %.obj
$(OBJ2HEX) -R .eeprom -O ihex $< $@
clean :
rm -f *.hex *.obj *.o
The makefile is a little different for WinAVR. This makefile is courtesy of Ken.
CC=avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=attiny13
OBJ2HEX=avr-objcopy
LOADER=avrdude -c usbtiny -P USB -p t13 -b 19200 -U flash:w:
TARGET=Blinky
all: $(TARGET).hex
$(LOADER)$(TARGET).hex
$(TARGET).o: $(TARGET).c
$(CC) $(CFLAGS) $< -o $@
$(TARGET).hex: $(TARGET).o
$(OBJ2HEX) -R .eeprom -O ihex $< $@
clean:
rm -f *.hex *.obj *.o