久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: STM32 ENC28J60調試通過的源程序 [打印本頁]

作者: 251354715    時間: 2020-8-1 22:38
標題: STM32 ENC28J60調試通過的源程序
  1. #include "main.h"

  2. static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
  3. static uint8_t myip[4] = {192,168,0,24};
  4. #define MYWWWPORT 80
  5. #define MYUDPPORT 1200
  6. #define BUFFER_SIZE 550
  7. static volatile ErrorStatus HSEStartUpStatus = SUCCESS;
  8. static vu32 TimingDelay = 0;
  9. static uint8_t buf[BUFFER_SIZE+1];
  10. static char password[]="secret";



  11. /*u16 fill_tcp_data_p(char *buf,u16 pos, u8 *progmem_s)
  12. {
  13.         char c;
  14.         // fill in tcp data at position pos
  15.         //
  16.         // with no options the data starts after the checksum + 2 more bytes (urgent ptr)
  17.         while ((c = *(progmem_s++))) {
  18.                 buf[TCP_CHECKSUM_L_P+3+pos]=c;
  19.                 pos++;
  20.         }
  21.         return(pos);
  22. }*/

  23. char strncmp ( char * s1, char * s2, char n)
  24. {
  25.   if ( !n )//n為無符號整形變量;如果n為0,則返回0
  26.   return(0);
  27.   
  28.   while (--n && *s1 && *s1 == *s2)
  29.   {
  30.     s1++;//S1指針自加1,指向下一個字符
  31.     s2++;//S2指針自加1,指向下一個字符

  32.   }
  33.   return( *s1 - *s2 );//返回比較結果
  34. }

  35. uint8_t verify_password(char *str)
  36. {
  37.         // the first characters of the received string are
  38.         // a simple password/cookie:
  39.         if (strncmp(password,str,5)==0){
  40.                 return(1);
  41.         }
  42.         return(0);
  43. }


  44. // takes a string of the form password/commandNumber and analyse it
  45. // return values: -1 invalid password, otherwise command number
  46. //                -2 no command given but password valid
  47. //                -3 valid password, no command and no trailing "/"
  48. int8_t analyse_get_url(char *str)
  49. {
  50.         uint8_t loop=1;
  51.         uint8_t i=0;
  52.         while(loop){
  53.                 if(password[i]){
  54.                         if(*str==password[i]){
  55.                                 str++;
  56.                                 i++;
  57.                         }else{
  58.                                 return(-1);
  59.                         }
  60.                 }else{
  61.                         // end of password
  62.                         loop=0;
  63.                 }
  64.         }
  65.         // is is now one char after the password
  66.         if (*str == '/'){
  67.                 str++;
  68.         }else{
  69.                 return(-3);
  70.         }
  71.         // check the first char, garbage after this is ignored (including a slash)
  72.         if (*str < 0x3a && *str > 0x2f){
  73.                 // is a ASCII number, return it
  74.                 return(*str-0x30);
  75.         }
  76.         return(-2);
  77. }

  78. // answer HTTP/1.0 301 Moved Permanently\r\nLocation: password/\r\n\r\n
  79. // to redirect to the url ending in a slash
  80. uint16_t moved_perm(uint8_t *buf)
  81. {
  82.         uint16_t plen;
  83.         plen=fill_tcp_data_p(buf,0,"HTTP/1.0 301 Moved Permanently\r\nLocation: ");
  84.         plen=fill_tcp_data(buf,plen,password);
  85.         plen=fill_tcp_data_p(buf,plen,"/\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n");
  86.         plen=fill_tcp_data_p(buf,plen,"<h1>301 Moved Permanently</h1>\n");
  87.         plen=fill_tcp_data_p(buf,plen,"add a trailing slash to the url\n");
  88.         return(plen);
  89. }


  90. // prepare the webpage by writing the data to the tcp send buffer
  91. uint16_t print_webpage(uint8_t *buf,uint8_t on_off)
  92. {
  93.         uint16_t plen;
  94.         plen=fill_tcp_data_p(buf,0,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n");
  95.         plen=fill_tcp_data_p(buf,plen,"<center><p>Output is: ");
  96.         if (on_off){
  97.                 plen=fill_tcp_data_p(buf,plen,"<font color=\"#00FF00\"> ON</font>");
  98.         }else{
  99.                 plen=fill_tcp_data_p(buf,plen,"OFF");
  100.         }
  101.         plen=fill_tcp_data_p(buf,plen," <small><a href=\".\">[refresh status]</a></small></p>\n<p><a href=\".");
  102.         if (on_off){
  103.                 plen=fill_tcp_data_p(buf,plen,"/0\">Switch off</a><p>");
  104.         }else{
  105.                 plen=fill_tcp_data_p(buf,plen,"/1\">Switch on</a><p>");
  106.         }
  107.         plen=fill_tcp_data_p(buf,plen,"</center><hr><br>version 2.17, TangYC\n");
  108.         return(plen);
  109. }

  110. /**
  111.   * @brief  Main program.
  112.   * @param  None
  113.   * @retval : None
  114.   */
  115. int main(void)
  116. {
  117.   uint16_t plen=0;
  118.   uint16_t dat_p;
  119.   int8_t cmd;
  120.   uint8_t payloadlen,cmd_pos;
  121.   char str[30];
  122.   char cmdval;
  123.   
  124.   RCC_Init();
  125.   InterruptConfig();
  126.   SysTick_Config();
  127.   SPI_Config();
  128.   GPIO_Config();
  129.   enc28j60Init(mymac);
  130.   
  131.   
  132.   /* Infinite loop */
  133. //init the ethernet/ip layer:
  134.         init_ip_arp_udp_tcp(mymac,myip,MYWWWPORT);

  135.         while(1){
  136.                 // get the next new packet:
  137.                 plen = enc28j60PacketReceive(BUFFER_SIZE, buf);

  138.                 /*plen will ne unequal to zero if there is a valid
  139.                  * packet (without crc error) */
  140.                 if(plen==0){
  141.                         continue;
  142.                 }
  143.                         
  144.                 // arp is broadcast if unknown but a host may also
  145.                 // verify the mac address by sending it to
  146.                 // a unicast address.
  147.                 if(eth_type_is_arp_and_my_ip(buf,plen)){
  148.                         make_arp_answer_from_request(buf);
  149.                         continue;
  150.                 }

  151.                 // check if ip packets are for us:
  152. ……………………

  153. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼


STM32 ENC28J60調試通過.7z

171.69 KB, 下載次數: 34, 下載積分: 黑幣 -5






歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 四虎在线视频 | 日韩中文一区 | 国产精品高潮呻吟久久 | 亚洲国产乱码 | 亚洲精品视频免费观看 | 激情久久网 | 亚洲国产成人在线观看 | 中文字幕在线观看视频一区 | 亚洲免费人成在线视频观看 | 国产精品亚洲综合 | 精品国产亚洲一区二区三区大结局 | 国产精品久久久久aaaa | 日韩欧美久久 | 欧美日韩一区二区三区视频 | 欧美一区二区久久 | 亚洲乱码一区二区 | 久久青视频 | 91九色porny首页最多播放 | 国产成人精品午夜视频免费 | 午夜在线观看免费 | 欧美另类视频 | 免费观看一级毛片 | 欧美xxxx黑人又粗又长 | 91精品国产91久久综合桃花 | 欧美不卡在线 | 亚洲欧美一区二区三区国产精品 | 日韩在线中文 | 国产精品视频一二三区 | 国产精品免费看 | 久草网站| 亚洲精品www.| 欧美 中文字幕 | 国产精品久久久久久妇女6080 | 一级黄色片网站 | 国产美女在线看 | 色资源在线 | 新超碰97| 男女午夜激情视频 | 免费精品在线视频 | 国产精品久久亚洲 | 日本亚洲精品成人欧美一区 |