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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2505|回復: 0
收起左側

STM32 ENC28J60調試通過的源程序

[復制鏈接]
ID:810398 發表于 2020-8-1 22:38 | 顯示全部樓層 |閱讀模式
  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

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩欧美中文在线 | 午夜视频网 | 国产一二三区精品视频 | 亚洲精品国产a久久久久久 午夜影院网站 | 欧美激情精品久久久久久 | 国产精品久久久久久久久久久久午夜片 | 国产精品美女一区二区三区 | 久久久精品一区 | 一区二区三区国产精品 | 国产精品美女久久久av超清 | 九九热在线观看视频 | www.一级片| 国产精品成人在线播放 | www.久久艹| 亚洲精品中文字幕中文字幕 | 毛片一级网站 | 精品成人| 一区二区三区久久久 | 亚洲精品日韩综合观看成人91 | 欧美日韩电影一区 | 欧美日韩亚洲一区 | 拍真实国产伦偷精品 | 91久久精品国产免费一区 | 亚洲高清在线观看 | 亚洲在线视频 | 国产激情视频网站 | 伊人伊成久久人综合网站 | 国产精品久久久久久久久久妇女 | 秋霞精品 | 亚洲一区二区视频在线观看 | www.狠狠干 | 欧美日韩中文字幕 | 一区二区三区四区av | 精品久久久久一区二区国产 | 影音先锋成人资源 | 99色在线 | 91不卡| 九九综合| 日韩精品一区二区三区中文在线 | 日韩aⅴ视频 | 国产美女精品视频 |