hallo muraad, dieses demo sendet 2 zahlen (10,20), es soll ja gemäss aussage 8 zahlen senden können. wie kann man es ändern, das es ein byte (8bit) sendet die man dann empfnagen kann. er hat dort 2x timecount in einem bereich von-bis abgefragt. wie weit geht eigentlich die von-bis abfrage wenn ich z.b. 8 byte abfragen kann und wie könnte man das nutzen für 8 bit.
mfg pebisoft
Code:/* IR-Routine: Es werden unterschiedlich lange Impulse gesendet und vom Empfänger ausgewertet. Exemplarisch werden 10 verschiedene Längen implementiert, wovon jeder dann als Befehl betrachtet werden kann. Dies ist zunächst die trivialste Variante, reicht aber für einfach Fernsteuerungen aus. Variation von pulse: 10 ... 20 ... 30 ...... 100*/ #include <avr/io.h> #include <avr/signal.h> #include <avr/interrupt.h> #include <lcd.c> //#define send #define receive #ifdef send volatile unsigned char empty = 0; volatile unsigned char pulse = 0; SIGNAL (SIG_OVERFLOW0) { if (pulse) { DDRB |= (1<<PB1); empty = 1; pulse--; } if (!pulse) { empty = 0; DDRB &= ~(1<<PB1); } } void ir_init_send (void) { //36kHz Träger TCCR1A = (1<<COM1A1) | (1<<COM1A0) | (1<<WGM11); TCCR1B = (1<<WGM12) | (1<<WGM13) | (1<<CS10); OCR1A = 111; ICR1 = 222; //Timer-Interrupt alle 2,048ms zur Signalerzeugung --> 1/(8MHz/256/64) TCCR0 = (1<<CS01) | (1<<CS00); //Prescaler von 64 TIMSK |= (1<<TOIE0); //Timer0 Overflow Interrupt aktivieren } void ir_send (unsigned char byte) { //Senderoutine if (!empty) pulse = byte; } #endif #ifdef receive volatile unsigned short timecount = 0; volatile unsigned char empty = 0; volatile unsigned char rec_byte = 0; SIGNAL (SIG_OVERFLOW0) { //-----<allgemein>------- if (!(PINB & (1<<PB0))) { //Low-Pegel = log. 1 am Sender timecount++; empty = 1; } else { empty = 0; } if ((!empty) && (timecount)) { //-----<Auswertung>------ //8fache Abtastung if ((timecount > 70) && (timecount < 90)) { //pulse war 10 rec_byte = 10; } if ((timecount > 150) && (timecount < 170)) { //pulse war 20 rec_byte = 20; } timecount = 0; } } void ir_init_receive (void) { //Abtastung realisieren //Timer-Interrupt alle 0,256ms zum Signalempfang --> 1/(8MHz/256/8) TCCR0 |= (1<<CS01); //Prescaler von 8 TIMSK |= (1<<TOIE0); //Timer0 Overflow Interrupt aktivieren lcd_init (LCD_DISP_ON); } unsigned char ir_receive (void) { //Empfangsroutine return rec_byte; } #endif int main (void) { #ifdef send ir_init_send (); DDRC &= ~(1<<PC5); #endif #ifdef receive ir_init_receive (); #endif sei (); for (;;) { #ifdef send if (!(PINC & (1<<PC5))) { delay (65000); //Entprellung ir_send (10); } if (!(PINC & (1<<PC4))) { delay (65000); //Entprellung ir_send (20); } #endif #ifdef receive if (rec_byte) { lcd_gotoxy (0,0); if (rec_byte == 10) lcd_puts ("10"); if (rec_byte == 20) lcd_puts ("20"); } #endif } return 0; }







Zitieren

Lesezeichen