Difference between revisions of "U23 2008/Gruppe4"

From C4 Wiki
Jump to: navigation, search
(... Kommentar fertig geschriben *rofl*)
m (Category)
Line 75: Line 75:
 
   }
 
   }
 
  }
 
  }
 +
 +
[[Category:U23 2008]]

Revision as of 15:35, 24 August 2008

Wir saßen am Go-Brett (Brett mit den Kästchen drauf).

News

Ich hab meine Bitshift-Geschichte gefixt (zwar nicht getestet, sollte aber nun wirklich laufen...) --Lostgeek 16:52, 19 August 2008 (UTC)

Mitglieder

  • lostgeek (Hemd, 180cm, MacBook)
  • ...
  • ...
  • ...


Sourcecode, Abend1

aufgabe1.c

#include <avr/io.h>
#include <util/delay.h>

static void display(uint8_t led_config) {
  /* Usage: led_config ist wie folgt aufgebaut:
                  0b0000 LED4 LED3 LED2 LED1
                  
                  Wenn alle LEDs an sind heisst das led_config = 0b00001111.
  */
  /* Erklärung: Über die led_config wird eine Maske gelegt (AND) um nur das nötige Bit übrig zu 
                lassen. Dieses übrige Bit wird dann an die richtige Stelle geshiftet.
                Die Erklärung an jeder Zeile ist die ausführliche Variante, wo das nötige Bit erst
                an das erste Bit geshiftet und danach an die benötigte Stelle geshiftet wird.
  */
  PORTC =  (led_config & 0b00000001)<<4; /* >>0 <<4 (PC4) */
  PORTD =  (led_config & 0b00000010)<<2; /* >>1 <<3 (PD3) */
  PORTD ^= (led_config & 0b00000100)<<4; /* >>2 <<6 (PD6) */
  PORTD ^= (led_config & 0b00001000)<<4; /* >>3 <<7 (PD7) */
}


static void delay(uint16_t delay){ // Von Gruppe 2 kopiert. Ungetestet.
  /* Usage: delay ist die Zeit in ms. */
  uint16_t i;
  for (i = 0; i < delay; i++) {
    /* wait 4 * 5000 cycles */
    _delay_loop_2(5000);
  }         
}


void main(void) {

  /* configure LEDs as output */
  DDRD = _BV(PD3) | _BV(PD6) | _BV(PD7);
  DDRC = _BV(PC4);
  
  uint8_t led_configs[] = { 0b00001000, //0
                            0b00000100,
                            0b00000010,
                            0b00000001,
                            0b00000010,
                            0b00000100, //5
                            0b00001000,
                            0b00001010,
                            0b00000101,
                            0b00001010,
                            0b00000101, //10
                            0b00001111,
                            0b00000000
                          };
  uint8_t led_config_size = 12;
                          
  while(1) {
    uint8_t i;
    for(i = 0; i < led_config_size; i++) { //Arraylösung ungetestet.
      display(led_configs[i]);
      delay(50);
    }
  }
}