User manual

491
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
SPI_Ethernet_renewDHCP
Prototype
function SPI_Ethernet_renewDHCP(tmax : byte) : byte;
Description This is DHCP module routine. It sends IP address lease time renewal request to DHCP server.
Parameters - tmax: time in seconds to wait for an reply.
Returns - 1 - upon success (lease time was renewed).
- 0 - otherwise (renewal request timed out).
Requires Ethernet module has to be initialized. See SPI_Ethernet_Init.
Example
while true do
begin
...
if (SPI_Ethernet_doDHCPLeaseTime() <> 0) then
begin
SPI_Ethernet_renewDHCP(5); // it’s time to renew the IP address
lease, with 5 secs for a reply
end;
...
end;
Notes None.
Library Example
This code shows how to use the Ethernet mini library:
- the board will reply to ARP & ICMP echo requests
- the board will reply to UDP requests on any port:
- returns the request in upper char with a header made of remote host IP & port number
- the board will reply to HTTP requests on port 80, GET method with pathnames:
- / will return the HTML main page
- /s will return board status as text string
- /t0 ... /t7 will toggle RD0 to RD7 bit and return HTML main page
- all other requests return also HTML main page.
Main program code:
program HTTP_Demo;
{***********************************
* RAM variables
*}
// mE ehternet NIC pinout
var
SPI_Ethernet_Rst : sbit at LATF0_bit; // for writing to output pin always use latch
SPI_Ethernet_CS : sbit at LATF1_bit; // for writing to output pin always use latch
SPI_Ethernet_Rst_Direction : sbit at TRISF0_bit;
SPI_Ethernet_CS_Direction : sbit at TRISF1_bit;
// end ethernet NIC denitions
var myMacAddr : array[6] of byte; // my MAC address
myIpAddr : array[4] of byte; // my IP address