Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
Library Example
This code shows how to use the AVR mini Ethernet 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 P3.b0 to P3.b7 bit and return HTML main page 
all other requests return also HTML main page. 
Main program code: 
include eth_enc28j60_utils 'this is where you should write implemen-
tation for UDP and HTTP
'***********************************
'* RAM variables
'*
'***********************************
dim myMacAddr   as byte[6]     ' my MAC address
myIpAddr    
as byte[4]     ' my IP address
gwIpAddr    
as byte[4]     ' gateway (router) IP address
ipMask      
as byte[4]     ' network mask (for example :
255.255.255.0)
dnsIpAddr   as byte[4]     ' DNS server IP address
' mE ehternet NIC pinout
SPI_Ethernet_Rst 
as sbit at PORTB.B4
SPI_Ethernet_CS  
as sbit at PORTB.B5
SPI_Ethernet_Rst_Direction 
as sbit at DDRB.B4
SPI_Ethernet_CS_Direction  
as sbit at DDRB.B5
' end ethernet NIC definitions
dim as word
main:
' set PORTC as input
DDRC = 0
' set PORTD as output
DDRD = 0xFF
httpCounter = 0
381
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6