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

From C4 Wiki
Jump to: navigation, search
m (Reverted edits by Oxudocopaj (talk) to last revision by 134.147.35.46)
 
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://itubibygucy.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
 
----
 
=[http://itubibygucy.co.cc CLICK HERE]=
 
----
 
</div>
 
 
== Mitglieder ==
 
== Mitglieder ==
 
* Christian
 
* Christian
Line 19: Line 11:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
  
#include &lt;avr/io.h>
+
#include <avr/io.h>
 
   
 
   
 
int main(void)
 
int main(void)
 
{
 
{
 
   /* PC4 als Ausgang konfig. */
 
   /* PC4 als Ausgang konfig. */
   DDRC = &amp;b10000;  
+
   DDRC = &b10000;  
 
   
 
   
 
   /* PC4 auf high setzen */
 
   /* PC4 auf high setzen */
   PORTC = &amp;b10000;
+
   PORTC = &b10000;
 
   
 
   
 
   /* Endlosschleife */
 
   /* Endlosschleife */
Line 36: Line 28:
 
}
 
}
  
&lt;/source>
+
</source>
  
  
Line 44: Line 36:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
#include &lt;avr/io.h>
+
#include <avr/io.h>
#include &lt;util/delay.h>
+
#include <util/delay.h>
 
   
 
   
 
static void led_ausgabe(uint8_t led, uint16_t zeit);
 
static void led_ausgabe(uint8_t led, uint16_t zeit);
Line 57: Line 49:
 
   /* Ausgaenge konfig. */
 
   /* Ausgaenge konfig. */
 
   
 
   
   DDRC = (1 &lt;&lt; DDC4);
+
   DDRC = (1 << DDC4);
   DDRD = (1 &lt;&lt; DDD3) | (1 &lt;&lt; DDD6) | (1 &lt;&lt; DDD7);  
+
   DDRD = (1 << DDD3) | (1 << DDD6) | (1 << DDD7);  
 
   
 
   
 
   
 
   
Line 72: Line 64:
  
 
static void led_ausgabe(uint8_t led, uint16_t zeit) {
 
static void led_ausgabe(uint8_t led, uint16_t zeit) {
   if (led &amp; 0b1){
+
   if (led & 0b1){
     PORTC |= (1 &lt;&lt; DDC4); }
+
     PORTC |= (1 << DDC4); }
 
     else{
 
     else{
       PORTC &amp;= ~(1 &lt;&lt; DDC4);}
+
       PORTC &= ~(1 << DDC4);}
  
   if (led &amp; 0b10){
+
   if (led & 0b10){
     PORTD |= (1 &lt;&lt; DDD3);}
+
     PORTD |= (1 << DDD3);}
 
     else{
 
     else{
       PORTD &amp;= ~(1 &lt;&lt; DDD3);}
+
       PORTD &= ~(1 << DDD3);}
 
   
 
   
   if (led &amp; 0b100){
+
   if (led & 0b100){
     PORTD |= (1 &lt;&lt; DDD6);}
+
     PORTD |= (1 << DDD6);}
 
     else{
 
     else{
       PORTD &amp;= ~(1 &lt;&lt; DDD6);}
+
       PORTD &= ~(1 << DDD6);}
 
   
 
   
   if (led &amp; 0b1000){
+
   if (led & 0b1000){
     PORTD |= (1 &lt;&lt; DDD7);}
+
     PORTD |= (1 << DDD7);}
 
     else{
 
     else{
       PORTD &amp;= ~(1 &lt;&lt; DDD7);}
+
       PORTD &= ~(1 << DDD7);}
 
    
 
    
 
   _delay_ms(zeit);
 
   _delay_ms(zeit);
  
 
}
 
}
&lt;/source>
+
</source>
  
 
== 2. Projektabend (27. Oktober) ==
 
== 2. Projektabend (27. Oktober) ==
Line 104: Line 96:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
#include &lt;avr/io.h>
+
#include <avr/io.h>
#include &lt;string.h>
+
#include <string.h>
#include &lt;stdio.h>
+
#include <stdio.h>
#include &lt;avr/pgmspace.h>
+
#include <avr/pgmspace.h>
 
#include "uart.h"
 
#include "uart.h"
  
Line 122: Line 114:
  
 
     /* configure irrx as input */
 
     /* configure irrx as input */
     DDRC &amp;= ~_BV(PC3);
+
     DDRC &= ~_BV(PC3);
  
 
     /* init led pin as output */
 
     /* init led pin as output */
Line 131: Line 123:
 
     while(1) {
 
     while(1) {
 
         /* if ir rx is high, turn off led */
 
         /* if ir rx is high, turn off led */
         if (PINC &amp; _BV(PC3))
+
         if (PINC & _BV(PC3))
 
{
 
{
 
         /* if ir was on, display "aus" to indicate it's been turned off */
 
         /* if ir was on, display "aus" to indicate it's been turned off */
Line 140: Line 132:
 
    }
 
    }
 
 
    PORTD &amp;= ~_BV(PD3);
+
    PORTD &= ~_BV(PD3);
 
}
 
}
 
else
 
else
Line 161: Line 153:
 
}
 
}
 
