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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-10-21T17:06:34+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=8895&amp;mode</id>
<entry>
<author><name><![CDATA[Lex_]]></name></author>
<updated>2014-10-21T17:06:34+01:00</updated>
<published>2014-10-21T17:06:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100023#p100023</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100023#p100023"/>
<title type="html"><![CDATA[Re: Kod Atmega88 vs Atmega32]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100023#p100023"><![CDATA[
Dziękuję panie Mirku  <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /><br /><br />aby nie być gołosłownym postaram się umieścić gotowy kod - może się komuś przyda.<br /><br />Ku chwale ojczyzny. Pozdrawiam.<br /><br />EDIT:<br />- gotowe - strona logowania / weryfikacji użytkownika do urządzenia działającego w sieci ETHERNET:<br /><br />[syntax=c]/*********************************************<br /> * vim:sw=8:ts=8:si:et<br /> * To use the above modeline in vim you must have &quot;set modeline&quot; in your .vimrc<br /> * Author: Guido Socher<br /><br /> * Edit: LEX 21.10.2014<br /><br /> * Copyright: GPL V2<br /> * See http://www.gnu.org/licenses/gpl.html<br /> *<br /> * Ethernet webserver with reset push button / LOGIN PAGE<br /> *<br /> * Chip type           :  ATMEGA 32 with ENC28J60<br /> * Note: there is a version number in the text. Search for &quot;ver.&quot;<br /> *********************************************/<br />#include &lt;avr/io.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;avr/pgmspace.h&gt;<br />#include &quot;ip_arp_udp_tcp.h&quot;<br />#include &quot;enc28j60.h&quot;<br />#include &quot;timeout.h&quot;<br />#include &quot;net.h&quot;<br />#include &quot;websrv_help_functions.h&quot;<br /><br />// please modify the following two lines. mac and ip have to be unique<br />// in your local area network. You can not have the same numbers in<br />// two devices:<br />// ustalamy adres MAC<br />static uint8_t mymac&#91;6&#93; = {0x54,0x55,0x58,0x10,0x00,0x29};<br />// ustalamy adres IP urządzenia<br />static uint8_t myip&#91;4&#93; = {192,168,0,108};<br />// listen port for tcp/www:<br />static uint16_t mywwwport=80;<br />//<br />// bigger web-pages need a bigger buffer:<br />#define BUFFER_SIZE 450<br />static uint8_t buf&#91;BUFFER_SIZE+1&#93;;<br />static volatile uint8_t stepcounter=0;<br />// global string buffer<br />#define STR_BUFFER_SIZE 24<br />static char strbuf&#91;STR_BUFFER_SIZE+1&#93;;<br />//<br />// the password string (only the first 7 char checked), (only a-z,0-9,_ characters):<br />static char password&#91;10&#93;=&quot;secret&quot;; // must not be longer than 9 char<br /><br />// <br />uint8_t verify_password(char *str)<br />{<br />        // the first characters of the received string are<br />        // a simple password/cookie:<br />        if (strncmp(password,str,strlen(password))==0){<br />                return(1);<br />        }<br />        return(0);<br />}<br /><br />// takes a string of the form co?pw=xxx&amp;rst=1 and analyse it<br />// return values: -1 not the reset page<br />//                -2 no rst command<br />//                -3 valid password<br />//                 1 rst=1 and passpword OK<br />int8_t analyse_get_url(char *str)<br />{<br />        if (strncmp(&quot;co&quot;,str,2)!=0){<br />                return(-1);<br />        }<br />        if (find_key_val(str,strbuf,STR_BUFFER_SIZE,&quot;rst&quot;)){<br />                if (find_key_val(str,strbuf,STR_BUFFER_SIZE,&quot;pw&quot;)){<br />                        urldecode(strbuf);<br />                        if (verify_password(strbuf)==0){<br />                                return(-3);<br />                        }else{<br />                                return(1);<br />                        }<br />                }else{<br />                        return(-3);<br />                }<br />        }<br />        // no rst<br />        return(-2);<br />}<br /><br />// answer HTTP/1.0 301 Moved Permanently\r\nLocation: password/\r\n\r\n<br />// to redirect to the url ending in a slash<br />uint16_t moved_perm(uint8_t *buf)<br />{<br />        uint16_t plen;<br />        plen=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 301 Moved Permanently\r\nLocation: &quot;));<br />        plen=fill_tcp_data(buf,plen,password);<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;/\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;add a trailing slash to the url\n&quot;));<br />        return(plen);<br />}<br /><br /><br />// prepare the webpage by writing the data to the tcp send buffer<br />uint16_t print_webpage(uint8_t *buf)<br />{<br />        uint16_t plen;<br />        plen=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;meta name=viewport content=\&quot;width=device-width\&quot;&gt;\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;h2&gt;reset/reboot button&lt;/h2&gt;\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;form action=/co method=get&gt;&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;\npw: &lt;input type=password name=pw&gt;&lt;input type=hidden name=rst value=1&gt;&lt;input type=submit value=reboot&gt;&lt;/form&gt;&lt;br&gt;\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;hr&gt;ver. 2.16\n&quot;));<br />        return(plen);<br />}<br /><br />uint16_t print_webpage_confirm(uint8_t *buf)<br />{<br />        uint16_t plen;<br />        plen=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;meta name=viewport content=\&quot;width=device-width\&quot;&gt;\n&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;h2&gt;OK&lt;/h2&gt;\nReset executed. &lt;a href=/&gt;&amp;gt;&amp;gt;continue&lt;/a&gt;&lt;br&gt;&lt;hr&gt;\n&quot;));<br />        return(plen);<br />}<br /><br />// timer interrupt, step counter and clear relay when at 2<br />ISR(TIMER1_COMPA_vect){<br />        if (stepcounter&gt;1){<br />                stepcounter=0;<br />                PORTD &amp;= ~(1&lt;&lt;PORTD7);// transistor off<br />        }<br />        if (stepcounter&gt;0){<br />                stepcounter++;<br />        }<br />}<br /><br /><br />// Generate an interrup about ever 1/2s form the 12.5MHz system clock<br />// Since we have that 1024 prescaler we do not really generate a second<br />// (1.00000256000655361677s) <br />void timer_init(void)<br />{<br />        /* write high byte first for 16 bit register access: */<br />        TCNT1H=0;  /* set counter to zero*/<br />        TCNT1L=0;<br />        // Mode 4 table 14-4 page 132. CTC mode and top in OCR1A<br />        // WGM13=0, WGM12=1, WGM11=0, WGM10=0<br />        TCCR1A=(0&lt;&lt;COM1B1)|(0&lt;&lt;COM1B0)|(0&lt;&lt;WGM11);<br />        TCCR1B=(1&lt;&lt;CS12)|(1&lt;&lt;CS10)|(1&lt;&lt;WGM12)|(0&lt;&lt;WGM13); // crystal clock/1024<br /><br />        // divide crystal clock by 16+1:<br />        //ICR1H=0;<br />        //ICR1L=16; // top for counter<br />        // At what value to cause interrupt. You can use this for calibration<br />        // of the clock. Theoretical value for 25MHz: 6103=0x17 and 0xd7<br />        OCR1AH=0x17;<br />        OCR1AL=0xd7;<br />        // interrupt mask bit:<br />        TIMSK = (1&lt;&lt;OCR0);<br />}<br /><br />int main(void){<br /><br />        uint16_t plen;<br />        uint16_t dat_p;<br />        uint8_t i=0;<br />        int8_t cmd;<br />        <br />        // set the clock speed to &quot;no pre-scaler&quot; (8MHz with internal osc or <br />        // full external speed)<br />        // set the clock prescaler. First write CLKPCE to enable setting of clock the<br />        // next four instructions.<br />        //CLKPR=(1&lt;&lt;CLKPCE); // change enable<br />       // CLKPR=0; // &quot;no pre-scaler&quot;<br />       // _delay_loop_1(0); // 60us<br /><br />        /* enable PD2/INT0, as input */<br />        DDRD&amp;= ~(1&lt;&lt;DDD2);<br /><br />        /*initialize enc28j60*/<br />        enc28j60Init(mymac);<br />        //enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz<br />        //_delay_loop_1(0); // 60us<br />        <br />        // LED<br />        /* enable PB1, LED as output */<br />        DDRB|= (1&lt;&lt;DDB1);<br /><br />        /* set output to Vcc, LED off */<br />        PORTB|= (1&lt;&lt;PORTB1);<br /><br />        // the transistor on PD7<br />        DDRD|= (1&lt;&lt;DDD7);<br />        PORTD &amp;= ~(1&lt;&lt;PORTD7);// transistor off<br />        <br />        /* Magjack leds configuration, see enc28j60 datasheet, page 11 */<br />        // LEDB=yellow LEDA=green<br />        //<br />        // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit<br />        // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);<br />        enc28j60PhyWrite(PHLCON,0x476);<br />        _delay_loop_1(0); // 60us<br />        <br />        /* set output to GND, red LED on */<br />        PORTB &amp;= ~(1&lt;&lt;PORTB1);<br />        i=1;<br /><br />        //init the ethernet/ip layer:<br />        init_ip_arp_udp_tcp(mymac,myip,mywwwport);<br />        timer_init();<br /><br />        sei(); // interrupt enable<br /><br />        while(1){<br />                // handle ping and wait for a tcp packet:<br />                dat_p=packetloop_icmp_tcp(buf,enc28j60PacketReceive(BUFFER_SIZE, buf));<br />                /*plen will ne unequal to zero if there is a valid <br />                 * packet (without crc error) */<br />                if(dat_p==0){<br />                        continue;<br />                }<br />                        <br />                if (strncmp(&quot;GET &quot;,(char *)&amp;(buf&#91;dat_p&#93;),4)!=0){<br />                        // head, post and other methods:<br />                        //<br />                        // for possible status codes see:<br />                        // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html<br />                        plen=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n&lt;h1&gt;200 OK&lt;/h1&gt;&quot;));<br />                        goto SENDTCP;<br />                }<br />                if (strncmp(&quot;/ &quot;,(char *)&amp;(buf&#91;dat_p+4&#93;),2)==0){<br />                        plen=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n&quot;));<br />                        plen=print_webpage(buf);<br />                        goto SENDTCP;<br />                }<br />                // we chop off already the leading &quot;/&quot;:<br />                cmd=analyse_get_url((char *)&amp;(buf&#91;dat_p+5&#93;));<br />                // for possible status codes see:<br />                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html<br />                if (cmd==1){<br />                        PORTD|= (1&lt;&lt;PORTD7);// transistor on<br />                        stepcounter=1; // trigger counter to clear transistor 1 sec later<br />                        plen=print_webpage_confirm(buf);<br />                }else{<br />                        plen=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n&lt;h1&gt;401 Unauthorized&lt;/h1&gt;&quot;));<br />                        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;a href=/&gt;&amp;gt;&amp;gt;continue&lt;/a&gt;\n&quot;));<br />                }<br /><br />SENDTCP:<br />                www_server_reply(buf,plen); // send web page data<br />                // udp not implemented<br />        }<br />        return (0);<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2676">Lex_</a> — 21 paź 2014, o 17:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2014-10-21T15:58:26+01:00</updated>
<published>2014-10-21T15:58:26+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100004#p100004</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100004#p100004"/>
<title type="html"><![CDATA[Re: Kod Atmega88 vs Atmega32]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100004#p100004"><![CDATA[
<img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /> pomiń te linie bo po prostu ATmega32 nie posiada takich właściwości - to wszystko<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 21 paź 2014, o 15:58</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Lex_]]></name></author>
<updated>2014-10-21T15:09:07+01:00</updated>
<published>2014-10-21T15:09:07+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100002#p100002</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100002#p100002"/>
<title type="html"><![CDATA[Kod Atmega88 vs Atmega32]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8895&amp;p=100002#p100002"><![CDATA[
Witam<br /><br />Przenoszę kod z atmegi88 na atmegę32 (tuxgraphics.org) i jest tam taka linijka kodu:<br /><br />[syntax=c]// set the clock speed to &quot;no pre-scaler&quot; (8MHz with internal osc or <br />        // full external speed)<br />        // set the clock prescaler. First write CLKPCE to enable setting of clock the<br />        // next four instructions.<br />        CLKPR=(1&lt;&lt;CLKPCE); // change enable PROBLEM :)<br />        CLKPR=0; // &quot;no pre-scaler&quot; PROBLEM :)<br />        _delay_loop_1(0); // 60us[/syntax]<br /><br />Przejrzałem dokumentację atmegi88 i wiem, że jest to rejestr prescalera (System Clock Prescaler).<br />Ale w dokumentacji atmegi32 nic takiego nie znalazłem. <br /><br />Czy to jest zwykłe ustawienie preskalera na 1 (czyli brak) czy jeszcze coś innego?<br /><br />Za każdą pomoc dziękuję.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2676">Lex_</a> — 21 paź 2014, o 15:09</p><hr />
]]></content>
</entry>
</feed>