用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c代码库

stm32 实现ping其他设备

2017-02-25 作者: 云代码会员举报

[c]代码库

**
  ******************************************************************************
  * @file    main.c
  * @author  ARMJISHU Team
  * @version V1.0.0
  * @date    11/20/2009
  * @brief   Main program body
  ******************************************************************************
  *
  * <h2><center>&copy; COPYRIGHT 2009 ARMJISHU</center></h2>
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32_eth.h"
#include "netconf.h"
#include "main.h"
#include "helloworld.h"
#include "helloarmjishu.h"
#include "httpd.h"
#include "tftpserver.h"
#include <stdio.h>

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define SYSTEMTICK_PERIOD_MS  10

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
uint32_t timingdelay;

/* Private function prototypes -----------------------------------------------*/
void System_Periodic_Handle(void);

void Delay_ARMJISHU(__IO uint32_t nCount);

extern void ARMJISHU_TouchScreen(void);
  /* 显示系统运行时间 */
void LCD_Time_Update(uint32_t localtime);

/* Private functions ---------------------------------------------------------*/

void Show_Msg(void);

u16 Show_ETH_PHY(u16 PHYRegAddr);

void Check_ETH_PHY(void);

void Delay_ARMJISHU(__IO uint32_t nCount)
{
  for (; nCount != 0; nCount--);
}


/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  u8 c[] = "www.armjishu.com";
  u8 c2[] = "3.2\" LCD 320X240";
  
  System_Setup();
             
  /* Initilaize the LwIP satck */
  LwIP_Init();

  /* Infinite loop */
  while (1)
  {    
    /* Periodic tasks */
    System_Periodic_Handle();
    ARMJISHU_TouchScreen();
  }
}

void Time_Update(void)
{
  LocalTime += SYSTEMTICK_PERIOD_MS;
}

  /* 显示系统运行时间 */
void LCD_Time_Update(uint32_t localtime)
{
  static uint32_t LcdDisplayTimer=20000;
  uint32_t TimeVar;
  uint32_t THH = 0, TMM = 0, TSS = 0;
  uint8_t  TimeStr[20];

  /* 1 s */
  if (localtime >= (LcdDisplayTimer + 1000)) 
  {
    LcdDisplayTimer = localtime;
    TimeVar = LcdDisplayTimer/1000;
    /* Compute  hours */
    THH = (TimeVar / 3600)%24;
    /* Compute minutes */
    TMM = (TimeVar % 3600) / 60;
    /* Compute seconds */
    TSS = (TimeVar % 3600) % 60;

    sprintf((char *)TimeStr, " Run Time: %0.2d:%0.2d:%0.2d ", THH, TMM, TSS);
    LCD_DisplayStringLine(Line0, TimeStr);
  }
}

/**
  * @brief  Handles the periodic tasks of the system
  * @param  None
  * @retval None
  */
void System_Periodic_Handle(void)
{
  /* Update the LCD display and the LEDs status */
  /* Manage the IP address setting */
  Display_Periodic_Handle(LocalTime);

  /* 显示系统运行时间 */
  LCD_Time_Update(LocalTime);
  
  /* LwIP periodic services are done here */
  LwIP_Periodic_Handle(LocalTime);
}

void Show_Msg(void)
{
    printf("\r\n\n\n ================ WWW.ARMJISHU.COM  %s configured ==============", EVAL_COM1_STR);
    printf("\n\r STM32 Connectivity Line Device\n\r");
    printf("\n\r WebServer;telnet;ping;tftp....\n\r");
    //printf("\n\r IP address is: 192.168.1.6\n\r");
}

u16 Show_ETH_PHY(u16 PHYRegAddr)
{
  u16 PHYRegData;
  PHYRegData = ETH_ReadPHYRegister(0,PHYRegAddr);
  printf("\n\rETH_ReadPHYRegister(0,%d):0x%X", PHYRegAddr, PHYRegData);
  return PHYRegData;
}

void Check_ETH_PHY(void)
{
    Show_ETH_PHY(0);
    Show_ETH_PHY(1);
    Show_ETH_PHY(2);
    Show_ETH_PHY(3);
    Show_ETH_PHY(4);
    Show_ETH_PHY(5);
    Show_ETH_PHY(6);
    if(Show_ETH_PHY(17) & 0x3000)
    {  
      /* Set Ethernet speed to 10M following the autonegotiation */    
      printf("\n\r==>ETH_Speed_10M!");
      LCD_DisplayStringLine(Line2, "     ETH_Speed_10M  ");
    }
    else
    {   
      /* Set Ethernet speed to 100M following the autonegotiation */ 
      printf("\n\r==>ETH_Speed_100M!");     
      LCD_DisplayStringLine(Line2, "     ETH_Speed_100M ");
    } 
    /* Configure the MAC with the Duplex Mode fixed by the autonegotiation process */
    if((Show_ETH_PHY(17) & 0xA000) != (uint32_t)RESET)
    {
      /* Set Ethernet duplex mode to FullDuplex following the autonegotiation */
      printf("\n\r==>ETH_Mode_FullDuplex!");
      LCD_DisplayStringLine(Line3, " ETH_Mode_FullDuplex");
    }
    else
    {
      /* Set Ethernet duplex mode to HalfDuplex following the autonegotiation */
      printf("\n\r==>ETH_Mode_HalfDuplex!");
      LCD_DisplayStringLine(Line3, " ETH_Mode_HalfDuplex");
    }
}

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

[源代码打包下载]




网友评论    (发表评论)

共3 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...