
Zitat von
dark_flash01
gcc-avr hab ich jetzt gefunden. Wie benutze ich den?
Hi,
damit es benutzbar wird, brauchst Du noch die avr-libc. Sie enthält die Grundfunktionen,
die Du zum Programmieren brauchst.
Unter http://www.mikrocontroller.net/artic...R-GCC-Tutorial gibt es ein gutes Tutorial.
Für meine eigene Installation habe ich http://www.tldp.org/linuxfocus/Deuts...ticle352.shtml als
Vorgabe genommen.
hier übrigens mein erstes Testprogramm:
Code:
/*
einfaches Testprogramm, das eine LED an PB0
blinken laesst.
J. Uhrmann, 02.02.2006
*/
#include <avr/io.h>
#define F_CPU 1000000 /* Takt: 1MHz */
#include <util/delay.h>
void main(void)
{
/* Initialisierung */
/* Port PB0 als Ausgang definieren */
DDRB |= _BV(PB0);
/* in einer Endlosschleife blinken lassen */
while (1)
{
/* Ausgang auf LOW */
PORTB &= ~_BV(PB0);
_delay_ms(500);
/* Ausgang auf HIGH */
PORTB |= _BV(PB0);
_delay_ms(500);
}
}
und hier das Makefile, das die hex-Datei erstellt und mit make load auch gleich mit uisp auf den Controller lädt.
Code:
# Erstellungsregeln fuer das Beispielprogramm
.PHONY: load clean
# Zielgerät ist ein ATMega16
MCU=atmega16
# Programmiert wird er mit einem Parallelportkabel (bsd-Style, siehe Homepage von uisp)
PROGTYPE=bsd
CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues
blink.hex: blink.out
load: blink.hex
uisp -dprog=$(PROGTYPE) --upload if=$^
%.hex: %.out
$(OBJCOPY) -R .eeprom -O ihex $^ $@
%.out: %.o
$(CC) $(CFLAGS) -o $@ -Wl,-Map,$@.map $^
%.o: %.c
$(CC) $(CFLAGS) -Os -c $^
clean:
-rm *.o *.hex *.map
Grüße,
Hans
Lesezeichen