Difference between revisions of "U23 2007/Inhalt Abend 2"

From C4 Wiki
Jump to: navigation, search
(New page: Beispiele: * /Binär durchzählen * /Schieberegister === Testen & Kompilieren === testdatei: #include <avr/io.h> int main(void) { DDRA = 0xFF; PORTA = 0xAA; ...)
 
(No difference)

Revision as of 17:08, 21 May 2007

Beispiele:


Testen & Kompilieren

testdatei:

#include <avr/io.h> 

int main(void) {
 
    DDRA = 0xFF;
    PORTA = 0xAA;

    return 0;
}

kompilieren:

avr-gcc -mmcu=atmega644 -Wall -o direkt.elf direkt.c

hex-file erzeugen:

avr-objcopy -O ihex direkt.elf direkt.hex

bootloader starten (strom raus, launch-bootloader starten, strom rein, warten bis blinkt):

launch-bootloader /dev/ttyUSB0 115200 

installieren:

avrdude -p m644 -b 115200 -c avr109 -P /dev/ttyUSB0 -F -u -U flash:w:direkt.hex

flash script (usb):

#!/bin/bash

avr-gcc -mmcu=atmega644 -Wall -o tmp.elf $1
avr-objcopy -O ihex tmp.elf tmp.hex
launch-bootloader /dev/ttyUSB0 115200 
avrdude -p m644 -b 115200 -c avr109 -P /dev/ttyUSB0 -F -u -U flash:w:tmp.hex
echo X > /dev/ttyUSB0


Makefile: (NAME=sourcecode.c dateiname ohne .c)

SERIALPORT=/dev/ttyUSB0
NAME=nightrider

CC=avr-gcc
CFLAGS=-Wall -mmcu=atmega644

OBJCPY=avr-objcopy
OFLAGS=-O ihex

BOOTL=launch-bootloader
BFLAGS=$(SERIALPORT) 115200

AVRDUDE=avrdude
AFLAGS=-p m644 -b 115200 -c avr109 -P $(SERIALPORT) -F -u -U flash:w:

all: object hex

install: bootloader flash runit

object:
        $(CC)  $(CFLAGS) -o $(NAME).elf $(NAME).c

hex:
        $(OBJCPY) $(OFLAGS) $(NAME).elf $(NAME).hex

bootloader:
        $(BOOTL) $(BFLAGS)

flash:
        $(AVRDUDE) $(AFLAGS)$(NAME).hex

runit:
        echo X > $(SERIALPORT)

clean:
        rm -f *.hex *.elf


Frage

Was tut dieses Programm?

#include <avr/io.h>

int main(void) {

    while (1) {
        DDRA = 0xFF;
        PORTA ^= 0xAA;

        uint16_t i;
        uint16_t j;

        for (i = 0; i < 5; i++) {
            for (j = 0; j < 0xffff; j++) {
                /* nix */
            }
        }
    }

    return 0;
}