<?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=50&amp;t=22504&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2019-08-22T21:18:39+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=50&amp;t=22504&amp;mode</id>
<entry>
<author><name><![CDATA[Mario17]]></name></author>
<updated>2019-08-22T21:18:39+01:00</updated>
<published>2019-08-22T21:18:39+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221563#p221563</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221563#p221563"/>
<title type="html"><![CDATA[Re: AVR C++ klasy i przerwania]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221563#p221563"><![CDATA[
Dioda nie miga dlatego że w tym momencie wskaźnik pTimer jest równy 0 i gdy odnosisz się do zmiennej led_flag przez Timer::pTimer-&gt;led_flag program próbuje odwołać się do zmiennej pod adresem 0. Musisz jeszcze zaincjalizować wskaźnik pTimer np w konstruktorze klasy wskaźnikiem this.<br />[syntax=cpp]Timer::Timer()<br />        : led_flag(false)<br />{<br />        pTimer = this;<br />        TCCR2A |= (1 &lt;&lt; WGM21);<br />        TCCR2B |= (1 &lt;&lt; CS22);<br />        OCR2A = 249;<br />        TIMSK2 |= (1 &lt;&lt; OCIE2A);<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3695">Mario17</a> — 22 sie 2019, o 21:18</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[lukaszc27]]></name></author>
<updated>2019-08-22T07:26:41+01:00</updated>
<published>2019-08-22T07:26:41+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221544#p221544</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221544#p221544"/>
<title type="html"><![CDATA[Re: AVR C++ klasy i przerwania]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221544#p221544"><![CDATA[
A możesz mi podać przykład jak to dokładnie zrobić bo nie bardzo rozumiem. Zadeklarowałem tą zmienną na zewnątrz klasy. w Klasie sekcje protected zmieniłem na public ale jednak dalej nie działa. Program kompiluje się prawidłowo, ale dioda nie miga.<br /><br />[syntax=cpp]Timer* Timer::pTimer;<br />void TIMER2_COMPA_vect(void)<br />{<br />static int c;<br />if (++c &gt; 200) {<br />c = 0;<br />Timer::pTimer-&gt;led_flag = true;<br />}<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=10175">lukaszc27</a> — 22 sie 2019, o 07:26</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Mario17]]></name></author>
<updated>2019-08-21T21:43:38+01:00</updated>
<published>2019-08-21T21:43:38+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221530#p221530</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221530#p221530"/>
<title type="html"><![CDATA[Re: AVR C++ klasy i przerwania]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221530#p221530"><![CDATA[
Zmienna statyczna musi być zdefiniowana na zewnątrz klasy i nie może być protected jak chcesz się odnieść do niej poza klasą. <br />[syntax=cpp]Timer* Timer::pTimer;[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3695">Mario17</a> — 21 sie 2019, o 21:43</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[lukaszc27]]></name></author>
<updated>2019-08-21T19:39:30+01:00</updated>
<published>2019-08-21T19:39:30+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221507#p221507</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221507#p221507"/>
<title type="html"><![CDATA[AVR C++ klasy i przerwania]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=22504&amp;p=221507#p221507"><![CDATA[
Witam!<br />Od pewnego czasu próbuję przejść z programowania AVR w czystym C do C++ (głównie chodzi o wzbogacenie się o klasy których mi brakuje) i mam problem z połączeniem klas i przerwań.<br /><br />Mam tu taki prosty program który powinien migać diodą led podłączoną do pinu PD7 a jednak nic się nie dzieje.<br />Programuję ATmega328P taktowana wewnętrznie 8MHz.<br /><br />[syntax=cpp]#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br />//#include &quot;libs/serial/serial.hpp&quot;<br /><br />extern &quot;C&quot; void TIMER2_COMPA_vect(void) __attribute__ ((signal));<br /><br />class Timer<br />{<br />public:<br />Timer();<br /><br />void update();<br />friend void TIMER2_COMPA_vect(void);<br /><br />protected:<br />volatile bool led_flag;<br />static Timer* pTimer;<br />};<br /><br />int main(void)<br />{<br />Timer timer;<br />DDRD |= (1 &lt;&lt; PD7);<br /><br />sei();<br />while (true)<br />{<br />timer.update();<br />}<br />return 0;<br />}<br /><br /><br />Timer::Timer()<br />: led_flag(false)<br />{<br />TCCR2A |= (1 &lt;&lt; WGM21);<br />TCCR2B |= (1 &lt;&lt; CS22);<br />OCR2A = 249;<br />TIMSK2 |= (1 &lt;&lt; OCIE2A);<br />}<br /><br />void Timer::update()<br />{<br />if (led_flag) {<br />PORTD ^= (1 &lt;&lt; PD7);<br />led_flag = false;<br />}<br />}<br /><br />void TIMER2_COMPA_vect(void)<br />{<br />static int c;<br />if (++c &gt; 200) {<br />c = 0;<br />Timer::pTimer-&gt;led_flag = true;<br />}<br />}[/syntax]<br /><br />Kompilacja pokazuje mi takie błędy:<br />[syntax=c]make all <br />Building file: ../main.cpp<br />Invoking: AVR C++ Compiler<br />avr-g++ -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -funsigned-char -funsigned-bitfields -fno-exceptions -mmcu=atmega328p -DF_CPU=8000000UL -MMD -MP -MF&quot;main.d&quot; -MT&quot;main.o&quot; -c -o &quot;main.o&quot; &quot;../main.cpp&quot;<br />Finished building: ../main.cpp<br /> <br />Building target: AVR-Cpp.elf<br />Invoking: AVR C++ Linker<br />avr-g++ -Wl,-Map,AVR-Cpp.map,--cref -mrelax -Wl,--gc-sections -mmcu=atmega328p -o &quot;AVR-Cpp.elf&quot;  ./libs/serial/serial.o  ./main.o   <br />./main.o: In function `__vector_7':<br />main.cpp:(.text.__vector_7+0x36): undefined reference to `Timer::pTimer'<br />main.cpp:(.text.__vector_7+0x3a): undefined reference to `Timer::pTimer'<br />collect2: error: ld returned 1 exit status<br />make: *** &#91;AVR-Cpp.elf&#93; Error 1<br />makefile:66: recipe for target 'AVR-Cpp.elf' failed<br /><br />20:32:56 Build Failed. 2 errors, 0 warnings. (took 118ms)[/syntax]<br /><br />Z góry dziękuję za pomoc w rozwiązaniu problemu.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=10175">lukaszc27</a> — 21 sie 2019, o 19:39</p><hr />
]]></content>
</entry>
</feed>