How does DHCP work?

The tictactoe example that is programmed at the factory will automatically look for a DHCP server if the static IP address is set to 0.0.0.0; otherwise it will use the static IP address. This method allows both static and dynamic addressed on the same network.

In order for the DHCP client to operate in your program, you need the following code running in your application (taken from tictactoe example):

#include <dhcpclient.h>

void UserMain(void * pd)
{
   InitializeStack();
   if (EthernetIP == 0)
   {
      OS_SEM DHCPSem;
      OSSemInit(&DHCPSem,0);  //Initialize the Semaphore 
      printf("IP address is 0.0.0.0, we are trying DHCP \n");
      StartDHCP(&DHCPSem);    //Start DHCP
      if (OSSemPend(&DHCPSem,10*TICKS_PER_SECOND)==OS_TIMEOUT) //Wait 10 seconds
      {
         //DHCP did not initialize, handle the error here
         printf("DHCP failed to initialize, system has IP address of Zero\r\n");
      }
      else
      {
         printf("DHCP assigned the IP address of:");
         ShowIP(EthernetIP);
         printf("\n");
      }
   }


   <Other code .....>

}