ETHERNET LIBRARY WITH WEB SERVER EXAMPLE FOR PIC18F97J60 FAM

General discussion on mikroBasic.
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

ETHERNET LIBRARY WITH WEB SERVER EXAMPLE FOR PIC18F97J60 FAM

#1 Post by yo2lio » 21 Jun 2007 21:27

Hello all,

I finished today 21.06.2007, BETA version of Eth_V2 library with WEB SERVER example for PIC18F97J60 family MCU for MikroBasic language.

Author of this project : Medrea Florin Andrei - YO2LIO -
Thanks to Mikroelektronika team and all forum users.

Web Server example : (No TCP STACK, No fragmentation available at this moment).

Initial IP Address : 192.168.1.253.
HTTP port respond : 80.

//192.168.1.253/ (web page1)
//192.168.1.253/p (web page2)

User Functions and Procedures:

Code: Select all

' Sub Procedure Eth_SetParameters 
  ' Set your IP, Mac, Mask ... etc... here.

' Sub Procedure Eth_Init  
  ' Init MCU Ethernet.

' Sub Procedure Eth_Reset 
  ' Reset MCU Ethernet.

' Sub Procedure Eth_DoPacket 
  ' Process incoming packets.

' Sub Function Eth_UserTCP(dim byref dest_ip_addr_T as byte[4], dim byref source_port_T, dest_port_T, len_T as word) as word 
  ' This Sub Function is called by library. Put your TCP response for WEB server parameters here. See example.
  
' Sub Function Eth_UserUDP(dim byref dest_ip_addr_U as byte[4], dim byref dest_port_U, source_port_U, len_U as word) as word 
  ' This Sub Function is called by library. Put your UDP response here. See example. ( ECHO example )

' Sub Procedure Eth_PutByte(dim value as byte) 
  ' Put one byte in ETH memory.

' Sub Function Eth_GetByte as byte 
  ' Get one byte from ETH memory.

' Sub Function CopyFlashToEthMem_CP(dim start_Flash_address as longint) as word 
  ' Copy Const from flash to Eth Memory and return length of Const data.
  ' Const data must be defined as STRING. (and must be zero terminated)
  ' Ex. len = CopyFlashToEthMem_CP(@httpHeader)  

' Sub Function CopyRamToEthMem_CP(dim s as byte[255]) as word 
  ' Copy dim data to Eth Memory and return length of dim data.
  ' dim data must be defined as ARRAY. (and must be zero terminated)
  ' Ex. len = CopyRamToEthMem_CP("data data data") 

' Sub Function Eth_SendARP(dim ip_dest as Byte[4]) as Boolean 
  ' Get ARP request. Return True if Mac exist.
  ' Return dest. mac address in dim dest_mac as bytes[6] .
  ' Return dest. ip address in dim dest_ip_addr as byte[4] . 
  ' Ex. bol = Eth_SendARP(user_ip_addr) 
  ' First Sub Function search in ArpCache (size of 9) ...

' Sub Procedure SendUDP(dim dest_port_S, source_port_S, len_data as word,  dim data_udp as byte[1472]) 
  ' Send UDP mesage. Max 1472 bytes.
  ' Ex. If Eth_SendARP(user_ip_addr) then SendUDP(dest_port, eth_port, 10, "Test Test ") 

' Sub Procedure Eth_SendPing(dim SlotState as boolean, dim PingSlot as Byte) 
  ' Have 8 Slots available 0 .. 7 and PingCache size of 8.
  ' Ex. Eth_SendPing(Eth_SendARP(user_ip_addr),0)  Send Ping at user_ip_addr and put result in Slot 0.
  ' PingCache format : 
  ' PingCache[Slot].IpP as byte[4] 
  ' PingCache[Slot].MacP as byte[6] 
  ' PingCache[Slot].Time as word 
  ' PingCache[Slot].TTL as byte.
Advance Functions and Procedures : (AddrPacket is address of received packet, TXSTART is start address of transmited packet)

Code: Select all

' Sub Procedure CopyEthMemToRam(dim start_eth_address, dest_ram_address, length_w as word) 
  ' Ex. CopyEthMemToRam(AddrPacket+6,@dest_mac_addr,6) 

' Sub Procedure CopyRamToEthMem(dim start_ram_address, dest_eth_address, length_w as word) 
  ' Ex. CopyRamToEthMem(@eth_mac,TXSTART+22,6) 

' Sub Procedure CopyFlashToEthMem(dim start_Flash_address as longint, dim dest_eth_address, length_w as word) 
  ' Ex. CopyFlashToEthMem(@httpHeader,TXSTART+54,30) 

' Sub Procedure CopyEthMemToEthMem(dim start_eth_address, dest_eth_address, length_w as word, dim where as byte) 
  ' where = 0 copy from Eth RxBuf to Eth TxBuf 
  ' where = 1 copy from Eth TxBuf to Eth TxBuf
  ' Ex. CopyEthMemToEthMem(AddrPacket+38,TXSTART+28,4,0) 

