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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2475|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32 ENC28J60調(diào)試通過的源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:810398 發(fā)表于 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 );//返回比較結(jié)果
  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黑下載附件…………
復(fù)制代碼


STM32 ENC28J60調(diào)試通過.7z

171.69 KB, 下載次數(shù): 34, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 国产高清自拍视频在线观看 | 99re在线视频观看 | 国产精品伦一区二区三级视频 | 一区在线观看 | 久久久久久国产免费视网址 | 视频精品一区 | 国产日韩在线观看一区 | 久久久国产一区二区三区 | 亚洲网站在线观看 | 狠狠爱免费视频 | 精品国产乱码久久久久久闺蜜 | 国产精品国产三级国产a | 久久久久久久久久久福利观看 | 亚洲精品久久久蜜桃 | 夜久久| 久草视频在线播放 | av日日操| 国产一二三视频在线观看 | 日日天天 | 九久久 | 久久亚洲美女 | 99免费在线观看视频 | 一区二区在线不卡 | 亚洲一区二区三区在线视频 | 中文字幕一区二区三区精彩视频 | av电影手机在线看 | 一区二区三 | 妞干网视频 | 精品一区久久 | 婷婷久久久久 | 免费精品一区 | 成人一区二区三区在线 | av免费网站在线 | 欧美一级在线免费观看 | 成人不卡 | 国产精品视频网 | 国产欧美一区二区三区在线看蜜臀 | 欧美四虎 | 伊人二区| 国产精品99久久久久久动医院 | 免费黄色片在线观看 |