User manual

mikroC PRO for dsPIC
MikroElektronika
515
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
#include “__EthEnc28j60.h”
// duplex cong ags
#dene Spi_Ethernet_HALFDUPLEX 0x00 // half duplex
#dene Spi_Ethernet_FULLDUPLEX 0x01 // full duplex
// mE ehternet NIC pinout
sfr sbit SPI_Ethernet_Rst at LATF0_bit; // for writing to output pin always use latch
sfr sbit SPI_Ethernet_CS at LATF1_bit; // for writing to output pin always use latch
sfr sbit SPI_Ethernet_Rst_Direction at TRISF0_bit;
sfr sbit SPI_Ethernet_CS_Direction at TRISF1_bit;
// end ethernet NIC denitions
/************************************************************
* ROM constant strings
*/
const code unsigned char httpHeader[] = “HTTP/1.1 200 OKnContent-type: “; // HTTP
header
const code unsigned char httpMimeTypeHTML[] = “text/htmlnn”; // HTML MIME
type
const code unsigned char httpMimeTypeScript[] = “text/plainnn”; // TEXT MIME
type
unsigned char httpMethod[] = “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 code char *indexPage = // Change the IP address of the page
to be refreshed
“<meta http-equiv=”refresh” content=”3;url=http://192.168.20.60”>
<HTML><HEAD></HEAD><BODY>
<h1>dsPIC + ENC28J60 Mini Web Server</h1>