Hello.
I have been trying to make EasyPic4 with PIC16F887 and serial ethernet board ENC28J60 working.
I can not browse the web page on the pic.
I did what is said in the program comments.
my computer has an ip adress : 192.168.20.32
Subnet mask : 255.255.255.0
Default gateway : 192.168.20.60
I tried with different ip and gateway ,but the result was the same.
Serial Ethernet Board's leds : LED A is always on, POWER is always ON, LEB B in the begining blinks and than dies.
Here is my code:
/*
* Project Name:
httpserver_example (Ethernet Library http server demo for ENC28J60 mcu)
* Target Platform:
PIC
* Copyright:
(c) mikroElektronika, 2006.
*
* description :
* this code shows how to use the ENC28J60 mini library :
* the board will reply to ARP & ICMP echo requests
* 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 RC0 to RC7 bit and return HTML main page
* all other requests return also HTML main page
*
* target devices :
* any PIC with integrated SPI and more than 4 Kb ROM memory
* 32 to 40 MHz clock is recommended to get from 8 to 10 Mhz SPI clock,
* otherwise PIC should be clocked by ENC clock output due to ENC silicon bug in SPI hardware
* if you try lower PIC clock speed, don't be surprised if the board hang or miss some requests !
* tested with PIC16F877A@10Mhz on EasyPIC4 board
*
* EP settings :
* RA2 & RA3 pots jumper : closed
* PORTB : pull-down
* PORTC : pull-down
* BUTTONS : pull-up
*
* RC0 : !RESET to ENC reset input pin
* RC1 : !CS to ENC chip select input pin
* the ENC28J60 SPI bus CLK, SO, SI must be connected to the corresponding SPI pins of the PIC
* the INT and WOL signals from the ENC are not used
*
* Test configuration:
MCU: PIC16F877A
Dev.Board: EasyPIC4
Oscillator: HS, 10.000MHz
Ext. Modules: mE Serial Ethernet board
SW: mikroC v6.2.0.0.
* NOTES:
None.
*/
#define SPI_Ethernet_HALFDUPLEX 0
#define SPI_Ethernet_FULLDUPLEX 1
sfr sbit SPI_Ethernet_Rst at RC0_bit;
sfr sbit SPI_Ethernet_CS at RC1_bit;
sfr sbit SPI_Ethernet_Rst_Direction at TRISC0_bit;
sfr sbit SPI_Ethernet_CS_Direction at TRISC1_bit;
/************************************************************
* ROM constant strings
*/
const unsigned char httpHeader[] = "HTTP/1.1 200 OK\nContent-type: " ; // HTTP header
const unsigned char httpMimeTypeHTML[] = "text/html\n\n" ; // HTML MIME type
const unsigned char httpMimeTypeScript[] = "text/plain\n\n" ; // TEXT MIME type
unsigned char httpMethod[] = "GET /"; // supported http method
/*
* web page, splited into 2 parts :
* when coming short of ROM, fragmented data is handled more efficiently by linker
*
* this HTML page calls the boards to get its status, and builds itself with javascript
*/
const char *indexPage = "<HTML><HEAD></HEAD><BODY>\
<h1>PIC + ENC28J60 Mini Web Server</h1>\
<a href=/>Reload</a>\
<script src=/s></script>\
<table><tr><td valign=top><table border=1 style=\"font-size:20px ;font-family: terminal ;\">\
<tr><th colspan=2>ADC</th></tr>\
<tr><td>AN2</td><td><script>document.write(AN2)</script></td></tr>\
<tr><td>AN3</td><td><script>document.write(AN3)</script></td></tr>\
</table></td><td><table border=1 style=\"font-size:20px ;font-family: terminal ;\">\
<tr><th colspan=2>PORTB</th></tr>\
<script>\
var str,i;\
str=\"\";\
for(i=0;i<8;i++)\
{str+=\"<tr><td bgcolor=pink>BUTTON #\"+i+\"</td>\";\
if(PORTB&(1<<i)){str+=\"<td bgcolor=red>ON\";}\
else {str+=\"<td bgcolor=#cccccc>OFF\";}\
str+=\"</td></tr>\";}\
document.write(str) ;\
</script>\
" ;
const char *indexPage2 = "</table></td><td>\
<table border=1 style=\"font-size:20px ;font-family: terminal ;\">\
<tr><th colspan=3>PORTD</th></tr>\
<script>\
var str,i;\
str=\"\";\
for(i=0;i<8;i++)\
{str+=\"<tr><td bgcolor=yellow>LED #\"+i+\"</td>\";\
if(PORTD&(1<<i)){str+=\"<td bgcolor=red>ON\";}\
else {str+=\"<td bgcolor=#cccccc>OFF\";}\
str+=\"</td><td><a href=/t\"+i+\">Set/Reset Bit\"+i+\"</a></td></tr>\";}\
document.write(str) ;\
</script>\
</table></td></tr></table>\
This is HTTP request #<script>document.write(REQ)</script></BODY></HTML>\
" ;
/***********************************
* RAM variables
*/
unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // my MAC address
unsigned char myIpAddr[4] = {192, 168, 20, 60} ; // my IP address
unsigned char getRequest[15] ; // HTTP request buffer
unsigned char dyna[31] ; // buffer for dynamic response
unsigned long httpCounter = 0 ; // counter of HTTP requests
/*******************************************
* functions
*/
/*
* put the constant string pointed to by s to the ENC transmit buffer
*/
unsigned int putConstString(const char *s)
{
unsigned int ctr = 0 ;
while(*s)
{
SPI_Ethernet_putByte(*s++) ;
ctr++ ;
}
return(ctr) ;
}
/*
* put the string pointed to by s to the ENC transmit buffer
*/
unsigned int putString(char *s)
{
unsigned int ctr = 0 ;
while(*s)
{
SPI_Ethernet_putByte(*s++) ;
ctr++ ;
}
return(ctr) ;
}
/*
* this function is called by the library
* the user accesses to the HTTP request by successive calls to SPI_Ethernet_getByte()
* the user puts data in the transmit buffer by successive calls to SPI_Ethernet_putByte()
* the function must return the length in bytes of the HTTP reply, or 0 if nothing to transmit
*
* if you don't need to reply to HTTP requests,
* just define this function with a return(0) as single statement
*
*/
unsigned int SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, char *canClose)
{
unsigned int len = 0 ; // my reply length
unsigned int i ; // general purpose integer
if(localPort != 80) // I listen only to web request on port 80
{
return(0) ;
}
// get 10 first bytes only of the request, the rest does not matter here
for(i = 0 ; i < 10 ; i++)
{
getRequest = SPI_Ethernet_getByte() ;
}
getRequest = 0 ;
if(memcmp(getRequest, httpMethod, 5)) // only GET method is supported here
{
return(0) ;
}
httpCounter++ ; // one more request done
if(getRequest[5] == 's') // if request path name starts with s, store dynamic data in transmit buffer
{
// the text string replied by this request can be interpreted as javascript statements
// by browsers
len = putConstString(httpHeader) ; // HTTP header
len += putConstString(httpMimeTypeScript) ; // with text MIME type
// add AN2 value to reply
intToStr(ADC_Read(2), dyna) ; // convert read adc channel 2 value into string
len += putConstString("var AN2=") ;
len += putString(dyna) ;
len += putConstString(";\n") ;
// add AN3 value to reply
intToStr(ADC_Read(3), dyna) ; // convert read adc channel 2 value into string
len += putConstString("var AN3=") ;
len += putString(dyna) ;
len += putConstString(";\n") ;
// add PORTB value (buttons) to reply
len += putConstString("var PORTB=") ;
intToStr(PORTB, dyna) ; // convert read portb state into string
len += putString(dyna) ;
len += putConstString(";\n") ;
// add PORTD value (LEDs) to reply
len += putConstString("var PORTD=") ;
intToStr(PORTD, dyna) ; // convert read latd value (portd led's state) into string
len += putString(dyna) ;
len += putConstString(";\n") ;
// add HTTP requests counter to reply
intToStr(httpCounter, dyna) ; // convert httpCounter value into string
len += putConstString("var REQ=") ;
len += putString(dyna) ;
len += putConstString(";\n") ;
}
else if(getRequest[5] == 't') // if request path name starts with t, toggle PORTD (LED) bit number that comes after
{
unsigned char bitMask = 0 ; // for bit mask
if(isdigit(getRequest[6])) // if 0 <= bit number <= 9, bits 8 & 9 does not exist but does not matter
{
bitMask = getRequest[6] - '0' ; // convert ASCII to integer
bitMask = 1 << bitMask ; // create bit mask
PORTD ^= bitMask ; // toggle PORTD with xor operator
}
}
else if(getRequest[5] == 'r')
{
PORTD=0x00;
}
else if(getRequest[5] == 'a')
{
PORTD=0xFF;
}
else if(getRequest[5] == 'n')
{
PORTD=~PORTD;
}
if(len == 0) // what do to by default
{
len = putConstString(httpHeader) ; // HTTP header
len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type
len += putConstString(indexPage) ; // HTML page first part
len += putConstString(indexPage2) ; // HTML page second part
}
return(len) ; // return to the library with the number of bytes to transmit
}
/*
* this function is called by the library
* the user accesses to the UDP request by successive calls to SPI_Ethernet_getByte()
* the user puts data in the transmit buffer by successive calls to SPI_Ethernet_putByte()
* the function must return the length in bytes of the UDP reply, or 0 if nothing to transmit
*
* if you don't need to reply to UDP requests,
* just define this function with a return(0) as single statement
*
*/
unsigned int SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength)
{
return 0 ; // back to the library with the length of the UDP reply
}
/*
* main entry
*/
void main()
{
ADCON1 = 0x00 ; // ADC convertors will be used
PORTA = 0 ;
TRISA = 0xff ; // set PORTA as input for ADC
PORTB = 0 ;
TRISB = 0xff ; // set PORTB as input for buttons
PORTD = 0 ;
TRISD = 0 ; // set PORTD as output
/*
* initialize ethernet board
* start ENC28J60 with :
* reset bit on RC0
* CS bit on RC1
* my MAC & IP address
* full duplex
*/
Spi1_Init();
SPI_Ethernet_Init(myMacAddr, myIpAddr, SPI_Ethernet_FULLDUPLEX) ;
while(1) // endless loop
{
SPI_Ethernet_doPacket() ; // process incoming Ethernet packets
/*
* add your stuff here if needed
* SPI_Ethernet_doPacket() must be called as often as possible
* otherwise packets could be lost
*/
}
}
EasyPic4 with PIC16F887 + ENC28J60 web server
General discussion on mikroPascal.
Author
Message
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Re: EasyPic4 with PIC16F887 + ENC28J60 web server
#2 Post by slavisa.zlatanovic » 04 Apr 2011 13:23
Hi!
We strongly encourage users to switch to mikroPascal PRO version because non-PRO version is an ancestor of PRO compiler
and is no longer being developed.
Every new feature, improvement and bug fix will only affect new versions of PRO compilers.
If you're a registered user you'll receive PRO license key free of charge.
Also, see the Migration Document for more details:
We strongly encourage users to switch to mikroPascal PRO version because non-PRO version is an ancestor of PRO compiler
and is no longer being developed.
Every new feature, improvement and bug fix will only affect new versions of PRO compilers.
If you're a registered user you'll receive PRO license key free of charge.
Also, see the Migration Document for more details:
- Migration_document.PNG (15.87 KiB) Viewed 6409 times
Best regards
Slavisa
Slavisa
Return to “mikroPascal General”
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects