|
|
Zeile 7: |
Zeile 7: |
| Das Board besteht im Kern aus einem ATmega-32-Controller, an den 4 Taster angeschlossen sind (Port B) und 8 LEDs (Port C). Ansonsten befindet sich auf der Platine noch ein 16 MHz Quartz f�r die Taktung, ein Reset-Taster, und eine kleine Schaltung zum stabilisieren der Versorgungsspannung. | | Das Board besteht im Kern aus einem ATmega-32-Controller, an den 4 Taster angeschlossen sind (Port B) und 8 LEDs (Port C). Ansonsten befindet sich auf der Platine noch ein 16 MHz Quartz f�r die Taktung, ein Reset-Taster, und eine kleine Schaltung zum stabilisieren der Versorgungsspannung. |
|
| |
|
| | | [[LMB-TestCode1]] |
| ===Demo-Code===
| |
| Den folgenden C-Code einfach unter '''demo.c''' speichern und die folgende Makefile einfach unter '''Makefile'''. Und dann k�nnt ihr mit '''make''' das demo-Programm f�r den AVR erzeugen. Falls '''make''' mit einer Fehlermeldung ala ''***missing seperator (did you mean TAB instaed of 8 spaces?)'' abbricht, k�nnt ihr mit '''<pre>sed s/" "/\\t/g Makefile > makefile</pre>''' das Problem beheben (zwischen den Anf�hrungszeichen m�ssen entsprechend der Fehlermedung viele Leerzeichen sein).
| |
| ====C-Code====
| |
| <pre class="code">
| |
| //demo.c
| |
| //This is a simple Demo for the Labor Board.
| |
| //It displays 2 different light patterns on the LEDs,
| |
| //and allows the pattern to be selected, and the speed to be controled
| |
| //with the 4 keys.
| |
| | |
| #include <inttypes.h>
| |
| #include <avr/io.h>
| |
| | |
| int main (void)
| |
| {
| |
| DDRB = 0; //Port B all inputs
| |
| PORTB = 0x0F; //Internal Pullups on on key inputs
| |
|
| |
| DDRC = 0xFF; //Port C all outputs
| |
| PORTC = 0x01; //1 LED on to start of Patterns
| |
|
| |
| int x, delay=10000; char mode=0, ud=0;
| |
|
| |
| for ( ;; ){ //for ever
| |
|
| |
| //this is a time delay loop
| |
| for(x=0; x< delay; x++){
| |
| //The volatile qualifier tells the compiler not to optimize
| |
| //it away.
| |
| volatile int y = 0;
| |
| };
| |
|
| |
| if(!mode){
| |
| //knight rider mode
| |
| switch (ud){
| |
| case 0: //shift light left
| |
| if( (PORTC<<=1) == 0x80 ){ //until bit7 is reached
| |
| ud = 1;
| |
| };
| |
| break;
| |
| case 1: //shift bit right
| |
| if( (PORTC>>=1) == 0x01 ){ //until bit0 is reached
| |
| ud = 0;
| |
| };
| |
| break;
| |
| };
| |
| }else{
| |
| //scroll mode
| |
| switch (ud){
| |
| case 0:
| |
| PORTC|=(PORTC<<1);//shift additional ones in from left
| |
| if(PORTC & 0x80) //until bit7 is reached
| |
| ud = 1;
| |
| break;
| |
| case 1:
| |
| PORTC<<=1; //shift zeros in
| |
| if (PORTC == 0){//until all zeros
| |
| ud = 0;
| |
| PORTC = 0x01;//start over
| |
| }
| |
| break;
| |
|
| |
| };
| |
|
| |
| }
| |
|
| |
| switch(PINB&0x0f){
| |
| case 0x0E: //Button 1 pressed
| |
| if (delay<30000){
| |
| delay += 100;
| |
| }
| |
| break;
| |
| case 0x0D: //Button 2 pressed
| |
| if (delay>1000){
| |
| delay -= 100;
| |
| }
| |
| break;
| |
| case 0x0B: //Button 3 pressed
| |
| mode = 0;
| |
| break;
| |
| case 0x07: //Button 4 pressed
| |
| mode = 1;
| |
| break;
| |
| };
| |
|
| |
|
| |
| };
| |
| }
| |
| </pre>
| |
| ====Makefile====
| |
| <pre class="code">
| |
| PRG = demo
| |
| OBJ = demo.o
| |
| MCU_TARGET = atmega32
| |
| OPTIMIZE = -Os
| |
| | |
| DEFS =
| |
| LIBS =
| |
| | |
| # You should not have to change anything below here.
| |
| | |
| CC = avr-gcc
| |
| | |
| # Override is only needed by avr-lib build system.
| |
| | |
| override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
| |
| $(DEFS)
| |
| override LDFLAGS = -Wl,-Map,$(PRG).map
| |
| | |
| OBJCOPY = avr-objcopy
| |
| OBJDUMP = avr-objdump
| |
| | |
| all: $(PRG).elf lst text eeprom
| |
| | |
| $(PRG).elf: $(OBJ)
| |
| $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
| |
| | |
| clean:
| |
| rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak
| |
| rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
| |
| | |
| lst: $(PRG).lst
| |
| | |
| %.lst: %.elf
| |
| $(OBJDUMP) -h -S $< > $@
| |
| | |
| # Rules for building the .text rom images
| |
| | |
| text: hex bin srec
| |
| | |
| hex: $(PRG).hex
| |
| bin: $(PRG).bin
| |
| srec: $(PRG).srec
| |
| | |
| %.hex: %.elf
| |
| $(OBJCOPY) -j .text -j .data -O ihex $< $@
| |
| | |
| %.srec: %.elf
| |
| $(OBJCOPY) -j .text -j .data -O srec $< $@
| |
| | |
| %.bin: %.elf
| |
| $(OBJCOPY) -j .text -j .data -O binary $< $@
| |
| | |
| # Rules for building the .eeprom rom images
| |
| | |
| eeprom: ehex ebin esrec
| |
| | |
| ehex: $(PRG)_eeprom.hex
| |
| ebin: $(PRG)_eeprom.bin
| |
| esrec: $(PRG)_eeprom.srec
| |
| | |
| %_eeprom.hex: %.elf
| |
| $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
| |
| | |
| %_eeprom.srec: %.elf
| |
| $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
| |
| | |
| %_eeprom.bin: %.elf
| |
| $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
| |
| | |
| # Every thing below here is used by avr-libc's build system and can be ignored
| |
| # by the casual user.
| |
| | |
| FIG2DEV = fig2dev
| |
| EXTRA_CLEAN_FILES = *.hex *.bin *.srec
| |
| | |
| dox: eps png pdf
| |
| | |
| eps: $(PRG).eps
| |
| png: $(PRG).png
| |
| pdf: $(PRG).pdf
| |
| | |
| %.eps: %.fig
| |
| $(FIG2DEV) -L eps $< $@
| |
| | |
| %.pdf: %.fig
| |
| $(FIG2DEV) -L pdf $< $@
| |
| | |
| %.png: %.fig
| |
| $(FIG2DEV) -L png $< $@
| |
| | |
| </pre>
| |
| | |
| | |
|
| |
|
|
| |
|
|
| |
|
| [[Category:Bastelecke]] | | [[Category:Bastelecke]] |