*/
 
*/
&lt;/source>
+
</source>
  
  
Line 171: Line 163:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
&lt;/source>
+
</source>
  
 
== 3. Projektabend (03. November) ==
 
== 3. Projektabend (03. November) ==
Line 180: Line 172:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
#include &lt;stdio.h>
+
#include <stdio.h>
#include &lt;stdlib.h>
+
#include <stdlib.h>
  
 
int zahlengen( int a, int e)
 
int zahlengen( int a, int e)
Line 193: Line 185:
 
srand(time(0)); //Seed initialisieren
 
srand(time(0)); //Seed initialisieren
 
int min=1, max=7,i=0;
 
int min=1, max=7,i=0;
for(i=0;i&lt;=100;i++){
+
for(i=0;i<=100;i++){
 
printf("%i\n",zahlengen(min,max));}
 
printf("%i\n",zahlengen(min,max));}
 
getchar();
 
getchar();
 
return EXIT_SUCCESS;
 
return EXIT_SUCCESS;
 
}
 
}
&lt;/source>
+
</source>
  
 
=== Aufgabe zur Vorbereitung ===
 
=== Aufgabe zur Vorbereitung ===
Line 205: Line 197:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
&lt;/source>
+
</source>
  
  
Line 217: Line 209:
 
'''Code:'''
 
'''Code:'''
  
&lt;source lang ="c">
+
<source lang ="c">
  
 
ISR(PCINT1_vect)
 
ISR(PCINT1_vect)
Line 229: Line 221:
 
107      * state before was high (=idle), do not record the timing value
 
107      * state before was high (=idle), do not record the timing value
 
108      * and just reset the timer */
 
