Difference between revisions of "Compile a program for attiny13"

From ThorstensHome
Jump to: navigation, search
Line 16: Line 16:
 
= beep =
 
= beep =
 
Here is my program for an ATtiny13 to beep with a frequency of 500Hz:
 
Here is my program for an ATtiny13 to beep with a frequency of 500Hz:
 +
 +
'''beep.c'''
 
<pre>
 
<pre>
 
#include <avr/io.h>
 
#include <avr/io.h>
Line 33: Line 35:
 
   return 0;
 
   return 0;
 
}
 
}
 +
</pre>
 +
 +
'''Makefile'''
 +
<pre>
 +
MCU=attiny13
 +
CC=avr-gcc
 +
OBJCOPY=avr-objcopy
 +
CFLAGS=-g -mmcu=$(MCU) -Os
 +
 +
all: beep.hex
 +
 +
beep.hex : beep.o
 +
$(OBJCOPY) -R .eeprom -O ihex beep.o beep.hex
 +
beep.o : beep.c
 +
$(CC) $(CFLAGS) -Os -o beep.o beep.c
 +
clean:
 +
rm -f *.hex *.o
 
</pre>
 
</pre>

Revision as of 18:51, 12 January 2013

This is a description how to compile a program for the attiny13 processor. It is based on SUSE 12.2. Other distributions may work similar.

  • install cross-avr-binutils
yast -i cross-avr-binutils
mkdir /cross
  • link the files to the respective places
ln -s /usr/bin/avr-as /cross/as
ln -s /usr/bin/avr-ld /cross/ld
  • tell the system to use these
export PATH=/cross:$PATH

beep

Here is my program for an ATtiny13 to beep with a frequency of 500Hz:

beep.c

#include <avr/io.h>
#define F_CPU 1000000UL
#include <util/delay.h>

int main(void)
{
  DDRB = 8;
  while (1)
  {
    PORTB = 8;
    _delay_ms(1);
    PORTB = 0;
    _delay_ms(1);
  }
  return 0;
}

Makefile

MCU=attiny13
CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS=-g -mmcu=$(MCU) -Os

all: beep.hex

beep.hex : beep.o 
	$(OBJCOPY) -R .eeprom -O ihex beep.o beep.hex 
beep.o : beep.c 
	$(CC) $(CFLAGS) -Os -o beep.o beep.c
clean:
	rm -f *.hex *.o