User manual

420
mikoPascal PRO for PIC32
MikroElektronika
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.
Copy Code To Clipboard
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
gwIpAddr : array[4] of byte; // gateway (router) IP address
ipMask : array[4] of byte; // network mask (for example : 255.255.255.0)
dnsIpAddr : array[4] of byte; // DNS server IP address
{************************************************************
* ROM constant strings
*}
const httpHeader : string[30] = ‘HTTP/1.1 200 OK’+#10+’Content-type: ; // HTTP
header
const httpMimeTypeHTML : string[11] = ‘text/html’+#10+#10; // HTML MIME type
const httpMimeTypeScript : string[12] = ‘text/plain’+#10+#10; // TEXT MIME type
const httpMethod : string[5] = ‘GET /’;
{*
* web page, splited into 2 parts :
* when coming short of ROM, fragmented data is handled more efciently by linker
*
* this HTML page calls the boards to get its status, and builds itself with
javascript
*}
const indexPage : string[761] =