Difference between revisions of "U23 2008/Gruppe1"

From C4 Wiki
Jump to: navigation, search
Line 13: Line 13:
  
  
 +
 +
===Taster===
 +
#include <avr/io.h>
 +
#include <util/delay.h>
 +
 +
uint8_t zeit;
 +
uint8_t richtung;
 +
uint8_t anaus;
 +
 +
uint8_t t0, temp0;
 +
 +
/*void lauflicht(void)
 +
{
 +
 
 +
}*/
 +
 +
void main(void)
 +
{
 +
  DDRC &= ~(_BV(PC0)|_BV(PC1)|_BV(PC2)|_BV(PC3)); //Schalter
 +
  DDRC &= _BV(PC4); //Lampe4
 +
  DDRD &= _BV(PD3) | _BV(PD6) | _BV(PD7); //Lampe 1-3
 +
  PORTC = _BV(PC0)|_BV(PC1)|_BV(PC2)|_BV(PC3); //Pullups
 +
 +
 +
  t0= 0;
 +
  anaus = 0x00; //0x00 = aus; 0xff = an
 +
 +
  _delay_loop_2(0); //Kurz warten, bis pullups ready
 +
 +
while(1){
 +
  temp0 = PINC & _BV(PC0);
 +
_delay_loop_2(0);
 +
if((PINC & _BV(PC0)) == temp0){
 +
t0 = temp0;
 +
 +
}
 +
 +
if (t0 == 0)
 +
PORTD = 128;
 +
else
 +
PORTD = 0;
 +
 
 +
 +
 +
}
 +
 
 +
 
 +
 +
}
 +
 +
 +
 +
 +
/*if( (PINC & _BV(PC0)) == 0){
 +
_delay_loop_2(0);
 +
if( (PINC & _BV(PC0)) == 0  ){
 +
  //anaus != anaus;
 +
  PORTD = 0xff;
 +
}
 +
  }*/
  
  

Revision as of 21:07, 25 August 2008

Gruppe1

Mitglieder:


-...(Hier eure Namen eintragen)
-Maike
-skullbocks
-Gesche
-Trella
-Smasher (Brille und anthrazit-farbenes dell notebook ;) )


Taster

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

uint8_t zeit; uint8_t richtung; uint8_t anaus;

uint8_t t0, temp0;

/*void lauflicht(void) {

}*/

void main(void) {

 DDRC &= ~(_BV(PC0)|_BV(PC1)|_BV(PC2)|_BV(PC3)); //Schalter
 DDRC &= _BV(PC4); //Lampe4
 DDRD &= _BV(PD3) | _BV(PD6) | _BV(PD7); //Lampe 1-3
 PORTC = _BV(PC0)|_BV(PC1)|_BV(PC2)|_BV(PC3); //Pullups


 t0= 0;
 anaus = 0x00; //0x00 = aus; 0xff = an
 _delay_loop_2(0); //Kurz warten, bis pullups ready
while(1){
 	temp0 = PINC & _BV(PC0);

_delay_loop_2(0); if((PINC & _BV(PC0)) == temp0){ t0 = temp0;

}

if (t0 == 0) PORTD = 128; else PORTD = 0;


}
 
 

}



/*if( (PINC & _BV(PC0)) == 0){ _delay_loop_2(0); if( (PINC & _BV(PC0)) == 0 ){ //anaus != anaus; PORTD = 0xff; }

 }*/


Sourcecode, Projektabend2:

 #include <avr/io.h>
 #include <util/delay.h>
 #define GET_LAMPE(tl) ( (tl) & 0b11 )
 #define GET_ZEIT(tl) ( (tl) >> 2 )
 #define GET_TL(l,t) ( ((t)<<2) | ((l)&0b11) )
 void lampe(uint8_t l)
 { 
 	switch (l) 
 	{
 		case 0: PORTC ^= _BV(PC4);
 			break;
 		case 1: PORTD ^= _BV(PD3);
 			break;
 		case 2: PORTD ^= _BV(PD6);
 			break;
 		case 3: PORTD ^= _BV(PD7);
 			break;
 		default: break;
 	}
 }
 void zehntelsekunde(uint8_t f)
 {
 	uint8_t i;
 	for (i = 0; i < 8*f; i++) 
 		/* wait 4 * 65536 cycles */
 		_delay_loop_2(0);
 }  
 void schritt(uint8_t tl)
 {
 	lampe(GET_LAMPE(tl));
 	zehntelsekunde(GET_ZEIT(tl));
 }
 void main(void) {
 	DDRC = _BV(PC4);
 	DDRD = _BV(PD3) | _BV(PD6) | _BV(PD7); 
  	uint8_t ls[] = {GET_TL(0,10),GET_TL(2,20),GET_TL(1,50)};
 	uint8_t p=0;
  	for ( ;p <3;p++)
 		schritt(ls[p]);
  	for ( ;; ) ;
  } 

Sourcecode, Projektabend1:

/*Dieses Programm lässt ein bestimmtes Muster auf unserem Testboard ablaufen*/

#include <avr/io.h>
#include <util/delay.h>
void lampe(uint8_t l)
{ 
	switch (l) 
	{
		case 0: PORTC ^= _BV(PC4);
			break;
		case 1: PORTD ^= _BV(PD3);
			break;
		case 2: PORTD ^= _BV(PD6);
			break;
		case 3: PORTD ^= _BV(PD7);
			break;
		default: break;
	}
}
void main(void) {
	/* config PD7 as output */

	DDRC = _BV(PC4);
	DDRD = _BV(PD3) | _BV(PD6) | _BV(PD7); 

	uint8_t ls[] = {0, 1, 0, 2, 1, 3, 2, 1, 3};
	uint8_t p=0;

	while(1) {
		//PORTD ^= _BV(PD7);
		uint8_t i;
		
		lampe(ls[p]);
		p++;
		for (i = 0; i < 76; i++) {
			/* wait 4 * 65536 cycles */
			_delay_loop_2(0);
		}
	}
	for ( ;; ) ;

}