Bitte aktiviere Stylesheets (CSS, von Website angebotener Stil)!
Home » Projekte » Microprozessoren  

Microcontroller

Meine Erfahrungen mit Microcontrollern, dem Atmel Evaluation Board von Pollin und der Programmiersprache C. Diese Seite wird im Laufe der Zeit „optisch aufgewertet” und natürlich ergänzt.

Direkt nach unten:

Bestellliste bei Pollin

Modifikationen beim Pollin-Board

Installation der Software

Da ich mit Linux (kubuntu) arbeite, ist diese Liste nur für Linux zu verstehen!

Code:

sudo apt-get install ava avarice avr-libc avra avrdude avrdude-doc avrp avrprog binutils-avr gcc-avr gdb-avr simulavr uisp

Erster Test des Programms

Eingabe in die Kommandozeile einmal mit und einmal ohne Testtool als Parameter:
Übertragen des Pollin-Testprogramms (im ZIP-Archiv, siehe Download-Bereich bei Pollin) auf den AVR => Funktioniert problemlos!

Code:
$ avrdude -p m8 -c ponyser -P /dev/ttyS0 -v

avrdude: Version 5.5, compiled on Nov 10 2007 at 00:07:28
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "~/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port            : /dev/ttyS0
         Using Programmer      : ponyser
         AVR Part              : ATMEGA8
         Chip Erase delay      : 10000 us
         PAGEL                 : PD7
         BS2                   : PC2
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    20   128    0 no        512    0      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : SERBB
         Description     : design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9307
avrdude: safemode: lfuse reads as E1
avrdude: safemode: hfuse reads as D9

avrdude: safemode: lfuse reads as E1
avrdude: safemode: hfuse reads as D9
avrdude: safemode: Fuses OK

avrdude done.  Thank you.



$ avrdude -p m8 -c ponyser -P /dev/ttyS0 -v -U flash:w:TESTTOOL.HEX

avrdude: Version 5.5, compiled on Nov 10 2007 at 00:07:28
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "~/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port            : /dev/ttyS0
         Using Programmer      : ponyser
         AVR Part              : ATMEGA8
         Chip Erase delay      : 10000 us
         PAGEL                 : PD7
         BS2                   : PC2
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    20   128    0 no        512    0      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : SERBB
         Description     : design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9307
avrdude: safemode: lfuse reads as E1
avrdude: safemode: hfuse reads as D9
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "TESTTOOL.HEX"
avrdude: input file TESTTOOL.HEX auto detected as Intel Hex
avrdude: writing flash (426 bytes):

Writing | ################################################## | 100% 0.20s

avrdude: 426 bytes of flash written
avrdude: verifying flash memory against TESTTOOL.HEX:
avrdude: load data flash data from input file TESTTOOL.HEX:
avrdude: input file TESTTOOL.HEX auto detected as Intel Hex
avrdude: input file TESTTOOL.HEX contains 426 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.17s

avrdude: verifying ...
avrdude: 426 bytes of flash verified

avrdude: safemode: lfuse reads as E1
avrdude: safemode: hfuse reads as D9
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Frage nach der richtigen Programmiersprache

Mögliche Sprachen:

Für C entschieden, weil am universellsten einsetzbar und nah genug am AVR.

Verstehen des Unterschieds zwischen Pins und Ports

Pin: ein Anschluss des AVRs

Port: Gruppe von mehreren Pins, z.B. besteht der PortD aus

Ein Port kann maximal 8 (0-7) Anschlüsse haben (siehe Definieren von I/O)

Hexadezimale Schreibweise

Bit Nr. 7 6 5 4 3 2 1 0
dezimal 128 64 32 16 8 4 2 1
hexadezimal 8 4 2 1 8 4 2 1
Beispiele:
0x11 0 0 0 1 0 0 0 1
0x3c 0 0 1 1 1 1 0 0
0x67 0 1 1 0 0 1 1 1
0x29 0 0 1 0 1 0 0 1
0xf3 1 1 1 1 0 0 1 1
0xa5 1 0 1 0 0 1 0 1

Man liest von rechts nach links und zählt alle Bits zusammen, deren Wert 1 ist.
"0x" leitet die hexadezimale Zahl ein. Dabei stehen die Buchstaben A bis F für die Zahlen 10 bis 15, da sie nur einen "Character" breit sind, d.h. 1 Buchstabe statt 2 Zahlen.

Definieren von I/O

Man kann selbst bestimmen, welcher Pin ein Eingang (In), und welcher ein Ausgang (Out) sein soll. Das muss für jeden Port einzeln gemacht werden. In C geht das für den PortD so:

Code:

DDRD = [hex.];

Das DDRD steht dabei für Data Direction Register PortD

Wenn beide LEDs an sein sollen, braucht man also folgendes:

Pin von PortD 7 6 5 4 3 2 1 0
hexadezimal 8 4 2 1 8 4 2 1
I = Eingang (in)
O = Ausgang (out)
x = egal => Eingang
x O O I I I x x
0 (Null) = Eingang
1 = Ausgang
0 1 1 0 0 0 0 0
=> hex. = 0x60

Die ersten Programme

Um die Dateien einfach übertragen zu können, sollte man als Erstes ein makefile schreiben. Den Dateinamen muss man natürlich anpassen!

Jetzt geht's aber an die Programme:

  1. Als erstes wollen wir LED1 anschalten, solange Taster 1 gedrückt wird, LED2, solange der 2. Taster gedrückt wird. Das fertige Programm findet Ihr hier: bsp-01-led.c

  2. Das erste Programm wird so abgeändert, dass man die LEDs mit einem „Klick” an- bzw. ausschalten kann: bsp-02-led-merken.c

  3. Die beiden LEDs blinken abwechselnd: bsp-03-led-wechselblinker.c


Bookmarken / Weitersagen | RSS-Feed abonnieren