U23 2007/Inhalt Abend 2

From C4 Wiki
< U23 2007
Revision as of 13:43, 28 May 2007 by Pylon (talk | contribs) (*gnarf* typo)
Jump to: navigation, search

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

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;
}