Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
OK. ETHERNET
Serial Ethernet module connected to
EasyPIC5 Development System
By Srdjan Tomic
For example, our local network parameters After the web browser “GET” request is re-
MikroElektronika - Software Department
are as follows: ceived, sent from your computer to the con-
trol system IP address, the microcontroller
All you need is a PIC18F4520 microcontroller will respond with a web page stored in its
and an ENC28J60 serial Ethernet chip. This IP : 192.168.20.60 (Control System address)
DNS : 192.168.20.1 (Domain Name System address)
memory. This page will then be automati-
chip is a great solution for other microcon- cally displayed on the computer screen by
troller families as well such as AVR, dsPIC etc. GATEWAY : 192.168.20.6 (Gateway address) the browser.
The CviLux CJCBA8HF1Y0 RJ-45 connector SUBNET : 255.255.255.0 (Subnet mask) When the ON command is received, the
is used for connection to the Ethernet net- LED connected to the PORTB.pin0 will be
work. An LED connected to the microcontrol- Step 3. Disable PORTB analogue inputs. turned on.
ler PORTB.0 simulates a home appliance we The microcontroller pin should be Likewise, when the OFF command is re-
want to control. cleared and configured as an out- ceived the LED will be turned off. If you
put. have a relay instead of LED, it is possible to
The mikroPASCAL for PIC compiler con- control any appliance such as lighting, se-
tains the SPI_Ethernet library that will Step 4. Initialize the SPI module of the curity system, heating system etc.
considerably simplify the process of writ- PIC18F4520 microcontroller.
ing a program for the microcontroller. By The control of any home appliance consists
using a few routines from this library, it is Step 5. Initialize the Serial Ethernet mod- of entering control system IP address in the
possible to create the program that will ule chip ENC28J60. web browser and specifying the desired
enable electrical appliances in your home commands.
to be controlled via a web browser. Step 6. Write the code within the
Spi_Ethernet_userTCP function
It is necessary to perform the following op- that will, after receiving command
erations within the program: via web browser, turn on/off the
LED connected to the PORTB.0.
Step 1. Create an html page to run the
microcontroller through. Import Step 7. Read received data in an endless
it in the code as a string. loop.
Step 2. Set IP, DNS, Gateway addresses The most important part of the program
and Subnet mask obtained from is the Spi_Ethernet_userTCP function, Figure 1. MikroElektronika’s Serial Ethernet
your internet provider. processing all received commands module with ENC28J60 chip
WEB
Router
Code for this example written for PIC® microcontrollers in C, Basic and Pascal as well as begin
ro
the programs written for dsPIC® and AVR® microcontrollers can be found on our web
result := 0;
end;
// back to the library with the length of the UDP reply
mik IC
site: www.mikroe.com/en/article/ end.
for P
Microchip®, logo and combinations thereof, PIC® and others are registered trademarks or trademarks of Microchip Corporation or its subsidiaries.
Other terms and product names may be trademarks of others.