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

From C4 Wiki
Jump to: navigation, search
(Aufgabe)
(Aufgabe)
Line 188: Line 188:
 
=== Aufgabe ===
 
=== Aufgabe ===
  
 +
Um den Jammer zu realisieren, haben wir die folgenden beiden Interrupts aus dem vorgegebenen Code geändert geändert:
 +
 +
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 }
  
  
Line 193: Line 264:
 
<source lang ="c">
 
<source lang ="c">
 
</source>
 
</source>
 
  
 
=== Aufgabe zur Vorbereitung ===
 
=== Aufgabe zur Vorbereitung ===

Revision as of 21:36, 10 November 2008

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"> </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:

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 }


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

Aufgabe zur Vorbereitung

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


5. Projektabend (17. November)

Aufgabe

Code: <source lang ="c"> </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