<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=22461&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2019-08-04T19:38:41+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=22461&amp;mode</id>
<entry>
<author><name><![CDATA[danny]]></name></author>
<updated>2019-08-04T19:38:41+01:00</updated>
<published>2019-08-04T19:38:41+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=22461&amp;p=220975#p220975</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=22461&amp;p=220975#p220975"/>
<title type="html"><![CDATA[Biblioteka pilot IR kodowanie NEC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=22461&amp;p=220975#p220975"><![CDATA[
Szanowni Koledzy,<br /><br />Pytanie dotyczy biblioteki z wątku <a href="https://forum.atnel.pl/topic10813.html"  class="postlink">https://forum.atnel.pl/topic10813.html</a><br /><br />Jako, że w/g tego:<br /><br /><a href="https://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol"  class="postlink">https://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol</a><br /><br />Nec koduje dane od LSB, więc ramkę z załącznika powinien odczytywać:<br /><br />address 0x04; command 0x72<br /><br />Natomiast w/g biblioteki zamieszczonej w tym wątku, odczytywane jest:<br /><br />address 0x20, command 0x4E<br /><br /><a href="https://obrazkiforum.atnel.pl/1505/5e9da30a4555026b052ac589f2e3642e.jpg"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/1505/5e9da30a4555026b052ac589f2e3642e.jpg" alt="Obrazek" /></a><br /><br /><br />Tak więc proszę o sprawdzenie czy moje rozumowanie jest poprawne i czy poniższe zmiany w kodzie są ok:<br /><br />nec.c<br />[syntax=c]#include &lt;avr/io.h&gt;<br />    #include &lt;avr/interrupt.h&gt;<br />     <br />    #include &quot;nec.h&quot;<br />     <br />    //volatile uint8_t frame_ready;<br />     <br />    volatile uint8_t address;<br />    volatile uint8_t command;<br />    volatile uint8_t Ir_key_press_flag;<br />    volatile uint8_t rep;// ilość powtórzeń ramki przy wciąż wciśniętym klawiszu - autorepeat<br />    // wskaźnik do funkcji callback dla zdarzenia IR_EVENT<br />    static void (*ir_event_callback)(uint8_t address, uint8_t command);<br />     <br />    // funkcja do rejestracji funkcji zwrotnej w zdarzeniu IR_EVENT()<br />    void register_ir_event_callback(<br />                    void (*callback)(uint8_t address, uint8_t command)) {<br />            ir_event_callback = callback;<br />    }<br />     <br />    // Zdarzenie do obsługi podczerwieni, następuje w nim wykrycie ustawionej flagi<br />    // oraz jej automatyczne kasowanie, łącznie ze skasowaniem wartości command i address do 0xff<br />    // użytkownik nie musi za każdym razem pamiętać o kasowaniu flagi czy wpisywaniu warunku if<br />    void IR_EVENT(void) {<br />     <br />            if (Ir_key_press_flag) {<br />     <br />                    // wywołanie własnej funkcji obsługi użytkownika jeśli<br />                    // uprzednio została ona zarejestrowana<br />     <br />                    if (ir_event_callback)<br />                            (*ir_event_callback)(address, command);<br />     <br />                    address = 0xff;<br />                    command = 0xff;<br />                    Ir_key_press_flag = 0;<br />            }<br />    }<br />     <br />    void ir_init(void) {<br />    //      DDRD &amp;=~(1&lt;&lt;PD6);<br />            IR_PORT |= (1 &lt;&lt; IR_PIN); /* podciągnięcie wejścia IR */<br />            // KONFIGURACJA PRACY PRZERWANIA ICP I TIMERA1<br />     <br />            TCCR1B |= (1 &lt;&lt; CS11); /* prescaler = 8 */<br />    //     TCCR1B &amp;= ~(1&lt;&lt;ICES1);  /* falling edge */<br />            TIMSK |= (1 &lt;&lt; TICIE1); /* enable interrupt */<br />    }<br />     <br />    ISR(TIMER1_CAPT_vect) {<br />            static uint32_t temp_frame;<br />            static uint16_t last_icr;<br />            uint16_t width;<br />    //        static uint8_t frame_idx = 33;<br />            static uint8_t frame_idx = 0;<br />     <br />            uint8_t bit = 2;<br />     <br />            width = ICR1 - last_icr;<br />            last_icr = ICR1;<br />     <br />            if (!frame_idx &amp;&amp; width &gt; F_START - F_OFFSET &amp;&amp; width &lt; F_START + F_OFFSET)     //frame_idx == 33<br />            // &gt; 27000 - 800 = 26200 i &lt; 27800<br />            {<br />    //            frame_idx--;<br />     <br />                    frame_idx++;<br />            }<br />     <br />    //              if(frame_idx &lt; 32)<br />            if (frame_idx &gt; 1)<br />     <br />            {<br />     <br />                    if (width &gt; F_ONE - F_OFFSET &amp;&amp; width &lt; F_ONE + F_OFFSET)<br />                            bit = 1;<br />                    // &gt; 3700 i &lt; 5300<br />                    if (width &gt; F_ZERO - F_OFFSET &amp;&amp; width &lt; F_ZERO + F_OFFSET)<br />                            bit = 0;<br />                    // &gt; 2250 - 800 = 900 i &lt; 3050<br />     <br />                    if (bit != 2) {<br />                            temp_frame |= (uint32_t) bit &lt;&lt; (frame_idx - 2);//frame_idx;<br />     <br />    //                                              if(frame_idx == 0)<br />                            if (frame_idx == 33)<br />     <br />                            {<br />    //                                address = (uint8_t)(temp_frame &gt;&gt; 24);<br />                                    address = (uint8_t) (temp_frame);<br />     <br />    //                                command = (uint8_t)(temp_frame &gt;&gt; 8);<br />                                    command = (uint8_t) (temp_frame &gt;&gt; 16);<br />     <br />                                    temp_frame = 0;<br />    //                                frame_idx = 33;<br />                                    frame_idx = 0;<br />     <br />    //                                frame_ready = 1;<br />     <br />                                    Ir_key_press_flag = 1;<br />                            } else {<br />    //                                frame_idx--;<br />                                    frame_idx++;<br />     <br />                            }<br />                    } else {<br />    //                        frame_idx = 33;<br />                            frame_idx = 0;<br />     <br />                    }<br />            }<br />     <br />    //              if(frame_idx == 32) frame_idx--;<br />            if (frame_idx == 1)<br />                    frame_idx++;<br />     <br />    }[/syntax]<br /><br />nec.h<br />[syntax=c]#ifndef NEC_H<br />    #define NEC_H<br />     <br />    //długości &#91;ms&#93;:<br />    // http://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol<br />     <br />    #define HEADER  13.5    //9ms + 4,5ms przerwa<br />    #define ZERO    1.125   //562,5us + 562,5us przerwa<br />    #define ONE             2.25    //562,5us + 1,6875ms przerwa<br />    #define REPEAT  11.25   //co 108ms 9ms + 2.25ms<br />    #define OFFSET  0.4<br />     <br />     <br />    #define F_START         F_CPU/8000*HEADER<br />    #define F_ONE           F_CPU/8000*ONE<br />    #define F_ZERO          F_CPU/8000*ZERO<br />    #define F_REPEAT        F_CPU/8000*REPEAT<br />    #define F_OFFSET        F_CPU/8000*OFFSET<br />     <br />     <br />     <br />    #define IR_PIN PD6                      // numer pinu wejścia ICP<br />    #define IR_DIR DDRD<br />    #define IR_PORT PORTD<br />     <br />     <br />    //kody pilota do TV LG AKB73715679<br />     <br />    #define LG_ADDRESS      0x04<br />     <br />    #define STOP            0xB1<br />    #define RWD                     0x8F<br />    #define PLAY            0xB0<br />    #define FF                      0x8E<br />    #define PAUSE           0xBA<br />    #define RED                     0x72<br />    #define GREEN           0x71<br />    #define YELLOW          0x63<br />    #define BLUE            0x61<br />     <br />    //#define REC           0xBD<br />    //#define AVMODE        0x30<br />    //#define EXIT          0x5B<br />    //#define BACK          0x28<br />    //#define OK            0x44<br />    //#define QMENU         0x45<br />    //#define SETTINGS      0x43<br />    //#define TEXT          0x20<br />    //#define INFO          0xAA<br />    //#define TOPT          0x21<br />    //#define MUTE          0x09<br />    //#define GUIDE         0xAB<br />    //#define FAV           0x1E<br />    //#define VOL+          0x02<br />    //#define VOL-          0x03<br />    //#define P+            0x00<br />    //#define P-            0x01<br />    //#define LIST          0x53<br />    //#define QVIEW         0x1A<br />    //#define 0                     0x10<br />    //#define 1                     0x11<br />    //#define 2                     0x12<br />    //#define 3                     0x13<br />    //#define 4                     0x14<br />    //#define 5                     0x15<br />    //#define 6                     0x16<br />    //#define 7                     0x17<br />    //#define 8                     0x18<br />    //#define 9                     0x19<br />    //#define SUBTITLE      0x39<br />    //#define AD            0x91<br />    //#define RATIO         0x79<br />    //#define INPUT         0x0B<br />    //#define TV-RADIO      0xF0<br />    //#define ON-OFF        0x08<br />    #define LEFT            0x07<br />    #define RIGHT           0x06<br />    #define IR_UP           0x40<br />    #define IR_DOWN         0x41<br />     <br />     <br />     <br />     <br />    void ir_init();<br />     <br />    void IR_EVENT(void);<br />     <br />    void register_ir_event_callback(void (*callback)(uint8_t address,<br />                                    uint8_t command));<br />    #endif[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1505">danny</a> — 4 sie 2019, o 19:38</p><hr />
]]></content>
</entry>
</feed>