starting with AVR-GCC

  1. get the avr-gcc, avr-libs and avr-binutils
  2. create a new folder and add these files:
    • Makefile

      file: http://darcs.erazor-zone.de/avr/avr-gcc/avrledtest/Makefile

      MCU=atmega8
      CC=avr-gcc
      OBJCOPY=avr-objcopy
      # optimize for size:
      CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
      HEXLOAD=/usr/sbin/hexload
       
       
       
      all: avrledtest.hex
       
      avrledtest.hex : avrledtest.out 
      	$(OBJCOPY) -R .eeprom -O ihex avrledtest.out avrledtest.hex 
      avrledtest.out : avrledtest.o 
      	$(CC) $(CFLAGS) -o avrledtest.out -Wl,-Map,avrledtest.map avrledtest.o 
      avrledtest.o : avrledtest.c 
      	$(CC) $(CFLAGS) -Os -c avrledtest.c
       
      load: avrledtest.hex
      	$(HEXLOAD) -I avrledtest.hex
       
      clean:
      	rm -f *.o *.map *.out
       
    • avrledtest.c

      file: http://darcs.erazor-zone.de/avr/avr-gcc/avrledtest/avrledtest.c

      #include <avr/io.h>
       
      int main(void) {
      	unsigned char w;
      	unsigned int w2;
      	/* enable  PD5 as output */
      	DDRD=255;
      	while (1) {
      	    for(w=0;w<8;w++) {
      		PORTD=(1<<w);
      		/* led on, pin=0 */
      		for (w2=0;w2<50000;w2++);
      		for (w2=0;w2<50000;w2++);
       
      	    }
      	}
      }

Some short explanations at this point

Makefile

Well, the Makefile is used to compile your C-source just by typing 'make' as you can see, that will create the avrledtest.hex by executing:

  1. $(CC) $(CFLAGS) -Os -c avrledtest.c
  2. $(CC) $(CFLAGS) -o avrledtest.out -Wl,-Map,avrledtest.map avrledtest.o
  3. $(OBJCOPY) -R .eeprom -O ihex avrledtest.out avrledtest.hex

Additionally you can use 'make load' for uploading your firmware to the device.

  • $(CC) means our c- compiler, thats 'avr-gcc'.
  • $(MCU) thats the type of our microcontroler.
  • $(OBJCOPY) is used to convert the binary .o file to a ascii .hex file

avrledtest.c

Thats quite an easy AVR program, it uses the 2 loops, the while-loop is a simple infinete loop, the next one (for-loop) is used to shift the PORD and other 2 simply slow down the whole thing.

additional links

FAQ - Frequently Asked Questions

Copyright

 
wiki/projects/avr/avr-gcc.txt · Last modified: 2005/09/25 17:57 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki