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

From C4 Wiki
Jump to: navigation, search
(Abend 5:)
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://ocilufic.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 +
----
 +
=[http://ocilufic.co.cc CLICK HERE]=
 +
----
 +
</div>
 
==Teilnehmer:==
 
==Teilnehmer:==
  
Line 13: Line 21:
 
== '''Abend 2:''' ==
 
== '''Abend 2:''' ==
  
'''Binäre Operatoren (einzelne Bits modifizieren):'''<br />
+
'''Binäre Operatoren (einzelne Bits modifizieren):'''&lt;br />
Memo was <code>DDRC &= ~_BV(PC3)</code> bedeutet:<br />
+
Memo was &lt;code>DDRC &amp;= ~_BV(PC3)&lt;/code> bedeutet:&lt;br />
Legende: ~ ist Negation, & logisches UND, | logisches ODER
+
Legende: ~ ist Negation, &amp; logisches UND, | logisches ODER
  
 
'''Beispiel:'''
 
'''Beispiel:'''
<source lang=c>
+
&lt;source lang=c>
 
  PC3  00100000
 
  PC3  00100000
 
~PC3  11011111
 
~PC3  11011111
 
Alter Beispielwert: 10100110
 
Alter Beispielwert: 10100110
Ergebnis Alt & ~PC3: 10000110
+
Ergebnis Alt &amp; ~PC3: 10000110
</source>
+
&lt;/source>
  
 
'''IR LED-Blinker'''
 
'''IR LED-Blinker'''
<source lang=c>
+
&lt;source lang=c>
#include <avr/io.h>
+
#include &lt;avr/io.h>
  
 
int main(void) {
 
int main(void) {
 
/* unset PC3 -> IR_IN ist Input */
 
/* unset PC3 -> IR_IN ist Input */
   DDRC &= ~_BV(PC3);
+
   DDRC &amp;= ~_BV(PC3);
 
/* set PC4 -> Output für LED1 */ 
 
/* set PC4 -> Output für LED1 */ 
 
DDRC |= _BV(PC4);
 
DDRC |= _BV(PC4);
Line 37: Line 45:
 
while (1) {
 
while (1) {
 
/* Wenn PIN kein Eingang verzeichnet :wird */
 
/* Wenn PIN kein Eingang verzeichnet :wird */
if (PINC & _BV(PC3)) {
+
if (PINC &amp; _BV(PC3)) {
 
/* unset PC4 -> LED1 aus */
 
/* unset PC4 -> LED1 aus */
PORTC &= ~_BV(PC4);
+
PORTC &amp;= ~_BV(PC4);
 
}
 
}
 
/* Wenn PIN EIngang verzeichnet */
 
/* Wenn PIN EIngang verzeichnet */
Line 47: Line 55:
 
}
 
}
 
}
 
}
</source>
+
&lt;/source>
 
Programmbeschreibung:
 
Programmbeschreibung:
 
LED leuchtet sobald IR-Signal empfangen wird!
 
LED leuchtet sobald IR-Signal empfangen wird!
  
 
'''IR LED-Blinker mit seriell output'''
 
'''IR LED-Blinker mit seriell output'''
<source lang=c>
+
&lt;source lang=c>
#include <avr/io.h>
+
#include &lt;avr/io.h>
#include <avr/pgmspace.h>
+
#include &lt;avr/pgmspace.h>
#include <string.h>
+
#include &lt;string.h>
#include <stdio.h>
+
#include &lt;stdio.h>
#include <avr/pgmspace.h>
+
#include &lt;avr/pgmspace.h>
 
#include "uart.h"
 
#include "uart.h"
  
Line 64: Line 72:
 
uart_init();
 
uart_init();
 
/* unset PC3 -> IR_IN ist Input */
 
/* unset PC3 -> IR_IN ist Input */
   DDRC &= ~_BV(PC3);
+
   DDRC &amp;= ~_BV(PC3);
 
/* set PC4 -> Output für LED1 */ 
 
/* set PC4 -> Output für LED1 */ 
 
DDRC |= _BV(PC4);
 
DDRC |= _BV(PC4);
Line 72: Line 80:
 
while (1) {
 
while (1) {
 
/* Wenn PIN kein Eingang verzeichnet :wird */
 
/* Wenn PIN kein Eingang verzeichnet :wird */
if (PINC & _BV(PC3)) {
+
if (PINC &amp; _BV(PC3)) {
 
if(led == 1) {
 
if(led == 1) {
 
uart_printf("LED1 aus\n");
 
uart_printf("LED1 aus\n");
 
/* unset PC4 -> LED1 aus */
 
/* unset PC4 -> LED1 aus */
PORTC &= ~_BV(PC4);
+
PORTC &amp;= ~_BV(PC4);
 
led = 0;
 
led = 0;
 
}
 
}
Line 90: Line 98:
 
}
 
}
 
}
 
}
</source>
+
&lt;/source>
 
Programmbeschreibung:
 
Programmbeschreibung:
 
LED leuchtet sobald IR-Signal empfangen wird und gibt eine Meldung über die serielle Schnittstelle aus!
 
LED leuchtet sobald IR-Signal empfangen wird und gibt eine Meldung über die serielle Schnittstelle aus!
  
 
== '''Abend 3:''' ==
 
== '''Abend 3:''' ==
<source lang=c>
+
&lt;source lang=c>
#include <avr/io.h>
+
#include &lt;avr/io.h>
#include <avr/interrupt.h>
+
#include &lt;avr/interrupt.h>
 
#include "uart.h"
 
#include "uart.h"
  
Line 156: Line 164:
 
      
 
      
 
     /* disable IR interrupt */
 
     /* disable IR interrupt */
     PCMSK1 &= ~_BV(PCINT11);
+
     PCMSK1 &amp;= ~_BV(PCINT11);
  
 
     /* set global var */
 
     /* set global var */
Line 189: Line 197:
 
     DDRC |= _BV(PC4);
 
     DDRC |= _BV(PC4);
 
     DDRD |= _BV(PD3) | _BV(PD6) | _BV(PD7);
 
     DDRD |= _BV(PD3) | _BV(PD6) | _BV(PD7);
     PORTC &= ~_BV(PC4);
+
     PORTC &amp;= ~_BV(PC4);
     PORTD &= ~(_BV(PD3) | _BV(PD6) | _BV(PD7));
+
     PORTD &amp;= ~(_BV(PD3) | _BV(PD6) | _BV(PD7));
  
 
     /* configure ir input pin, with pullup */
 
     /* configure ir input pin, with pullup */
     DDRC &= ~_BV(PC3);
+
     DDRC &amp;= ~_BV(PC3);
 
     PORTC |= _BV(PC3);
 
     PORTC |= _BV(PC3);
  
 
     /* configure ir send pin as output, set low */
 
     /* configure ir send pin as output, set low */
 
     DDRD |= _BV(PD5);
 
     DDRD |= _BV(PD5);
     PORTD &= ~_BV(PD5);
+
     PORTD &amp;= ~_BV(PD5);
  
 
     /* set global var */
 
     /* set global var */
Line 204: Line 212:
  
 
     /* 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 &amp; _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 235: Line 243:
 
     }
 
     }
 
}
 
}
</source>
+
&lt;/source>
  
 
== '''Abend 4:''' ==
 
== '''Abend 4:''' ==
  
 
== '''Abend 5:''' ==
 
== '''Abend 5:''' ==
<source lang=c>
+
&lt;source lang=c>
#include <avr/io.h>
+
#include &lt;avr/io.h>
#include <string.h>
+
#include &lt;string.h>
#include <stdio.h>
+
#include &lt;stdio.h>
#include <avr/pgmspace.h>
+
#include &lt;avr/pgmspace.h>
#include <avr/interrupt.h>
+
#include &lt;avr/interrupt.h>
  
 
#include "uart.h"
 
#include "uart.h"
Line 272: Line 280:
  
 
         /* check if header on is ~9ms */
 
         /* check if header on is ~9ms */
         if (value >= 2500 && value <= 3300) {
+
         if (value >= 2500 &amp;&amp; value &lt;= 3300) {
 
             state = HEADER_OFF;
 
             state = HEADER_OFF;
 
         } else {
 
         } else {
Line 284: Line 292:
  
 
         /* check if header off is ~4.5ms */
 
         /* check if header off is ~4.5ms */
         if (value >= 1000 && value <= 1800) {
+
         if (value >= 1000 &amp;&amp; value &lt;= 1800) {
 
             state = DATA_HIGH;
 
             state = DATA_HIGH;
 
         } else {
 
         } else {
Line 299: Line 307:
 
          
 
          
 
         /* IR "Licht" ~560µs */
 
         /* IR "Licht" ~560µs */
         if (value >= 150  && value <= 200) {
+
         if (value >= 150  &amp;&amp; value &lt;= 200) {
 
             state = DATA_LOW;
 
             state = DATA_LOW;
 
         } else {
 
         } else {
Line 312: Line 320:
 
          
 
          
 
         /* IR "aus lang" 3x~560µs => 1*/
 
         /* IR "aus lang" 3x~560µs => 1*/
         if (value >= 490  && value <= 550) {
+
         if (value >= 490  &amp;&amp; value &lt;= 550) {
 
             state = DATA_HIGH;
 
             state = DATA_HIGH;
 
             uart_printf("1");
 
             uart_printf("1");
 
              
 
              
             byte |= (1<<bit);
+
             byte |= (1&lt;&lt;bit);
 
             bit++;
 
             bit++;
 
             if(bit == 8){
 
             if(bit == 8){
Line 326: Line 334:
 
         }
 
         }
 
         /* IR "aus kurz" ~560µs => 0*/
 
         /* IR "aus kurz" ~560µs => 0*/
         else if (value >= 150  && value <= 200) {
+
         else if (value >= 150  &amp;&amp; value &lt;= 200) {
 
             state = DATA_HIGH;
 
             state = DATA_HIGH;
 
             uart_printf("0");
 
             uart_printf("0");
Line 354: Line 362:
  
 
     /* configure irrx as input */
 
     /* configure irrx as input */
     DDRC &= ~_BV(PC3);
+
     DDRC &amp;= ~_BV(PC3);
  
 
     /* init led pin as output */
 
     /* init led pin as output */
Line 360: Line 368:
  
 
     /* configure ir input pin, with pullup */
 
     /* configure ir input pin, with pullup */
     DDRC &= ~_BV(PC3);
+
     DDRC &amp;= ~_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 &amp; _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 383: Line 391:
 
     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 &amp; _BV(PC3)) {
             PORTD &= ~_BV(PD3);
+
             PORTD &amp;= ~_BV(PD3);
 
         } else {
 
         } else {
 
             PORTD |= _BV(PD3);
 
             PORTD |= _BV(PD3);
Line 397: Line 405:
 
     }
 
     }
 
}
 
}
</source>
+
&lt;/source>
  
 
== '''Abend 6:''' ==
 
== '''Abend 6:''' ==

Revision as of 10:33, 24 November 2010



UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY


CLICK HERE


Teilnehmer:

  • David (der von weit her, FSC Laptop)
  • Vincent (das schwarze Schaf der Apple-Familie)
  • Christian (ASUS Notebook)
  • André (der ohne Beschreibung)


thx für das code hochladen!

Abend 1:

Abend 2:

Binäre Operatoren (einzelne Bits modifizieren):<br /> Memo was <code>DDRC &= ~_BV(PC3)</code> bedeutet:<br /> 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> Programmbeschreibung: LED leuchtet sobald IR-Signal empfangen wird!

IR LED-Blinker mit seriell output <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; } } } } </source> Programmbeschreibung: LED leuchtet sobald IR-Signal empfangen wird und gibt eine Meldung über die serielle Schnittstelle aus!

Abend 3:

<source lang=c>

  1. include <avr/io.h>
  2. include <avr/interrupt.h>
  3. include "uart.h"

/* constants */

  1. define MAX 160

/* 38khz: freq = F_CPU/(2*prescaler*frequency)

* 20mhz/(2*8*38khz) = ~33
* real frequency: 20mhz/(2*8*33) = ~37878Hz */
  1. define PWM_FREQ 33

uint8_t sending_active;

/* enum {

   MODE_IDLE = 0,
   MODE_SENDING = 1,
   MODE_SLEEP = 2,

} mode = MODE_IDLE;

  • /

/* set up timer 0 to generate a carrier using pwm at freq on pin OC0B (PD5) */ static void ir_enable(uint8_t freq) {

   /* timer 0: fast pwm mode, clear OC0B on match, prescaler 8 */
   TCCR0A = _BV(WGM00) | _BV(COM0B1);
   TCCR0B = _BV(CS01) | _BV(WGM02);
   /* set frequency */
   OCR0A = freq;
   /* set duty-cycle to 25% */
   OCR0B = freq/4;

}

/* disable timer 0 and pwm generation */ static void ir_disable(void) {

   TCCR0A = 0;
   TCCR0B = 0;

}


/* pin change interrupt 1 service function */ ISR(PCINT1_vect) {

   /* if this would be the first timing value ever recorded, and the
    * state before was high (=idle), do not record the timing value
    * and just reset the timer */
   
   
           /* store current timer value in code[]
        * and reset the timer */
       //code[pos++] = TCNT1;
       //TCNT1 = 0;
   /* toggle second led */
   PORTD ^= _BV(PD3);
   
   TCNT1 = 0;
   
   /* disable IR interrupt */
   PCMSK1 &= ~_BV(PCINT11);
   /* set global var */
   sending_active = 1;    
   
   ir_enable(PWM_FREQ);
   
   uart_printf("jamming activated\n");

}

/* timer 1 compare A interrupt service function */ ISR(TIMER1_COMPA_vect) {

   TCNT1 = 0;
   if(sending_active) {
       uart_printf("jamming deactivated\n");
       ir_disable();
       sending_active = 0;
       
       /* enable IR interrupt */
       PCMSK1 |= _BV(PCINT11);
   }

}

int main(void) {

   /* initialize uart */
   uart_init();
   uart_printf("rumpus ir-jammer\n");
   /* configure led pins as outputs and turn leds off */
   DDRC |= _BV(PC4);
   DDRD |= _BV(PD3) | _BV(PD6) | _BV(PD7);
   PORTC &= ~_BV(PC4);
   PORTD &= ~(_BV(PD3) | _BV(PD6) | _BV(PD7));
   /* configure ir input pin, with pullup */
   DDRC &= ~_BV(PC3);
   PORTC |= _BV(PC3);
   /* configure ir send pin as output, set low */
   DDRD |= _BV(PD5);
   PORTD &= ~_BV(PD5);
   /* set global var */
   sending_active = 0;
   /* 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 after 200ms: 20mhz/64/5 */
   OCR1A = F_CPU/5/64;
   /* enable OCR1A interrupt */
   TIMSK1 = _BV(OCIE1A);
   /* signal user availability by turning on led 1 */
   PORTC |= _BV(PC4);
   /* enable interrupts */
   sei();
   /* signal the user that the analyzer part has started by turning led 1 on */
   PORTC |= _BV(PC3);
   /* clear interrupt flags, enable timer1 and pin change interrupts */
   TIFR1 = _BV(OCIE1A);
   TIMSK1 |= _BV(OCIE1A);
   PCMSK1 |= _BV(PCINT11);
   while(1) {
   }

} </source>

Abend 4:

Abend 5:

<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; volatile uint8_t byte = 0;

enum {

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

} state;

ISR(PCINT1_vect) {

   if (state == IDLE) {
       state = HEADER_ON;
       TCNT1 = 0;
   } else if (state == HEADER_ON) {
       uint16_t value = TCNT1;
       TCNT1 = 0;
       /* check if header on is ~9ms */
       if (value >= 2500 && value <= 3300) {
           state = HEADER_OFF;
       } else {
           state = IDLE;
           pos = 0;
           bit = 0;
       }
   } else if (state == HEADER_OFF) {
       uint16_t value = TCNT1;
       TCNT1 = 0;
       /* check if header off is ~4.5ms */
       if (value >= 1000 && value <= 1800) {
           state = DATA_HIGH;
       } else {
           state = IDLE;
           pos = 0;
           bit = 0;
       }
   } else if (state == DATA_HIGH) {
       /* INSERT CODE HERE */
       uint16_t value = TCNT1;
       TCNT1 = 0;
       
       /* IR "Licht" ~560µs */
       if (value >= 150  && value <= 200) {
           state = DATA_LOW;
       } else {
           state = IDLE;
           pos = 0;
           bit = 0;
       }
   } else if (state == DATA_LOW){
   
       uint16_t value = TCNT1;
       TCNT1 = 0;
       
       /* IR "aus lang" 3x~560µs => 1*/
       if (value >= 490  && value <= 550) {
           state = DATA_HIGH;
           uart_printf("1");
           
           byte |= (1<<bit);
           bit++;
           if(bit == 8){
               bit = 0;
               data[pos] = byte;
               ++pos;
               byte = 0;
           }
       }
       /* IR "aus kurz" ~560µs => 0*/
       else if (value >= 150  && value <= 200) {
           state = DATA_HIGH;
           uart_printf("0");
           
           bit++;
           if(bit == 8){
               bit = 0;
               data[pos] = byte;
               ++pos;
               byte = 0;
           }        
       } else {
           state = IDLE;
           pos = 0;
           bit = 0;
       }            
   }

}

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 after 200ms: 20mhz/64/5 */
   OCR1A = F_CPU/5/64;
   /* enable OCR1A interrupt */
   //TIMSK1 = _BV(OCIE1A);
   sei();
   state = IDLE;
   while(1) {
       /* if ir rx is high, turn off led */
       if (PINC & _BV(PC3)) {
           PORTD &= ~_BV(PD3);
       } else {
           PORTD |= _BV(PD3);
       }


       if (uart_done == 1) {
           uart_printf("\n%s\n", uart_input);
           uart_len = 0;
           uart_done = 0;
       }
   }

} </source>

Abend 6: