Академический Документы
Профессиональный Документы
Культура Документы
OK. ETHERNET
Serial Ethernet module connected to
EasyAVR5A Development System
By Srdjan Tomic
For example, our local network parameters After the web browser GET request is re-
are as follows: ceived, sent from your computer to the con-
MikroElektronika - Software Department
trol system IP address, the microcontroller
IP : 192.168.20.60 (Control System address) will respond with a web page stored in its
All you need is a Atmega 32 microcontroller memory. This page will then be automati-
and an ENC28J60 serial Ethernet chip. This DNS : 192.168.20.1 (Domain Name System address)
cally displayed on the computer screen by
chip is a great solution for other microcontrol- GATEWAY : 192.168.20.6 (Gateway address) the browser.
ler families as well such as PIC, dsPIC etc. The SUBNET : 255.255.255.0 (Subnet mask) When the ON command is received, the
CviLux CJCBA8HF1Y0 RJ-45 connector is used LED connected to the PORTA.0 will be
for connection to the Ethernet network. An Step 3. Disable PORTA analogue inputs. turned on.
LED connected to the microcontroller PORTB. The microcontroller pin should be Likewise, when the OFF command is re-
pin0 simulates a home appliance we want to cleared and configured as an out- ceived the LED will be turned off. If you
control. put. have a relay instead of LED, it is possible to
control any appliance such as lighting, se-
The mikroBASIC for AVR compiler con- Step 4. Initialize the SPI module of the curity system, heating system etc.
tains the SPI_Ethernet library that will Atmega 32 microcontroller.
considerably simplify the process of writ- The control of any home appliance consists
ing a program for the microcontroller. By Step 5. Initialize the Serial Ethernet mod- of entering control system IP address in the
using a few routines from this library, it is ule chip ENC28J60. web browser and specifying the desired
possible to create the program that will commands.
enable electrical appliances in your home Step 6. Write the code within the Of course, it is possible to control more than
to be controlled via a web browser. Spi_Ethernet_userTCP function
that will, after receiving command
It is necessary to perform the following op- via web browser, turn on/off the
erations within the program: LED connected to the PORTA.0.
Step 1. Create an html page to run the Step 7. Read received data in an endless
microcontroller through. Import loop.
it in the code as a string.
The most important part of the program
Step 2. Set IP, DNS, Gateway addresses is the Spi_Ethernet_userTCP function,
and Subnet mask obtained from processing all received commands Figure 1. MikroElektronikas Serial Ethernet
your internet provider. module with ENC28J60 chip
WEB
Router
Schematic 1. Connecting the Serial Ethernet module to a Atmega 32 Example 1: Program to demonstrate control over Ethernet
program enc_ethernet
dim myMacAddr as byte[6] my MAC address
one microcontroller pin, which enables you to govern a large number of appli- myIpAddr as byte[4]
gwIpAddr as byte[4]
my IP address
gateway (router) IP address
ipMask as byte[4] network mask (for example : 255.255.255.0)
ances or complete home automation system as well. dnsIpAddr as byte[4] DNS server IP address
indexPage as string[523] default html page
getRequest as byte[20] HTTP request buffer
httpHeader as string[30] HTTP header
The screendump illustrates httpMimeTypeHTML as string[13]
httpMimeTypeScript as string[14]
HTML MIME type
TEXT MIME type
the web page displayed by mE ehternet NIC pinout
SPI_Ethernet_Rst as sbit at PORTB.B0
the web browser after en- SPI_Ethernet_CS as sbit at PORTB.B1
SPI_Ethernet_Rst_Direction as sbit at DDRB.B0
tering the control system IP SPI_Ethernet_CS_Direction as sbit at DDRB.B1
end ethernet NIC definitions
address. In our example, ON sub function putString(dim s as ^byte) as word
result = 0
and OFF button clicks cause while(s^ <> 0)
Spi_Ethernet_putByte(s^)
the LED to be turned on Inc(s)
Inc(result)
wend
and off, thus simulating the end sub
Atmel, logo and combinations thereof, AVR and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other
terms and product names may be trademarks of others.