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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-03-28T14:55:47+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=11201&amp;mode</id>
<entry>
<author><name><![CDATA[faber33]]></name></author>
<updated>2015-03-28T14:55:47+01:00</updated>
<published>2015-03-28T14:55:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124872#p124872</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124872#p124872"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124872#p124872"><![CDATA[
Po ciężkich bojach udało mi się uzyskać w miarę dobry efekt. <br /><br />[syntax=c]void sprawdz_opto(void){<br />uint8_t raz;<br />Timer2=30;<br /><br />   do{<br />  raz=0;<br />    if(!Timer2){<br />         Timer2=30;<br />          if(!OPTO1_ON &amp;&amp; OPTO2_ON){<br />          zmienna1--;<br />          raz=1;<br />          clear_line(0);<br />          clear_line(1);<br />          menu_element=4;<br />          }<br />    }<br /><br />    }while(!OPTO1_ON &amp;&amp; OPTO2_ON &amp;&amp; menu_element==3 &amp;&amp; raz==0);<br /><br />  do{<br />raz=0;<br />    if(!Timer2){<br />         Timer2=60;<br />          if(OPTO1_ON &amp;&amp; !OPTO2_ON){<br />         zmienna1--;<br />         raz=1;<br />         clear_line(0);<br />         clear_line(1);<br />         menu_element=3;<br />          }<br />    }<br /><br />}while(OPTO1_ON &amp;&amp; !OPTO2_ON &amp;&amp; menu_element==4 &amp;&amp; raz==0);<br /><br />}[/syntax]<br /><br />Wszystko fajnie tylko problem w tym, że chciałbym teraz usunąć zależność od menu_element i dekrementować tylko zmienna1. Problem w tym że zmienna &quot;raz&quot; przestaje blokować, kolejne dekrementacje zmiennej <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /><br /><br />[syntax=c]void sprawdz_opto(void){<br />uint8_t raz;<br />Timer2=30;<br /><br />   do{<br />   raz=0;<br />    if(!Timer2){<br />         Timer2=30;<br />          if(!OPTO1_ON &amp;&amp; OPTO2_ON){<br />          zmienna1--;<br />          raz=1;<br />          }<br />    }<br /><br />    }while(!OPTO1_ON &amp;&amp; OPTO2_ON &amp;&amp; raz==0);<br /><br /><br />   Timer2=30;<br /><br />   do{<br />   raz=0;<br />    if(!Timer2){<br />         Timer2=30;<br />          if(OPTO1_ON &amp;&amp; !OPTO2_ON){<br />          zmienna1--;<br />          raz=1;<br />          }<br />    }<br /><br />    }while(OPTO1_ON &amp;&amp; !OPTO2_ON &amp;&amp; raz==0);<br /><br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=976">faber33</a> — 28 mar 2015, o 14:55</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Lex_]]></name></author>
<updated>2015-03-27T21:06:38+01:00</updated>
<published>2015-03-27T21:06:38+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124823#p124823</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124823#p124823"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124823#p124823"><![CDATA[
Więc inaczej, jeśli którykolwiek warunek się spełni, reszta nie jest sprawdzana - w sumie tak chciałem od początku źle popatrzyłem w kod:<br /><br />[syntax=c]void sprawdz_opto(void){<br />    if(menu_element ==3 &amp;&amp; OPTO1_ON &amp;&amp; !OPTO2_ON){<br />        clear_line(0);<br />        clear_line(1);<br /> <br />    }<br /> <br />    else if(menu_element ==4 &amp;&amp; OPTO2_ON &amp;&amp; !OPTO1_ON){<br />        clear_line(0);<br />        clear_line(1);<br /> <br />    }<br /> <br /> <br /> <br />        else if(OPTO1_ON &amp;&amp; !OPTO2_ON ){<br /> <br />                if(!Timer2){<br />               <br />                Timer2=20;<br />                menu_element=2;<br />                }<br />        }<br /> <br />        else if(!OPTO1_ON &amp;&amp; OPTO2_ON){<br /> <br />                if(!Timer2){<br />                Timer2=20;<br />                menu_element=1;<br />                }<br />        }<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2676">Lex_</a> — 27 mar 2015, o 21:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[faber33]]></name></author>
<updated>2015-03-27T20:25:34+01:00</updated>
<published>2015-03-27T20:25:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124815#p124815</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124815#p124815"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124815#p124815"><![CDATA[
Timer działa sprawdzałem już na wiele sposobów na LEDach więc nie w tym problem tylko zapewne w warunkach :/<br /><br />Jeszcze jedna sprawa: Jak napisać warunek, żeby po jego spełnieniu instrukcja była wykonywana tylko raz ???<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=976">faber33</a> — 27 mar 2015, o 20:25</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[matekogon]]></name></author>
<updated>2015-03-27T20:02:14+01:00</updated>
<published>2015-03-27T20:02:14+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124813#p124813</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124813#p124813"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124813#p124813"><![CDATA[
czy timer2 nie powinien być  volatile uint8_t timer2;<br /><br />a tak na marginesie ja robię tak timer programowy<br />[syntax=c]ISR(TIMER0_COMP_vect){    // przerwanie od timera0<br /><br />// programowe timery<br />if (!(tyk%1))flaga_10ms=1;// odmierza odcinik 10ms<br />if (!(tyk%10))flaga_100ms=1;// odcinek 100ms modulo reszta z dzielenia wyznacznikiem<br />if (!(tyk%50))flaga_500ms=1;<br />if (!(tyk%100)){<br />flaga_1s=1;<br />tyk=0;<br />}<br /> tyk++;<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1380">matekogon</a> — 27 mar 2015, o 20:02</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[faber33]]></name></author>
<updated>2015-03-27T19:54:04+01:00</updated>
<published>2015-03-27T19:54:04+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124811#p124811</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124811#p124811"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124811#p124811"><![CDATA[
Nie pomogło. Na początku działa jakby bez opóźnienia. A następnie napisy czasem przygasają i napis przyłącza się jakby losowo :/<br /><br /><br />PS. Poza tematem trochę. Dodałem jeszcze czyszczenie linii wyświetlacza i ono działa ok.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=976">faber33</a> — 27 mar 2015, o 19:54</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Lex_]]></name></author>
<updated>2015-03-27T19:42:44+01:00</updated>
<published>2015-03-27T19:42:44+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124810#p124810</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124810#p124810"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124810#p124810"><![CDATA[
Dodałem else if, sprawdź.<br /><br />[syntax=c]void sprawdz_opto(void){<br />            if(OPTO1_ON &amp;&amp; !OPTO2_ON ){<br />     <br />                    if(!Timer2){<br />                   <br />                    Timer2=20;<br />                    menu_element=2;<br />                    }<br />            }<br />     <br />           else if(!OPTO1_ON &amp;&amp; OPTO2_ON){<br />     <br />                    if(!Timer2){<br />                    Timer2=20;<br />                    menu_element=1;<br />                    }<br />            }<br />    }[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2676">Lex_</a> — 27 mar 2015, o 19:42</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[faber33]]></name></author>
<updated>2015-03-27T19:06:23+01:00</updated>
<published>2015-03-27T19:06:23+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124806#p124806</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124806#p124806"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124806#p124806"><![CDATA[
Poprawione ale to nic nie zmieniło dalej nie mam tego efektu który chce<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=976">faber33</a> — 27 mar 2015, o 19:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[matekogon]]></name></author>
<updated>2015-03-27T18:56:13+01:00</updated>
<published>2015-03-27T18:56:13+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124804#p124804</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124804#p124804"/>
<title type="html"><![CDATA[Re: Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124804#p124804"><![CDATA[
coś nie tak z tymi nawiasami  { } masz w kodzie<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1380">matekogon</a> — 27 mar 2015, o 18:56</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[faber33]]></name></author>
<updated>2015-03-27T19:51:44+01:00</updated>
<published>2015-03-27T18:38:54+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124801#p124801</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124801#p124801"/>
<title type="html"><![CDATA[Timer programowy]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11201&amp;p=124801#p124801"><![CDATA[
Witam. Realizuje właśnie pewne urządzenie. Problem jest mianowicie taki, że potrzebuje wprowadzić nieduże opóźnienie instrukcji wykonywanej w warunkach:<br /><br />[syntax=c]void sprawdz_opto(void){<br />    if(menu_element ==3 &amp;&amp; OPTO1_ON &amp;&amp; !OPTO2_ON){<br />    clear_line(0);<br />    clear_line(1);<br /><br />    }<br /><br />    if(menu_element ==4 &amp;&amp; OPTO2_ON &amp;&amp; !OPTO1_ON){<br />    clear_line(0);<br />    clear_line(1);<br /><br />    }<br />if(OPTO1_ON &amp;&amp; !OPTO2_ON ){<br /><br />if(!Timer2){<br />                <br />Timer2=20;<br />menu_element=2;<br />}<br />}<br /><br />if(!OPTO1_ON &amp;&amp; OPTO2_ON){<br /><br />if(!Timer2){<br />Timer2=20;<br />menu_element=1;<br />}<br />}<br />}[/syntax]<br /><br />Np. przypisanie do menu_element wartości 2 powinno nastąpić po spełnieniu warunku if(OPTO1_ON &amp;&amp; !OPTO2_ON ) i upływie 200ms. Niestety nie mogę sobie z tym poradzić. Jeśli ktoś mógłby podpowiedzieć byłbym wdzięczny.<br /><br /><br /><br />Cały kod:<br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;avr/pgmspace.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &quot;LCD/lcd44780.h&quot;<br /><br /><br />#define OPTO1 (1&lt;&lt;PB4) <br />#define OPTO2 (1&lt;&lt;PB3) <br />#define OPTO1_ON !(PINB &amp; OPTO1)<br />#define OPTO2_ON !(PINB &amp; OPTO2) <br /><br />void sprawdz_opto(void);<br /><br />uint8_t menu_element = 0;<br /><br /><br />int main( void ) {<br /><br />DDRB &amp;= ~OPTO1|~OPTO2;<br /><br />// timer0 - konfig<br />TCCR0 |= (1&lt;&lt;CS02)|(1&lt;&lt;CS00); //prescaler = 1024<br />TIMSK |= (1&lt;&lt;TOIE0); // zezwolenie na przerwanie OVF<br />TCNT0 = 256-78; // częstotliwość przerwania 100 Hz<br /><br />sei();<br /><br />    while(1) {<br />                         menu(menu_element);  <br /><br />                         sprawdz_opto();<br />        }<br /><br /><br /><br /><br />ISR( TIMER0_OVF_vect ) {<br /><br />uint16_t n;<br /><br />n = Timer1;<br />if(n) Timer1=--n;<br /><br />n = Timer2;<br />if(n) Timer2=--n;<br /><br />}<br /><br /><br /><br />void menu(uint8_t element)<br />{<br /><br />        switch(element)<br />        {<br />        case 0:<br />            lcd_locate(0,1);<br />           lcd_str(&quot;Wprowadz temp:&quot;);<br />    break;<br /><br />        case 1:<br /><br />                lcd_locate(0,1);<br />                lcd_str(&quot;Liczba&quot;);<br />                break;<br />}<br /><br /><br />void clear_line( uint8_t line ) {<br /><br />   uint8_t i;<br />   lcd_locate( line, 0 );<br />   for( i=0; i&lt;16; i++) lcd_char(' ');<br /><br />}<br /><br /><br /><br />void sprawdz_opto(void){<br />    if(menu_element ==3 &amp;&amp; OPTO1_ON &amp;&amp; !OPTO2_ON){<br />    clear_line(0);<br />    clear_line(1);<br /><br />    }<br /><br />    if(menu_element ==4 &amp;&amp; OPTO2_ON &amp;&amp; !OPTO1_ON){<br />    clear_line(0);<br />    clear_line(1);<br /><br />    }<br /><br /><br /><br />if(OPTO1_ON &amp;&amp; !OPTO2_ON ){<br /><br />if(!Timer2){<br />                <br />Timer2=20;<br />menu_element=2;<br />}<br />}<br /><br />if(!OPTO1_ON &amp;&amp; OPTO2_ON){<br /><br />if(!Timer2){<br />Timer2=20;<br />menu_element=1;<br />}<br />}<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=976">faber33</a> — 27 mar 2015, o 18:38</p><hr />
]]></content>
</entry>
</feed>