' Sub Procedure WriteToEthMem(dim dest_eth_address as word, dim value as byte) 
  ' Ex. WriteToEthMem(TXSTART+12,$08) 

' Sub Function ReadFromEthMem(dim start_eth_address as word) as byte 
  ' Ex. data = ReadFromEthMem(AddrPacket+38) 

' Sub Function EthMemCompareWithRam(dim start_eth_address, start_ram_address, length_w as word) as boolean 
  ' Ex. bol = EthMemCompareWithRam(AddrPacket+30,@eth_ip_addr,4) 

' Sub Function EthMemCompareWithFlash(dim start_eth_address as word, dim start_Flash_address as longint, dim length_w as word) as boolean 
  ' Ex. bol = EthMemCompareWithFlash(AddrPacket+54, @httpHeader, 30) 

' Sub Function Eth_Cksum(dim start_eth_address, length_w as word) as word 
  ' Ex. cksum_ip = Eth_Cksum(TXSTART+14,20) 

' Sub Procedure Eth_WritePHYReg(dim register_address as byte, dim data as word) 
  ' Write to PHY registers 

' Sub Procedure Eth_SetLedConfig(dim NewConfig as word) 
  ' Set Eth Led configuration. See datasheet for more detail.

' Sub Function Eth_ReadPacket as word 
  ' Read packet and return TYPE OF SERVICE.

' Sub Procedure Eth_Send(dim length_w as word) 
  ' Send packet from Tx buffer.
You can download the code from here: http://www.microelemente.ro/MikroBasic/ ... Eth_V2.zip

Definitions files for this MCU family, you found here : http://www.mikroe.com/forum/viewtopic.php?t=10454

UDP Bootloader for PIC18F97J60 family, you found here : http://www.mikroe.com/forum/viewtopic.php?t=11260

Good luck !

Best regards, Florin Medrea.
Last edited by yo2lio on 21 Aug 2007 21:37, edited 2 times in total.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: ETHERNET LIBRARY WITH WEB SERVER EXAMPLE FOR PIC18F97J60

#2 Post by zristic » 22 Jun 2007 07:57

Thanks Florin!

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Ethernet library V3.2 and example for LV18FJ board

#3 Post by yo2lio » 19 Aug 2007 23:51

Coming soon : Ethernet library V3.2 and example for LV18FJ board

This library is SMALLER and FASTER.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#4 Post by yo2lio » 22 Aug 2007 13:10

Definitions file for PIC18F97J60 family, MikroBasic language, was revised.

File update is recommended.

Revised file you found here : http://www.mikroe.com/forum/viewtopic.php?t=10454
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Ethernet library V3.2 and example for LV18FJ board

#5 Post by yo2lio » 22 Aug 2007 16:47

Ethernet library V 3.2 MCU family PIC18F97J60

Major changes !!! Some parts from V3.2 library is written in ASM and use indirect addressing and DMA.
Library is 10% smaller and faster.

Added few routine in "aditional_string_lib":

Code: Select all

- Sub Function Str2Byte(dim byref byte_in as string[3]) as byte
   
- Sub Function Str2Word(dim byref word_in as string[5]) as word

- Sub Procedure Byte2Hex(dim data_hex as byte, dim byref hex as string[2])

- Sub Function Hex2Byte(dim byref hex as string[2]) as byte

- Sub Procedure Ip2Str(dim byref user_ip_addr as byte[4], dim byref str_out as string[15])

- Sub Procedure Mac2Str(dim byref mac_address as byte[6], dim byref str_out as string[12])

- Sub Procedure Str2Ip(dim byref str_in as string[15], dim byref user_ip_addr as byte[4])

- Sub Procedure Str2Mac(dim byref str_in as string[12], dim byref mac_address as byte[6])

Added :

Code: Select all

- Sub Function Send_Ping(dim byref ip_address as byte[4]) as word
  ' Send ping at specified ip_address and return response time.
  ' Ex. PingTimeResponse = Send_Ping(user_ip_address)
  
- Sub Function Send_UDP(dim byref ip_address as byte[4], dest_port_S, source_port_S, len_data as word, dim byref data_udp as byte[1472]) as boolean
  ' Send UDP mesage, max 1472 bytes, at specified ip_address and return true if success.
  ' Ex. Success = Send_UDP(user_ip_addr, 10001, 9999, 10, "data data ")
  
- Sub Function Send_ARP(dim byref ip_address as byte[4], dim byref mac_address as byte[6]) as boolean
  ' Get MAC for specified ip_address, put result in mac_address variable and return true if success.
  ' Ex. Success = Send_ARP(user_ip_addr,reply_mac_addr)
  
- Sub Procedure Firewall(ICMP, TCP, UDP as boolean)
  ' Default all false, allow all type of packets.
  ' If ICMP = true, ignore ICMP request. Ex. Firewall(true, false, false)
  ' If TCP = true, ignore TCP packets. Ex. Firewall(false, true, false)
  ' If UDP = true, ignore UDP packets. Ex. Firewall(false, false, true)
  
