Working with AVR-gcc, tiny13, STK500 on a Mac.

11 02 2008

First, install the packages (avr-gcc, binutils etc) for compiling/linking AVR programs in Mac OS X. I followed the instruction here: Programming an AVR microcontroller

Afterward, it is time to start my first led program in C.

I decide to use PB0 as led output, I connect the PB0 to Led0 on STk500 to start this testing program quickly.

#include <avr/io.h>
#define F_CPU 120000
#include <util/delay.h>
int main (void)

// set PB.0 as output pin

DDRB  = 0x01;

// set PB.0 to output high

PORTB = 0x01;

while (1) {

PORTB ^= 0x01;




Compile the program:

avr-gcc led_blink.c -o led.elf -mmcu=attiny13

Convert the elf format to hex format for flashing to the Tiny13:

avr-objcopy -O ihex led.elf led.rom

Prepare avrdude for Mac to flash program and find out the serial port device name on your Mac OS X. I am using usb2serial adapter, the serial port device is /dev/cu.usbserial and connected to stk500 RS232 CTRL port with the serial cable provided in stk500 kit.

avrdude -p t13 -c stk500v2 -P /dev/cu.usbserial -e -U flash:w:led.rom

If it programs successfully, you will see the LED0 is flashing on STk500 board.




3 responses

6 08 2008
Justin Winter

Thanks for posting this, it really helped me get up and running on the stk500

3 11 2008

I am using the Arduino as an AVR910 programmer but this page was the one google found for me to get my ATtiny13 reading code from the Arduino for the first time! Thanks for the demo code!

12 05 2009
Daniel Farley

Can you help me?? when i try to compile this code i get this error

/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h:90:3: warning: #warning “Compiler optimizations disabled; functions from won’t work as designed”

Thanks Daniel

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: