Hola, tambien estoy probando un ejemplo que viene en el mikrobaisc 5.0 para modulo enc28j60, es el siguiente:
program enc28j60
' ***********************************
' * RAM variables
' *
dim myMacAddr as byte[6] ' my MAC address
myIpAddr as byte[4] ' my IP address
' mE ehternet NIC pinout
SPI_Ethernet_Rst as sbit at RC0_bit
SPI_Ethernet_CS as sbit at RC1_bit
SPI_Ethernet_Rst_Direction as sbit at TRISC0_bit
SPI_Ethernet_CS_Direction as sbit at TRISC1_bit
' end ethernet NIC definitions
' ************************************************************
' * ROM constant strings
' *
const httpHeader as string[31] = "HTTP/1.1 200 OK"+chr(10)+"Content-type: " ' HTTP header
const httpMimeTypeHTML as string[13] = "text/html"+chr(10)+chr(10) ' HTML MIME type
const httpMimeTypeScript as string[14] = "text/plain"+chr(10)+chr(10) ' TEXT MIME type
const httpMethod as string[5] = "GET /"
' *
' * 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 indexPage as string[763] =
"<meta http-equiv=" + Chr(34) + "refresh" + Chr(34) + " content=" + Chr(34) + "3;url=http://192.168.20.60" + Chr(34) + ">" +
"<HTML><HEAD></HEAD><BODY>"+
"<h1>PIC + ENC28J60 Mini Web Server</h1>"+
"<a href=/>Reload[/url]"+
"<script src=/s></script>"+
"<table><tr><td valign=top><table border=1 style="+chr(34)+"font-size:20px ;font-family: terminal ;"+chr(34)+"> "+
"<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="+chr(34)+"font-size:20px ;font-family: terminal ;"+chr(34)+"> "+
"<tr><th colspan=2>PORTB</th></tr>"+
"<script>"+
"var str,i;"+
"str="+chr(34)+chr(34)+"; "+
"for(i=0;i<8;i++)"+
"{str+="+chr(34)+"<tr><td bgcolor=pink>BUTTON #"+chr(34)+"+i+"+chr(34)+"</td>"+chr(34)+"; "+
"if(PORTB&(1<<i)){str+="+chr(34)+"<td bgcolor=red>ON"+chr(34)+";}"+
"else {str+="+chr(34)+"<td bgcolor=#cccccc>OFF"+chr(34)+";}"+
"str+="+chr(34)+"</td></tr>"+chr(34)+";}"+
"document.write(str) ;"+
"</script>"
const indexPage2 as string[470] =
"</table></td><td>"+
"<table border=1 style="+chr(34)+"font-size:20px ;font-family: terminal ;"+chr(34)+"> "+
"<tr><th colspan=3>PORTD</th></tr>"+
"<script>"+
"var str,i;"+
"str="+chr(34)+chr(34)+"; "+
"for(i=0;i<8;i++)"+
"{str+="+chr(34)+"<tr><td bgcolor=yellow>LED #"+chr(34)+"+i+"+chr(34)+"</td>"+chr(34)+"; "+
"if(PORTD&(1<<i)){str+="+chr(34)+"<td bgcolor=red>ON"+chr(34)+";}"+
"else {str+="+chr(34)+"<td bgcolor=#cccccc>OFF"+chr(34)+";}"+
"str+="+chr(34)+"</td><td><a href=/t"+chr(34)+"+i+"+chr(34)+">Toggle[/url]</td></tr>"+chr(34)+";}"+
"document.write(str) ;"+
"</script>"+
"</table></td></tr></table>"+
"This is HTTP request #<script>document.write(REQ)</script></BODY></HTML>"
dim getRequest as byte[15] ' HTTP request buffer
dyna as char[30] ' buffer for dynamic response
httpCounter as word ' counter of HTTP requests
tmp as string[11]
' *******************************************
' * user defined sub functions
' *
' *
' * this sub 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 sub 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 sub function with a return(0) as single statement
' *
' *
sub function Spi_Ethernet_UserTCP(dim byref remoteHost as byte[4], dim remotePort, localPort, reqLength as word, dim byref flags as TEthPktFlags) as word
dim i as word ' general purpose integer
bitMask as byte ' for bit mask
result = 0
' should we close tcp socket after response is sent?
' library closes tcp socket by default if canClose flag is not reset here
' canClose = 0 ' 0 - do not close socket
' otherwise - close socket
if(localPort <> 80) then ' I listen only to web request on port 80
result = 0
exit
end if
' get 10 first bytes only of the request, the rest does not matter here
for i = 0 to 10
getRequest = Spi_Ethernet_getByte()
next i
getRequest = 0
' copy httpMethod to ram for use in memcmp routine
for i = 0 to 4
tmp = httpMethod
next i
if(memcmp(@getRequest, @tmp, 5) <> 0) then ' only GET method is supported here
result = 0
exit
end if
Inc(httpCounter) ' one more request done
if(getRequest[5] = "s") then ' 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
result = SPI_Ethernet_putConstString(@httpHeader) ' HTTP header
result = result + SPI_Ethernet_putConstString(@httpMimeTypeScript) ' with text MIME type
' add AN2 value to reply
WordToStr(ADC_Read(2), dyna)
tmp = "var AN2="
result = result + SPI_Ethernet_putString(@tmp)
result = result + SPI_Ethernet_putString(@dyna)
tmp = ";"
result = result + SPI_Ethernet_putString(@tmp)
' add AN3 value to reply
WordToStr(ADC_Read(3), dyna)
tmp = "var AN3="
result = result + SPI_Ethernet_putString(@tmp)
result = result + SPI_Ethernet_putString(@dyna)
tmp = ";"
result = result + SPI_Ethernet_putString(@tmp)
' add PORTB value (buttons) to reply
tmp = "var PORTB= "
result = result + SPI_Ethernet_putString(@tmp)
WordToStr(PORTB, dyna)
result = result + SPI_Ethernet_putString(@dyna)
tmp = ";"
result = result + SPI_Ethernet_putString(@tmp)
' add PORTD value (LEDs) to reply
tmp = "var PORTD= "
result = result + SPI_Ethernet_putString(@tmp)
WordToStr(PORTD, dyna)
result = result + SPI_Ethernet_putString(@dyna)
tmp = ";"
result = result + SPI_Ethernet_putString(@tmp)
' add HTTP requests counter to reply
WordToStr(httpCounter, dyna)
tmp = "var REQ= "
result = result + SPI_Ethernet_putString(@tmp)
result = result + SPI_Ethernet_putString(@dyna)
tmp = ";"
result = result + SPI_Ethernet_putString(@tmp)
else
if(getRequest[5] = "t") then ' if request path name starts with t, toggle PORTD (LED) bit number that comes after
bitMask = 0
if(isdigit(getRequest[6]) <> 0) then ' 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 = PORTD xor bitMask ' toggle PORTD with xor operator
end if
end if
end if
if(result = 0) then ' what do to by default
result = SPI_Ethernet_putConstString(@httpHeader) ' HTTP header
result = result + SPI_Ethernet_putConstString(@httpMimeTypeHTML) ' with HTML MIME type
result = result + SPI_Ethernet_putConstString(@indexPage) ' HTML page first part
result = result + SPI_Ethernet_putConstString(@indexPage2) ' HTML page second part
end if
' return to the library with the number of bytes to transmit
end sub
' *
' * this sub 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 sub 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 sub function with a return(0) as single statement
' *
' *
sub function Spi_Ethernet_UserUDP(dim byref remoteHost as byte[4],
dim remotePort, destPort, reqLength as word, dim byref flags as TEthPktFlags) as word
result = 0
' reply is made of the remote host IP address in human readable format
byteToStr(remoteHost[0], dyna) ' first IP address byte
dyna[3] = "."
byteToStr(remoteHost[1], tmp) ' second
dyna[4] = tmp[0]
dyna[5] = tmp[1]
dyna[6] = tmp[2]
dyna[7] = "."
byteToStr(remoteHost[2], tmp) ' second
dyna[8] = tmp[0]
dyna[9] = tmp[1]
dyna[10] = tmp[2]
dyna[11] = "."
byteToStr(remoteHost[3], tmp) ' second
dyna[12] = tmp[0]
dyna[13] = tmp[1]
dyna[14] = tmp[2]
dyna[15] = ":" ' add separator
' then remote host port number
WordToStr(remotePort, tmp)
dyna[16] = tmp[0]
dyna[17] = tmp[1]
dyna[18] = tmp[2]
dyna[19] = tmp[3]
dyna[20] = tmp[4]
dyna[21] = "["
WordToStr(destPort, tmp)
dyna[22] = tmp[0]
dyna[23] = tmp[1]
dyna[24] = tmp[2]
dyna[25] = tmp[3]
dyna[26] = tmp[4]
dyna[27] = "]"
dyna[28] = 0
' the total length of the request is the length of the dynamic string plus the text of the request
result = 28 + reqLength
' puts the dynamic string into the transmit buffer
SPI_Ethernet_putBytes(@dyna, 28)
' then puts the request string converted into upper char into the transmit buffer
while(reqLength <> 0)
SPI_Ethernet_putByte(SPI_Ethernet_getByte())
reqLength = reqLength - 1
wend
' back to the library with the length of the UDP reply
end sub
main:
ANSEL = 0x0C ' AN2 and AN3 convertors will be used
PORTA = 0
TRISA = 0xff ' set PORTA as input for ADC
ANSELH = 0 ' Configure other AN pins as digital I/O
PORTB = 0
TRISB = 0xff ' set PORTB as input for buttons
PORTD = 0
TRISD = 0 ' set PORTD as output
httpCounter = 0
' set mac address
myMacAddr[0] = 0x00
myMacAddr[1] = 0x14
myMacAddr[2] = 0xA5
myMacAddr[3] = 0x76
myMacAddr[4] = 0x19
myMacAddr[5] = 0x3F
' set IP address
myIpAddr[0] = 192
myIpAddr[1] = 168
myIpAddr[2] = 20
myIpAddr[3] = 60
' *
' * starts ENC28J60 with :
' * reset bit on PORTC.B0
' * CS bit on PORTC.B1
' * my MAC & IP address
' * full duplex
' *
SPI1_Init() ' init spi module
SPI_Ethernet_Init(myMacAddr, myIpAddr, _SPI_Ethernet_FULLDUPLEX) ' init ethernet module
SPI_Ethernet_setUserHandlers(@SPI_Ethernet_UserTCP, @SPI_Ethernet_UserUDP) ' set user handlers
while TRUE ' 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
' *
wend
end.
y al compilar me da el siguiente error :
unknown type "TethPktFlags"
Syntax error: expected "end" but "dim" found
Syntax error: expected "sub" but "i" found
Syntax error: expected "end" but "as" found
Syntax error: expected "." but "word" found
Si alguien puede ayudar con el tema, dado que no comprendo porque un ejemplo da este error.