- Sub Procedure EraseARPCache
  ' Erase ARP cache table.

- Sub Procedure CounterTask
  ' Increments all counters used by library in ARP, ICMP, TCP, UDP routine.
  ' This procedure must be called at 1ms in interrupt routine.

- Sub Procedure CopyEthMemToRam_Inv(dim start_eth_address, dest_ram_address, length_w as word)
  ' Ex. CopyEthMemToRam(AddrPacket+6,@data_dWord,4)

- Sub Procedure CopyRamToEthMem_Inv(dim start_ram_address, dest_eth_address, length_w as word)
  ' Ex. CopyRamToEthMem(@data_dWord,TXSTART+22,4)

You have ARP, ICMP, UDP, TCP, Mini Web Server examples, designed for LV18FJ board.

Image

Parameters :

ARP response time : 317 us
ICMP response time, packet size 32 bytes : 330 us
ICMP response time, packet size 1472 bytes : 3.2 ms
TCP connection response time : 620 us

UDP ECHO response time, method Eth_PutByte(Eth_GetByte), packet size 1442 bytes : 9.7 ms
Bandwidth : 1.3 Mbits/s UP/DOWN
Image

UDP ECHO response time, method CopyEthMemToEthMem(AddrPacket+42, TXSTART+42, len_U, 0), packet size 1442 bytes : 3.4 ms
Bandwidth : 3.0 Mbits/s UP/DOWN
Image

You can download code from : http://www.microelemente.ro/MikroBasic/ ... amples.zip

UDP BootLoader V3 , smaller and faster, you can download here : http://www.mikroe.com/forum/viewtopic.php?t=11260
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#6 Post by yo2lio » 24 Oct 2007 20:02

Hi,

Ethernet lib file V 3.2 MCU family PIC18F97J60 , recompiled with MikroBasic 6.0
http://www.microelemente.ro/MikroBasic/ ... _files.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#7 Post by yo2lio » 12 Nov 2007 22:49

Ethernet Library V3.3 is ready. :D

Please read this post : http://www.mikroe.com/forum/viewtopic.p ... 9&start=22
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

hansolo
Posts: 344
Joined: 28 Oct 2005 07:28

#8 Post by hansolo » 06 Dec 2007 14:22

What development board do you use to test your programs?

Did you develop your own board?

Hansolo
PIC Rules!!

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#9 Post by yo2lio » 06 Dec 2007 20:32

No, I use LV18FJ board from Mikroelektronika. Thanks to Zoran.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

hansolo
Posts: 344
Joined: 28 Oct 2005 07:28

#10 Post by hansolo » 12 Dec 2007 12:11

yo2lio wrote:No, I use LV18FJ board from Mikroelektronika. Thanks to Zoran.
Did you get it free from mE since you have done so much work in the serial ethernet area?

You must be one of the first to use the board.

Hansolo
PIC Rules!!

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#11 Post by yo2lio » 12 Dec 2007 12:17

hansolo wrote:Did you get it free from mE since you have done so much work in the serial ethernet area?
:D
hansolo wrote:You must be one of the first to use the board.
The LV18FJ board is GREAT !
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

BarryP
Posts: 517
Joined: 02 Apr 2007 03:57
Location: New Zealand

#12 Post by BarryP » 26 Dec 2007 21:58

Hi
Did your board come with a 41.6667 MHz Xtal ?
Just received my board a few days ago & it has a 25mhz.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#13 Post by yo2lio » 26 Dec 2007 23:24

Board have 25 MHZ Xtal (this frequency is used by Ethernet).

And MCU clock is 41.666667 Mhz.

For this you must set in configuration OSC HS PLL and at beginning of program OSCTUNE = %01000000
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

BarryP
Posts: 517
Joined: 02 Apr 2007 03:57
Location: New Zealand

#14 Post by BarryP » 27 Dec 2007 05:38

Ah Ha !!
A Little More of the Cloud Lifts
So Much to Read & Learn !
Thanks Heaps For the Lib's + Examples :D
It's great to have something that just works 'Out Of The Box'

Regards
Barry

BarryP
Posts: 517
Joined: 02 Apr 2007 03:57
Location: New Zealand

#15 Post by BarryP » 04 Jan 2008 00:17

Hi
Havin lotsa fun with this stuff !!
I was using your mini web server example as the basis for my own project.
when asking for data using
"var jsel = document.createElement('SCRIPT');"+
"jsel.type = 'text/javascript';"+
"jsel.src = 'value.js';"+
"document.body.appendChild (jsel);"+
I got weird results.
The fist time it was executed , there was no data , but the data WAS sent.
The second time it was executed the data was actually the first lot of data.
I tried heaps of diff things in the jscript to solve this , but All to no avail.

After a lot of web searching , I bumped into AJAX
Highly recommend looking into this if ya haven't already

Post Reply

Return to “mikroBasic General”