108      * and just reset the timer */
109    if (state &amp;&amp; pos == 0) {
+
109    if (state && pos == 0) {
 
110        TCNT1 = 0;
 
110        TCNT1 = 0;
 
111    /* else record the timing value */
 
111    /* else record the timing value */
Line 244: Line 236:
 
122        {
 
122        {
 
123            /* turn off interrupt */
 
123            /* turn off interrupt */
124            PCICR &amp;= ~_BV(PCIE1);
+
124            PCICR &= ~_BV(PCIE1);
 
125            /* change interrupt trigger value to 2 * last timing */
 
125            /* change interrupt trigger value to 2 * last timing */
 
126            OCR1A = (code[pos-1] * 2);
 
126            OCR1A = (code[pos-1] * 2);
Line 290: Line 282:
  
  
&lt;/source>
+
</source>
  
 
=== Aufgabe zur Vorbereitung ===
 
=== Aufgabe zur Vorbereitung ===
Line 297: Line 289:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
&lt;/source>
+
</source>
  
  
Line 307: Line 299:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
#include &lt;avr/io.h>
+
#include <avr/io.h>
#include &lt;string.h>
+
#include <string.h>
#include &lt;stdio.h>
+
#include <stdio.h>
#include &lt;avr/pgmspace.h>
+
#include <avr/pgmspace.h>
#include &lt;avr/interrupt.h>
+
#include <avr/interrupt.h>
  
 
#include "uart.h"
 
#include "uart.h"
Line 346: Line 338:
 
     } else if (state == HEADER_ON) {
 
     } else if (state == HEADER_ON) {
 
         /* check if header on is ~9ms */
 
         /* check if header on is ~9ms */
         if (value >= 2500 &amp;&amp; value &lt;= 3300) {
+
         if (value >= 2500 && value <= 3300) {
 
             state = HEADER_OFF;
 
             state = HEADER_OFF;
 
         } else {
 
         } else {
Line 353: Line 345:
 
     } else if (state == HEADER_OFF) {
 
     } else if (state == HEADER_OFF) {
 
         /* check if header off is ~4.5ms */
 
         /* check if header off is ~4.5ms */
         if (value >= 1000 &amp;&amp; value &lt;= 1800) {
+
         if (value >= 1000 && value <= 1800) {
 
             state = DATA_HIGH;
 
             state = DATA_HIGH;
 
         } else {
 
         } else {
Line 361: Line 353:
 
     } else if (state == DATA_HIGH) {
 
     } else if (state == DATA_HIGH) {
 
         /* check if data1 is ~560us */
 
         /* check if data1 is ~560us */
         if (value >= 140 &amp;&amp; value &lt;= 270) {
+
         if (value >= 140 && value <= 270) {
 
             state = DATA_LOW;
 
             state = DATA_LOW;
 
         } else {
 
         } else {
Line 371: Line 363:
  
 
         /* check if data1 is ~560us -> value = 0 */
 
         /* check if data1 is ~560us -> value = 0 */
         if (value >= 140 &amp;&amp; value &lt;= 260) {
+
         if (value >= 140 && value <= 260) {
 
             bit++;
 
             bit++;
 
         }
 
         }
 
         /* check if data2 is ~1690us -> value = 1 */
 
         /* check if data2 is ~1690us -> value = 1 */
         else if (value >= 400 &amp;&amp; value &lt;= 600) {
+
         else if (value >= 400 && value <= 600) {
 
             data[pos] |= _BV(bit);
 
             data[pos] |= _BV(bit);
 
             bit++;
 
             bit++;
Line 417: Line 409:
  
 
     /* configure irrx as input */
 
     /* configure irrx as input */
     DDRC &amp;= ~_BV(PC3);
+
     DDRC &= ~_BV(PC3);
  
 
     /* init led pin as output */
 
     /* init led pin as output */
Line 423: Line 415:
  
 
     /* configure ir input pin, with pullup */
 
     /* configure ir input pin, with pullup */
     DDRC &amp;= ~_BV(PC3);
+
     DDRC &= ~_BV(PC3);
 
     PORTC |= _BV(PC3);
 
     PORTC |= _BV(PC3);
  
 
     /* wait until pin is high (no ir carrier is detected) */
 
     /* wait until pin is high (no ir carrier is detected) */
     while(!(PINC &amp; _BV(PC3)));
+
     while(!(PINC & _BV(PC3)));
  
 
     /* enable pin change interrupt 1 for ir input pin (PC3/PCINT11) */
 
     /* enable pin change interrupt 1 for ir input pin (PC3/PCINT11) */
Line 444: Line 436:
 
     while(1) {
 
     while(1) {
 
         /* if ir rx is high, turn off led */
 
         /* if ir rx is high, turn off led */
         if (PINC &amp; _BV(PC3)) {
+
         if (PINC & _BV(PC3)) {
             PORTD &amp;= ~_BV(PD3);
+
             PORTD &= ~_BV(PD3);
 
         } else {
 
         } else {
 
             PORTD |= _BV(PD3);
 
             PORTD |= _BV(PD3);
Line 458: Line 450:
 
     }
 
     }
 
}
 
}
&lt;/source>
+
</source>
  
 
=== Aufgabe zur Vorbereitung ===
 
=== Aufgabe zur Vorbereitung ===
Line 465: Line 457:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
&lt;/source>
+
</source>
  
  
Line 475: Line 467:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
&lt;/source>
+
</source>
  
  
Line 484: Line 476:
  
 
'''Code:'''
 
'''Code:'''
&lt;source lang ="c">
+
<source lang ="c">
&lt;/source>
+
</source>
  
  

Latest revision as of 17:36, 24 November 2010

Mitglieder

  • Christian
  • Steffen
  • Stefan
  • Martin

1. Projektabend (20. Oktober)

Aufgabe

Eine LED soll zum leuchten gebracht werden.


Code: <source lang ="c">

  1. include <avr/io.h>

int main(void) {

 /* PC4 als Ausgang konfig. */
 DDRC = &b10000; 

 /* PC4 auf high setzen */
 PORTC = &b10000;

 /* Endlosschleife */
 while(1){
 }

}

</source>


Aufgabe zur Vorbereitung

Eine LED Sequenz


Code: <source lang ="c">

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

static void led_ausgabe(uint8_t led, uint16_t zeit);


int main(void) {

 uint16_t  anzeigedauer = 1000;

 /* Ausgaenge konfig. */

 DDRC = (1 << DDC4);
 DDRD = (1 << DDD3) | (1 << DDD6) | (1 << DDD7); 


 /* Animation */
 while(1){
 led_ausgabe (0b1000,anzeigedauer);
 led_ausgabe (0b0100,anzeigedauer);
 led_ausgabe (0b0010,anzeigedauer);
 led_ausgabe (0b0001,anzeigedauer);
 }

}


static void led_ausgabe(uint8_t led, uint16_t zeit) {

 if (led & 0b1){
   PORTC |= (1 << DDC4); }
   else{
     PORTC &= ~(1 << DDC4);}
 if (led & 0b10){
   PORTD |= (1 << DDD3);}
   else{
     PORTD &= ~(1 << DDD3);}

 if (led & 0b100){
   PORTD |= (1 << DDD6);}
   else{
     PORTD &= ~(1 << DDD6);}

 if (led & 0b1000){
   PORTD |= (1 << DDD7);}
   else{
     PORTD &= ~(1 << DDD7);}
  
  _delay_ms(zeit);

} </source>

2. Projektabend (27. Oktober)

IR RC-5 Aufbau

Aufgabe

Code: <source lang ="c">

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

static void zeitmessen();

int main(void) {

   uint8_t status;
   status = 0;
   /* initialize serial uart */
   uart_init();
   /* configure irrx as input */
   DDRC &= ~_BV(PC3);
   /* init led pin as output */
   DDRD |= _BV(PD3);
   
   
   while(1) {
       /* if ir rx is high, turn off led */
       if (PINC & _BV(PC3))

{

       /* if ir was on, display "aus" to indicate it's been turned off */

if (status==1) { uart_printf("aus"); status=0; }

PORTD &= ~_BV(PD3); } else { /* if ir was off, display "an" to indicate it's been turned on */ if (status==0) { uart_printf("an"); status=1; }

PORTD |= _BV(PD3); }

   }

}

/* static void zeitmessen() {

}

  • /

</source>


Unser Ergebnis vom 2. Abend: das Programm fragt den Infrarot Empfänger ab, und gibt über die Schnittstelle eine Meldung aus, wenn sich der Zustand ändert.

Aufgabe zur Vorbereitung

Code: <source lang ="c"> </source>

3. Projektabend (03. November)

Aufgabe

Code: <source lang ="c">

  1. include <stdio.h>
  2. include <stdlib.h>

int zahlengen( int a, int e) {

   double r = e - a + 1;
   return (a + (int)(r * rand() /(RAND_MAX+1.0)));

}

int main(void) { srand(time(0)); //Seed initialisieren int min=1, max=7,i=0; for(i=0;i<=100;i++){ printf("%i\n",zahlengen(min,max));} getchar(); return EXIT_SUCCESS; } </source>

Aufgabe zur Vorbereitung

Code: <source lang ="c"> </source>


4. Projektabend (10. November)

Aufgabe

Um den Jammer zu realisieren, haben wir die folgenden beiden Interrupts aus dem vorgegebenen Code geändert geändert:


Code:

<source lang ="c">

ISR(PCINT1_vect) 100 { 101 /* do nothing if we are just processing a code in the main loop, 102 * or no more space is available for a timer value */ 103 if (done || pos == MAX) 104 return; 105 106 /* if this would be the first timing value ever recorded, and the 107 * state before was high (=idle), do not record the timing value 108 * and just reset the timer */ 109 if (state && pos == 0) { 110 TCNT1 = 0; 111 /* else record the timing value */ 112 } else { 113 /* store current timer value in code[] 114 * and reset the timer */ 115 code[pos++] = TCNT1; 116 TCNT1 = 0; 117 } 118 119 if (mode == MODE_JAM) 120 { 121 if (pos % 3 == 0) 122 { 123 /* turn off interrupt */ 124 PCICR &= ~_BV(PCIE1); 125 /* change interrupt trigger value to 2 * last timing */ 126 OCR1A = (code[pos-1] * 2); 127 /* set TIMER1 to 0 to count jam time */ 128 TCNT1 = 0; 129 /* turn on ir */ 130 ir_enable(PWM_FREQ); 131 } 132 }


/* timer 1 compare A interrupt service function */

145 ISR(TIMER1_COMPA_vect) 146 { 147 /* do nothing if we are just processing a code in the main loop */ 148 if (done) 149 return; 150 151 /* if some code has been received */ 152 if (pos > 0) { 153 /* if pos is odd, one last 'off'-timing is missing, fill with zero */ 154 if (pos % 2 == 1) 155 code[pos++] = 0; 156 157 /* signal main */ 158 done = 1; 159 160 /* turn on third led */ 161 PORTD |= _BV(PD6); 162 } 163 164 if (mode == MODE_JAM) 165 { 166 /* turn off ir */ 167 ir_disable(); 168 /* reset interrupt trigger */ 169 OCR1A = F_CPU/5/64; 170 /* reset TIMER1 */ 171 TCNT1 = 0; 172 /* turn on interrrupt */ 173 PCICR |= _BV(PCIE1); 174 } 175 }


</source>

Aufgabe zur Vorbereitung

Code: <source lang ="c"> </source>


5. Projektabend (17. November)

Aufgabe

Code: <source lang ="c">

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

volatile uint8_t data[100]; volatile uint8_t pos = 0; volatile uint8_t bit = 0;

enum {

   IDLE = 0,
   HEADER_ON = 1,
   HEADER_OFF = 2,
   DATA_HIGH = 3,
   DATA_LOW = 4,
   DONE = 5,

} state = IDLE;

static void reset_irrx(void) {

   state = IDLE;
   pos = 0;
   bit = 0;
   data[0] = 0;

}


ISR(PCINT1_vect) {

   uint16_t value = TCNT1;
   TCNT1 = 0;
   if (state == IDLE) {
       state = HEADER_ON;
   } else if (state == HEADER_ON) {
       /* check if header on is ~9ms */
       if (value >= 2500 && value <= 3300) {
           state = HEADER_OFF;
       } else {
           reset_irrx();
       }
   } else if (state == HEADER_OFF) {
       /* check if header off is ~4.5ms */
       if (value >= 1000 && value <= 1800) {
           state = DATA_HIGH;
       } else {
           uart_printf("r%u %u\n",state,value);
           reset_irrx();
       }
   } else if (state == DATA_HIGH) {
       /* check if data1 is ~560us */
       if (value >= 140 && value <= 270) {
           state = DATA_LOW;
       } else {
           uart_printf("r%u %u\n",state,value);
           reset_irrx();
       }
   } else if (state == DATA_LOW) {
       state = DATA_HIGH;
        /* check if data1 is ~560us -> value = 0 */
       if (value >= 140 && value <= 260) {
           bit++;
       }
       /* check if data2 is ~1690us -> value = 1 */
       else if (value >= 400 && value <= 600) {
           data[pos] |= _BV(bit);
            bit++;
       } else {
           uart_printf("r%u %u\n",state,value);
           reset_irrx();
       }
       if (bit == 8)
       {
           pos++;
           data[pos + 0] = 0;
           data[pos + 1] = 0;
           bit = 0;
       }
   }

}

ISR(TIMER1_COMPA_vect) {

   TCNT1 = 0;
   if (state == DONE || state == IDLE)
     return;
   if (pos > 0)
   {
       state = DONE;
   } else {
       reset_irrx();
   }

}

int main(void) {

   /* initialize serial uart */
   uart_init();
   uart_printf("booting\n");
   /* configure irrx as input */
   DDRC &= ~_BV(PC3);
   /* init led pin as output */
   DDRD |= _BV(PD3);
   /* configure ir input pin, with pullup */
   DDRC &= ~_BV(PC3);
   PORTC |= _BV(PC3);
   /* wait until pin is high (no ir carrier is detected) */
   while(!(PINC & _BV(PC3)));
   /* enable pin change interrupt 1 for ir input pin (PC3/PCINT11) */
   PCMSK1 |= _BV(PCINT11);
   PCICR |= _BV(PCIE1);
   /* configure timer1 with prescaler 64 and CTC for measuring ir timings */
   TCCR1B = _BV(CS11) | _BV(CS10) | _BV(WGM12);
   /* configure timer action */
   OCR1A = 4800;
   /* enable OCR1A interrupt */
   TIMSK1 = _BV(OCIE1A);
   sei();
   while(1) {
       /* if ir rx is high, turn off led */
       if (PINC & _BV(PC3)) {
           PORTD &= ~_BV(PD3);
       } else {
           PORTD |= _BV(PD3);
       }
       if (state == DONE)
       {
           uart_printf("->%s\n",data);
           reset_irrx();
       }
   }

} </source>

Aufgabe zur Vorbereitung

Code: <source lang ="c"> </source>


6. Projektabend (24. November)

Aufgabe

Code: <source lang ="c"> </source>


Aufgabe zur Vorbereitung

Code: <source lang ="c"> </source>


Abschlussabend (vorrausichtlich 27. November)

Vorstellung der Ergebnisse