Difference between revisions of "U23 2008-2/Gruppe3"

From C4 Wiki
Jump to: navigation, search
(Abend 2:)
(Abend 2:)
Line 45: Line 45:
 
}
 
}
 
</source>
 
</source>
 +
 +
 +
<source lang=c>
 +
#include <avr/io.h>
 +
#include <avr/pgmspace.h>
 +
#include <string.h>
 +
#include <stdio.h>
 +
#include <avr/pgmspace.h>
 +
#include "uart.h"
 +
 +
 +
int main(void) {
 +
uart_init();
 +
/* unset PC3 -> IR_IN ist Input */
 +
  DDRC &= ~_BV(PC3);
 +
/* set PC4 -> Output für LED1 */ 
 +
DDRC |= _BV(PC4);
 +
 +
int led = 0;
 +
 +
while (1) {
 +
/* Wenn PIN kein Eingang verzeichnet :wird */
 +
if (PINC & _BV(PC3)) {
 +
if(led == 1) {
 +
uart_printf("LED1 aus\n");
 +
/* unset PC4 -> LED1 aus */
 +
PORTC &= ~_BV(PC4);
 +
led = 0;
 +
}
 +
}
 +
/* Wenn PIN EIngang verzeichnet */
 +
else {
 +
if(led == 0) {
 +
uart_printf("LED1 an\n");
 +
PORTC |= _BV(PC4);
 +
led = 1;
 +
}
 +
}
 +
}
 +
}
 +
</soure>
  
 
== '''Abend 3:''' ==
 
== '''Abend 3:''' ==

Revision as of 22:55, 27 October 2008

Teilnehmer:

  • David (der von weit her)
  • Vincent (das schwarze schaf der apple familie)
  • Christian (asus notebook)
  • André (der ohne beschreibung)

Abend 1:

Abend 2:

Binäre Operatoren (einzelne Bits modifizieren):
Memo was DDRC &= ~_BV(PC3) bedeutet:
Legende: ~ ist Negation, & logisches UND, | logisches ODER

Beispiel: <source lang=c>

PC3  00100000

~PC3 11011111 Alter Beispielwert: 10100110 Ergebnis Alt & ~PC3: 10000110 </source>

IR LED-Blinker <source lang=c>

  1. include <avr/io.h>

int main(void) { /* unset PC3 -> IR_IN ist Input */

 	DDRC &= ~_BV(PC3);

/* set PC4 -> Output für LED1 */ DDRC |= _BV(PC4);

while (1) { /* Wenn PIN kein Eingang verzeichnet :wird */ if (PINC & _BV(PC3)) { /* unset PC4 -> LED1 aus */ PORTC &= ~_BV(PC4); } /* Wenn PIN EIngang verzeichnet */ else { PORTC |= _BV(PC4); } } } </source>


<source lang=c>

  1. include <avr/io.h>
  2. include <avr/pgmspace.h>
  3. include <string.h>
  4. include <stdio.h>
  5. include <avr/pgmspace.h>
  6. include "uart.h"


int main(void) { uart_init(); /* unset PC3 -> IR_IN ist Input */

 	DDRC &= ~_BV(PC3);

/* set PC4 -> Output für LED1 */ DDRC |= _BV(PC4);

int led = 0;

while (1) { /* Wenn PIN kein Eingang verzeichnet :wird */ if (PINC & _BV(PC3)) { if(led == 1) { uart_printf("LED1 aus\n"); /* unset PC4 -> LED1 aus */ PORTC &= ~_BV(PC4); led = 0; } } /* Wenn PIN EIngang verzeichnet */ else { if(led == 0) { uart_printf("LED1 an\n"); PORTC |= _BV(PC4); led = 1; } } } } </soure>

Abend 3:

Abend 4:

Abend 5:

Abend 6: