Difference between revisions of "Compile a program for attiny13"

From ThorstensHome
Jump to: navigation, search
 
(8 intermediate revisions by one user not shown)
Line 1: Line 1:
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.
+
This is a description how to compile a program, beep.hex in this example, for the attiny13 processor. It is based on SUSE 12.2. Other distributions may work similar.
  
 +
= Set up the compile environment =
 
* install cross-avr-binutils
 
* install cross-avr-binutils
 
  yast -i cross-avr-binutils
 
  yast -i cross-avr-binutils
Line 13: Line 14:
 
  export PATH=/cross:$PATH
 
  export PATH=/cross:$PATH
 
* now you can build this: http://gitorious.org/avr-gcc-examples/avr-gcc-examples/trees/master/attiny13-blink
 
* now you can build this: http://gitorious.org/avr-gcc-examples/avr-gcc-examples/trees/master/attiny13-blink
 +
 +
= Understand the ATtiny13 =
 +
The ATtiny13 is a processor. Its pins have the following meaning:
 +
            ------
 +
        PB0-|ATtiny|-GND
 +
        PB1-|  13  |-PB4
 +
        PB2-|      |-PB3
 +
        VCC-|    o|-RES
 +
            ------
 +
There are 5 binary pins PB: PB0 till PB4. Then there is a pin to reset the processor, one voltage ground and one power supply (voltage common cathode VCC).
 +
 +
= beep =
 +
Here is my program for an ATtiny13 to beep with a frequency of 500Hz:
 +
 +
'''beep.c'''
 +
<pre>
 +
#include <avr/io.h>
 +
#define F_CPU 1000000UL
 +
#include <util/delay.h>
 +
 +
int main(void)
 +
{
 +
  DDRB = 8; // PB3 will be output, all others input
 +
  while (1)
 +
  {
 +
    PORTB = 8;
 +
    _delay_ms(1);
 +
    PORTB = 0;
 +
    _delay_ms(1);
 +
  }
 +
  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>
 +
 +
= Build =
 +
To compile and link your software beep.hex issue the statement
 +
make
 +
And you will get a file beep.hex
 +
 +
= Next step =
 +
Next step is to upload the file beep.hex to the ATtiny13, see [[attiny13]].
 +
 +
= See also =
 +
* http://www.rn-wissen.de/index.php/GNU_Assembler

Latest revision as of 08:39, 13 January 2013

This is a description how to compile a program, beep.hex in this example, for the attiny13 processor. It is based on SUSE 12.2. Other distributions may work similar.

Contents

Set up the compile environment

  • 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

Understand the ATtiny13

The ATtiny13 is a processor. Its pins have the following meaning:

            ------
       PB0-|ATtiny|-GND
       PB1-|  13  |-PB4
       PB2-|      |-PB3
       VCC-|     o|-RES
            ------

There are 5 binary pins PB: PB0 till PB4. Then there is a pin to reset the processor, one voltage ground and one power supply (voltage common cathode VCC).

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; // PB3 will be output, all others input
  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

Build

To compile and link your software beep.hex issue the statement

make

And you will get a file beep.hex

Next step

Next step is to upload the file beep.hex to the ATtiny13, see attiny13.

See also