avr web server
DESCRIPTION
avr webserver enc28j60TRANSCRIPT
March 2009
AVR MICROCONTROLLER BASED WEB SERVER
Submitted by
Vishram Mishra
in partial fulfillment of requirement of the Degree of
Bachelor of Technology (B.Tech)
in
COMPUTER SCIENCE AND ENGINEERING
SCHOOL OF ENGINEERING
COCHIN UNIVERSITY OF SCIENCE AND TECHNOLOGY
KOCHI- 682022
COCHIN UNIVERSTY OF SCIENCE AND TECHNOLOGYDIVISION OF COMPUTER ENGINEERING
CENTRE FOR ENGINEERING STUDIESCOCHIN-682022
Certficate
Certified that this is a bonafide record of the project work entitled
“AVR MICROCONTROLLER BASED WEB SERVER”
done by the following student
VISHRAM MISHRA
Of the VIthsemester ,Computer Science and Engineering in the year 2009 in partial
fulfilment of the requirements to the award of Degree Bachelor of Technology in
Computer Science and Engineering of Cochin Universty of Science and Technology.
Mr.Vinod Kumar P.P. Dr. David PeterProject Guide Head of the Department
Place:KochiDate:30.03.2009
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ACKNOWLEDGEMENT
I take this occasion to thank God, Almighty for blessing me with
his grace and taking my endeavor to a successful culmination. I extend
my sincere and heart felt thanks to my esteemed guide, Mr. Vinod Kumar
P.P. for providing me with the right guidance and advice at the crucial
junctures and for showing me the right way. I extend my sincere thanks to
my respected head of the division Dr. David Peter, for allowing me to use
the facilities available. I would like to thank the other faculty members
also ,at this occasion. Last but not least, I would like to thank my friends
and family for the support and encouragement they have given to me
during the course of my work.
Vishram Mishra
Abstract
This project aims at implementing a web server over an AVR
Microcontroller. The web server will host a small web page which will be
stored in the Microcontroller’s Flash memory. Through the interface of
the web page, a user can control the devices attached to the
Microcontroller. Additionally an LCD is also interfaced with the
Microcontroller to provide user interface through the use of four keys.
I am sure that this project will be helpful to control the devices remotely
by embedding AVR web server onto each of the devices to be controlled.
ii
LIST OF TABLES
1 Two pair crossover cable pin outs..............................................14
2 SPI pins of ATmega32 Microcontroller.....................................16
3 Classes of IP...............................................................................25
4 HTTP Methods...........................................................................35
5 HTTP status code.......................................................................35
iii
LIST OF FIGURES
1.1 Monitoring Home Equipment from the Office....................................2
1.2 Implementation of Web Server using 8-bit Microcontroller….............2
2.1 Pin Configuration of ATmega32 Microcontroller.................................5
2.2 Block Diagram of ATmega32...............................................................6
2.3 AVR CPU Core.....................................................................................8
2.4 Pin Configuration of ENC28J60...........................................................9
2.5 Block diagram of ENC28J60..............................................................10
2.6 Connection of ENC28J60 with Microcontroller.................................11
2.7 MagJack...............................................................................................12
2.8 Schematic of Integrated Magnetics RJ-45 Jack..................................12
2.9 RJ-45 Connector..................................................................................13
2.10 Interaction between different devices supporting SPI.........................15
2.11 Pins of LM 7805..................................................................................17
2.12 Pins of LM 317....................................................................................17
2.13 JHD 162A LCD display......................................................................18
2.14 AVR Web Server Interfacing..............................................................19
2.15 TCP/IP protocol stack.........................................................................20
2.16 Example of various protocols involvesd.............................................22
2.17 Encapsulation of data as it goes down the protocol stack...................24
2.18 Five different classes of internet addresses.........................................25
2.19 IP headers fields................................................................................26
2.20 Encapsulation of TCP data in IP datagram.........................................29
2.21 TCP header fields................................................................................30
iv
2.22 Ethernet Encapsulation.......................................................................32
2.15 Example POST request.......................................................................34
2.15 HTTP response message.....................................................................34
4.1 AVR web server screen shot…...........................................................44
7.1 Select New Project in AVR Studio....................................................47
7.2 Select AVR GCC in AVR Studio......................................................48
7.3 Select Microcontroller type................................................................48
7.4 Write the program in the editor..........................................................49
7.5 Setup the interface of PonyProg .........................................................50
7.6 Select the appropiate hardware programmer type..............................50
7.7 Write appropriate configuration bits..................................................51
7.8 Burn the code onto the Microcontroller.............................................51
7.9 Error message of PonyProg................................................................52
7.10 Parallel Port Programmer Hardware..................................................53
v
TABLE OF CONTENTS
ACKNOWLEDGEMENT....................................................................i
ABSTRACT.........................................................................................ii
LIST OF TABLES...............................................................................iii
LIST OF FIGURES..............................................................................iv
TABLE OF CONTENTS.....................................................................vi
1. INTRODUCTION.....................................................................................1
1.1 Embedded Web Server.........................................................................1
1.2 8-bit Microcontroller Based Web Server.............................................1
2. SYSTEM STUDY.....................................................................................4
2.1 HARDWARE...........................................................................................4
2.1.1 Atmel ATmega32 Microcontroller.........................................................4
2.1.1.1 PIN Configuration.....................................................................5
2.1.1.2 Overview...................................................................................5
2.1.1.3 AVR CPU Core.........................................................................7
2.1.2 ENC28J60 Ethernet Controller...............................................................9
2.1.2.1 Pin Configuration......................................................................9
2.1.2.2 Overview...................................................................................9
2.1.3 Integrated Magnetics RJ-45 Jack ..........................................................12
2.1.3.1 Overview.................................................................................12
2.1.3.2 AutoMDIX ..............................................................................12
2.1.3.3 Cabling....................................................................................13
2.1.4 SPI (Serial Peripheral Interface) ..........................................................14
2.1.4.1 Overview.................................................................................14
vi
2.1.4.2 Data transmission between Master and Slave................................15
2.1.4.3 Pins of the SPI.........................................................................16
2.1.5 Miscellaneous Components..................................................................17
2.1.5.1 LM 7805 IC.............................................................................17
2.1.5.2 LM 317 IC ..............................................................................17
2.1.5.3 JHD-162A LCD Display.........................................................18
2.1.6 Interfacing of Different Components....................................................19
2.2 NETWORKING....................................................................................20
2.2.1 TCP/IP Protocol Suite................................................................20
2.2.1.1 Application Layer..........................................................20
2.2.1.2 Transport Layer.............................................................21
2.2.1.3 Network Layer..............................................................21
2.2.1.4 Link Layer.....................................................................21
2.2.2 Combining all.............................................................................22
2.2.3 Port Numbers..............................................................................23
2.2.4 Encapsulation........................................................................................23
2.2.5 Internet Addresses......................................................................25
2.2.6 IP (Internet Protocol) .................................................................26
2.2.6.1 IP Header.......................................................................26
2.2.7 TCP (Transmission Control Protocol) .......................................28
2.2.7.1 TCP Header...................................................................29
2.2.8 Ethernet Encapsulation...............................................................32
2.2.9 HTTP (Hyper Text Transfer Protocol) ......................................33
2.2.9.1 HTTP Message .............................................................33
2.2.9.2 HTTP Methods..............................................................34
2.2.9.3 Status Codes..................................................................34
vii
viii
2.2 Software Package..................................................................................36 2.3.1 WinAVR....................................................................................36
2.3.2 AVR Studio version 4................................................................36
2.3.3 PonyProg....................................................................................36
3. Software Code...................................................................................38
3.1 Header Files..................................................................................38
3.1.1 enc28j60.h........................................................................38
3.1.2 arp.h..................................................................................38
3.1.3 ip.h....................................................................................39
3.1.4 tcp.h..................................................................................39
3.1.5 http.h ................................................................................40
3.1.6 menu.h..............................................................................41
3.1.7 main.h...............................................................................42
4. EXECUTION.....................................................................................43
4.1 Testing and Debugging.......................................................43
4.2 Procedure for Execution......................................................43
5. CONCLUSION..................................................................................45
REFERENCES..................................................................................46
APPENDICES...................................................................................47
AVR Web Server
CHAPTER 1
INTRODUCTION
This chapter provides an introduction to the embedded web server and their
implementation. Their typical application is explained with the help of examples.
Section 1.2 gives a brief explanation of implementation of embedded web server
based on Atmel AVR microcontroller.
1.1 Embedded Web Server
Small systems to large systems may provide an interface and control via the
onboard switches or via IR or RF based remote control. But what if the User who
wants to control a device, is out of reach of the device or is at another part of world.
There are other methods developed to control the devices remotely, but each
technique requires some new implementations to be done. Here we use the existing
technique of Internet Web based HTTP protocol with TCP/IP protocol suite to control
the devices. Embedding a web application in a system is termed as embedded web
server.
Suppose an Embedded Web Server is embedded in several units in a house as
shown in figure 1.1. Every server is connected to the network. A computer located at
home as on figure controls all devices and can receive requests from other computers
on the Internet. The web server is identified by its unique IP address and can be
controlled remotely from anywhere in the world.
A computer located in an office may send a request to turn off the Refrigerator
located at home via Internet. The web server will be running an HTTP application
through the interface of which the user can control and monitor the devices.
1.2 8-bit Microcontroller based Web Server
It is not a new technique to control or monitor a device via web based
interface. Many of the day-to-day life devices are already using this technique. For
example a printer connected via an Ethernet link, Remote Surveillance Camera etc
provides such services. But all these devices use 32 bit-processors like ARM, AVR32,
Division of Computer Engineering, S.O.E. 1
AVR Web Server
COLDFIRE, POWER ARCHITECTURE etc. The usage of these 32-bit
microprocessor increases the cost of an application. For a simple Embedded Web
Server we can also use 8-bit Microcontrollers!
Fig 1.1: Monitoring Home Equipment from the Office
The following high level diagram explains how we can implement a web server on an
8-bit Microcontroller.
Fig 1.2: Implementation of Web Server using 8-bit Microcontroller
Division of Computer Engineering, S.O.E. 2
AVR Web Server
Fig 1.2 shows how an 8-bit microcontroller is interfaced with an Ethernet controller
which controls the physical layer of TCP/IP stack model. The standard RJ-45
connector is used for interfacing the Ethernet controller with a PC. When a request is
made from the web browser it is transferred as raw bits through the Ethernet lines and
is then fetched by the Ethernet Controller. The Ethernet Controller then passes this
information above to it that is to the Microcontroller. The program running on the
microcontroller then decodes the request and performs the required operation.
Usage of 8-bit AVR Microcontroller simplifies the design step. One of the most
popular 8-bit AVR Microcontroller is ATmega32 which has 32 Kb of Flash memory,
large enough for storing a small web page.
In the next coming sections we will perform system study and deals with various
hardware and software requirements of the project.
Division of Computer Engineering, S.O.E. 3
AVR Web Server
CHAPTER 2
SYSTEM STUDY
In this section we perform the system study by studying and analyzing various
hardware, software requirement and constraints. Section 2.1 deals with the hardware
requirements and explains the constraints associated with some of the hardware. The
constraints are removed by selecting different hardware. Section 2.2 deals with the
study of networking which is required for writing the various protocols. These
protocols include TCP, IP, HTTP, ICMP etc. In section 2.3 we give a brief
introduction to the software packages used.
2.1 Hardware Study
To implement a web server on an 8 bit Microcontroller we will use AVR
microcontroller because of its high throughput. Also ENC28J60 Ethernet controller is
used instead of Realtek family of Ethernet controller because of low number of pins
which provides an easy interfacing with 8 bit Microcontroller.
We will discuss some of the following important components in brief (For further
study their datasheet can be referred):
Atmel ATmega32 Microcontroller.
ENC28J60 Ethernet Controller.
Integrated Magnetics RJ -45 Jack.
Along with these we will also discuss some of the miscellaneous components used
and about the SPI (Serial Peripheral Interfacing) used to interface ATmega32 with
ENC28J60.
2.1.1 Atmel ATmega32 Microcontroller
A Microcontroller is a highly integrated chip that contains all the components
comprising a controller. Typically this includes a CPU, RAM, some form of ROM,
Division of Computer Engineering, S.O.E. 4
AVR Web Server
I/O ports, and timers. The reason for using ATmega32 as an 8-bit Microcontroller in
our application is because of its high throughput and SPI(Serial Peripheral Interface)
interfacing. The SPI interfacing provides serial interface with the device and hence
lowering the number of address and data lines used.
2.1.1.1 PIN Configuration
Fig 2.1: Pin Configuration of ATmega32 Microcontroller
2.1.1.2 Overview
The ATmega16 is a low-power CMOS 8-bit microcontroller based on the
AVR enhanced RISC architecture. By executing powerful instructions in a single
clock cycle, the ATmega16 achieves throughputs approaching 1 MIPS per MHz
allowing the system designer to optimize power consumption versus processing
speed. The block diagram is shown in fig 2.2.
Division of Computer Engineering, S.O.E. 5
AVR Web Server
Fig 2.2: Block Diagram of ATmega32
The AVR core combines a rich instruction set with 32 general purpose
working registers. All the 32 registers are directly connected to the Arithmetic Logic
Unit (ALU), allowing two independent registers to be accessed in one single
instruction executed in one clock cycle. The resulting architecture is more code
efficient while achieving throughputs up to ten times faster than conventional CISC
microcontrollers.
Division of Computer Engineering, S.O.E. 6
AVR Web Server
The ATmega32 provides the following main features:
Up to 16 MIPS Throughput at 16 MHz
On-chip 2-cycle Multiplier
32K Bytes of In-System Self-programmable Flash program memory
1024 Bytes EEPROM
2K Byte Internal SRAM
In-System Programming by On-chip Boot Program
JTAG (IEEE std. 1149.1 Compliant) Interface
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
One 16-bit Timer/Counter with Separate Prescalers, Compare Mode, and
Capture Mode
Real Time Counter with Separate Oscillator
Four PWM Channels
8-channel, 10-bit ADC
Byte-oriented Two-wire Serial Interface
Programmable Serial USART
Master/Slave SPI Serial Interface
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down,
Standby and Extended Standby
2.1.1.3 AVR CPU Core
The main function of the CPU core is to ensure correct program execution.
The CPU must therefore be able to access memories, perform calculations, control
peripherals, and handle interrupts. Figure 2.3 represents a typical AVR CPU core.
Division of Computer Engineering, S.O.E. 7
AVR Web Server
In order to maximize performance and parallelism, the AVR uses Harvard
architecture – with separate memories and buses for program and data. Instructions in
the program memory are executed with a single level pipelining. While one
instruction is being executed, the next instruction is pre-fetched from the program
memory. This concept enables instructions to be executed in every clock cycle. The
program memory is In-System Reprogrammable Flash memory.
Fig 2.3: AVR CPU Core
The fast-access Register File contains 32 x 8-bit general purpose working
registers with a single clock cycle access time. Six of the 32 registers can be used as
three 16-bit indirect address register pointers for Data Space addressing – enabling
efficient address calculations.
The ALU supports arithmetic and logic operations between registers or
between a constant and a register. Single register operations can also be executed in
the ALU. After an arithmetic operation, the Status Register is updated to reflect
information about the result of the operation.
Division of Computer Engineering, S.O.E. 8
AVR Web Server
2.1.2 ENC28J60 Ethernet Controller
An Ethernet Controller is a device used to implement Ethernet Protocol. The
reason for using ENC28J60 as an Ethernet Controller in our application is because its
supports SPI(Serial Peripheral Interface) interfacing. The SPI interfacing provides
serial interface with the device and hence lowers the number of address and data lines
used.
2.1.2.1 Pin Configuration
Fig 2.4: Pin Configuration of ENC28J60
2.1.2.2 Overview
The ENC28J60 is a stand-alone Ethernet controller with an industry standard
Serial Peripheral Interface (SPI). It is designed to serve as an Ethernet network
interface for any controller equipped with SPI. The ENC28J60 meets all of the IEEE
802.3 specifications. It incorporates a number of packet filtering schemes to limit
incoming packets. It also provides an internal DMA module for fast data throughput
and hardware assisted checksum calculation, which is used in various network
protocols. Communication with the host controller is implemented via an interrupt pin
and the SPI, with clock rates of up to 20 MHz. Two dedicated pins are used for LED
Division of Computer Engineering, S.O.E. 9
AVR Web Server
link and network activity indication. A simple block diagram of the ENC28J60 is
shown in figure 2.5. With the ENC28J60, two pulse transformers and a few passive
components are all that is required to connect a microcontroller to an Ethernet
network.
Fig 2.5: Block diagram of ENC28J60
The ENC28J60 consists of seven major functional blocks:
1. An SPI interface that serves as a communication channel between the host
controller and the ENC28J60.
2. Control Registers which are used to control and monitor the ENC28J60.
3. A dual port RAM buffer for received and transmitted data packets.
4. An arbiter to control the access to the RAM buffer when requests are made from
DMA, transmit and receive blocks.
5. The bus interface that interprets data and commands received via the SPI interface.
6. The MAC (Medium Access Control) module that implements IEEE 802.3
compliant MAC logic.
7. The PHY (Physical Layer) module that encodes and decodes the analog data that is
present on the twisted pair interface.
Division of Computer Engineering, S.O.E. 10
AVR Web Server
Following are the features of ENC28J60:
IEEE 802.3 compatible Ethernet controller
Integrated MAC and 10BASE-T PHY
Supports one 10BASE-T port with automatic polarity detection and correction
Supports Full and Half-Duplex modes
Programmable automatic retransmit on collision
Programmable padding and CRC generation
Programmable automatic rejection of erroneous packets
SPI Interface with clock speeds up to 20 MHz
A typical application circuit using the device is shown in the following figure 2.6
Fig 2.6: Connection of ENC28J60 with Microcontroller
Here only five lines are required to interface the Microcontroller with the
ENC28J60. Whenever a data packet is received by ENC28J60 it sends an interrupt to
the Microcontroller. Based upon the timing of the interrupt the main program checks
the packet received and check to which protocol it belong. Based on that, appropriate
handling is done.
Division of Computer Engineering, S.O.E. 11
AVR Web Server
2.1.3 Integrated Magnetics RJ-45 Jack
2.1.3.1 Overview
An integrated Magnetics RJ-45 Jack includes the required Pulse Magnetics
within the RJ-45 Jack itself. Generally a pulse transformer is used in conjunction with
the RJ 45 jack to maintain the input pulse waveform and power while transforming
the source impedance to a value approximating the load impedance. The use of
Integrated Magnetics RJ-45 Jack excludes the overhead of using Pulse Transformer in
the Circuit.
A typical circuit inside of a Integrated Magnetics
RJ-45 is shown in figure 2.8. Figure 2.7 shows a typical
Integrated Magnetics RJ-45 jack called as MagJack. The
MagJack also provide a feature called as AutoMDIX.
Fig 2.8: Schematic of Integrated Magnetics RJ-45 Jack
Division of Computer Engineering, S.O.E. 12
AVR Web Server
2.1.3.2 AutoMDIX
An Ethernet has one wire pair for transmit (Tx) and one for receive (Rx). A
Hub/Switch will amplify the signal and cross connect Tx of one network element with
Rx of the other. If we want to connect the AVR web server directly to our computer
without a Hub/Switch in-between then we will normally need a cross connect
Ethernet cable. A cross connect cable is a cable where Tx and Rx are swapped on one
side. The AutoMDIX magjack has some additional logic inside which will
automatically swap the cable for us if needed. In other words we can always use a
straight cable no matter if weconnect to a Hub/Switch or directly to a computer.
2.3.3 Cabling
ENC28J60 supports 10BASE-T transmission which means 10 Mbps of data
transfer rate. BASE is short for baseband, meaning that there is no frequency-division
multiplexing (FDM) or other frequency shifting modulation in use i.e. each signal has
full control of wire, on a single frequency. T designates twisted pair cable, where the
pairs of wires are twisted together for purposes of reducing crosstalk
The cabling used for the transmission uses
8 position modular connectors (shown in figure
2.9), usually called RJ-45 in the context of Ethernet
over twisted pair. The cables usually used are four-
pair or above twisted pair cable. This standard
supports both full-duplex and half-duplex
communication. According to the standards, this
operates over distances of 'up to 100 meters'.
To connect two computers directly together without a switch, an Ethernet crossover
cable is often used. Two pair crossover cable pin outs are shown in the table 1. This
table shows the connection at both the ends of the cable. This constraint can be
removed by using the AutoMDIX feature of a RJ 45 Jack.
Division of Computer Engineering, S.O.E. 13
AVR Web Server
Table 1: Two pair crossover cable pin outs
2.1.4 SPI (Serial Peripheral Interface)
2.1.4.1 Overview
An ATmega 32 Microcontroller uses SPI (Serial Peripheral Interface) to
effectively communicate with the Ethernet controller ENC28J60. The usage of SPI
provides serial communication thus eliminating large number of lines used for data
and addressing purpose. The SPI allows high-speed synchronous data transfer
between the AVR and peripheral devices or between several AVR devices. On most
parts the SPI has a second purpose where it is used for In System Programming (ISP).
The interconnection between two SPI devices always happens between a
master device and a slave device. Compared to some peripheral devices like sensors
which can only run in slave mode, the SPI of the AVR can be configured for both
master and slave mode. The mode the AVR is running in is specified by the settings
of the master bit (MSTR) in the SPI control register (SPCR). Special considerations
about the SS pin have to be taken into account.
Division of Computer Engineering, S.O.E. 14
AVR Web Server
The master is the active part in this system and has to provide the clock signal a serial
data transmission is based on. The slave is not capable of generating the clock signal
and thus can not get active on its own. The slave just sends and receives data if the
master generates the necessary clock signal. The master however generates the clock
signal only while sending data. That means that the master has to send data to the
slave to read data from the slave.
2.1.4.2 Data transmission between Master and Slave
The interaction between a master and a slave AVR is shown in the figure 2.10
Fig 2.10: Interaction between different devices supporting SPI
Two identical SPI units are displayed. The left unit is configured as master
while the right unit is configured as slave. The MISO, MOSI and SCK lines are
connected with the corresponding lines of the other part. The mode in which a part is
running determines if they are input or output signal lines. Because a bit is shifted
from the master to the slave and from the slave to the master simultaneously in one
clock cycle both 8-bit shift registers can be considered as one 16-bit circular shift
register. This means that after eight SCK clock pulses the data between master and
slave will be exchanged. The system is single buffered in the transmit direction and
double buffered in the receive direction.
Division of Computer Engineering, S.O.E. 15
AVR Web Server
This influences the data handling in the following ways:
1. New bytes to be sent can not be written to the data register (SPDR) / shift register
before the entire shift cycle is completed.
2. Received bytes are written to the Receive Buffer immediately after the transmission
is completed.
3. The Receive Buffer has to be read before the next transmission is completed or data
will be lost.
4. Reading the SPDR will return the data of the Receive Buffer.
After a transfer is completed the SPI Interrupt Flag (SPIF) will be set in the SPI Status
Register (SPSR). This will cause the corresponding interrupt to be executed if this
interrupt and the global interrupts are enabled. Setting the SPI Interrupt Enable (SPIE)
bit in the SPCR enables the interrupt of the SPI while setting the I bit in the SREG
enables the global interrupts.
2.1.4.3 Pins of the SPI
The SPI consists of four different signal lines. These lines are the shift clock
(SCK), the Master Out Slave In line (MOSI), the Master In Slave Out line (MISO)
and the active low Slave Selectline (SS). When the SPI is enabled, the data direction
of the MOSI, MISO, SCK and SS pins are overridden according to the following table
2.
Table 2: SPI pins of ATmega32 Microcontroller
Division of Computer Engineering, S.O.E. 16
AVR Web Server
2.1.5 Miscellaneous Components:
2.1.5.1 LM 7805 IC
LM7805 is a three-terminal positive voltage regulator employ built-in current
limiting, thermal shutdown, and safe-operating area protection which makes them
virtually immune to damage from output overloads. Here we use LM 7805 for getting
an output of 5V required by ATmega32 Microcontroller. Figure 2.11 shows the pin
layout of LM7805 IC.
Fig 2.11: Pins of LM 7805
2.1.5.2 LM 317 IC
LM317 is an adjustable 3-terminal positive voltage regulator capable of
supplying in excess of 1.5A over a 1.2V to 37V output range. They are exceptionally
easy to use and require only two external resistors to set the output voltage. Further,
both line and load regulation is better than standard fixed regulators. Here we use LM
317 voltage regulator for getting an output of 3.3 V required by ENC28J60 IC. .
Figure 2.12 shows the pin layout of LM317 IC.
Fig 2.12: Pins of LM 317
Division of Computer Engineering, S.O.E. 17
AVR Web Server
2.1.5.3 JHD-162A LCD Display
An LCD display offers high flexibility to user to display the required data on
it. It may be also used for debugging purpose of the program i.e. by checking which
all subroutines are executed by displaying the value on LCD display. In our case a
16x2 alphanumeric LCD display is used to display the current AVR IP, the ADC
value (if connected) and temperature. An LCD driver is a link between the
microcontroller and LCD. The JHD 162A LCD display uses driver HD44780U. The
header file included in the program depends upon the LCD display driver used.
Figure 2.13 shows a JHD 162A LCD display
Fig 2.13: JHD 162A LCD display
Division of Computer Engineering, S.O.E. 18
AVR Web Server
2.1.6 Interfacing of Different Components
The following figure shows the main interfacing of AVR web server:
Fig 2.14: AVR Web Server Interfacing
Division of Computer Engineering, S.O.E. 19
AVR Web Server
2.2 Networking
Before we can actually write a program for ATmega32 microcontroller we
must have knowledge about TCP/IP protocol stack, Ethernet frame structure, Web
browser protocol (HTTP) etc. We will discuss these one by one in this section.
2.2.1 TCP/IP Protocol Suite
The TCP/IP protocol suite allows computers of all sizes, running different
operating systems, to communicate with each other. It forms the basis for what is
called the worldwide Internet, a Wide Area Network (WAN) of several million
computers.
TCP/IP Suite Layers: The TCP/IP protocol suite is a combination of different
protocols at various layers. TCP/IP is normally considered to be a 4-layer system as
shown in figure below (fig. 2.15).
. Fig 2.15: TCP/IP protocol stack
2.2.1.1 Application Layer
The Application layer handles the details of a particular application. Common
TCP/IP applications include:
• Telnet for remote login
• Browser support for displaying web pages
• File transfer applications
• E-mail applications
Division of Computer Engineering, S.O.E. 20
AVR Web Server
The three lower layers do not know anything about the specific application and only
take care of communications details.
2.2.1.2 Transport Layer
TCP is responsible for a reliable flow of data between two hosts. Typically,
TCP divides data passed to it from the application into appropriately sized chunks for
the network layer below, acknowledging received packets that are sent and
retransmits lost packets. Since this reliable, flow of data is provided by the Transport
Layer, the Application Layer above can ignore these details.
UDP is a much simpler service to the Application Layer. It sends packets of
data called datagrams from one host to the other, but with no guarantee that the
datagrams reach the other end. Desired reliability must be added by the application
Layer.
2.2.1.3 Network Layer
This layer is sometimes called the Internet Layer. It handles the movements of
packets around the network. Routing of packets, for example, takes place here. IP
(Internet Protocol) and ICMP (Internet Control Message Protocol) provides the
Network Layer in the TCP/IP Protocol Suite.
2.2.1.4 Link Layer
Data-link or Network Interface Layer is another common name of this layer.
The Link Layer normally includes the device driver in the operating system and the
corresponding network interface (card) in the computer. Together they handle all the
hardware details of physically interfacing with the cable.
2.2.2 Combining all
Division of Computer Engineering, S.O.E. 21
AVR Web Server
Figure 2.16 shows an example that includes two hosts on a Local Area Network
(LAN) such as Ethernet, using HTTP.
Fig 2.16: Example of various protocols involved
One side represents the client, and the other the server. The server provides
some type of service to clients, in this case, access to web pages on the server host.
Each layer has one or more protocols for communicating with its peer at the same
layer. One protocol, for example, allows the two TCP layers to communicate, and
another protocol lets the two IP layers communicate.
The Application Layer is normally a user-process while the lower three layers
are usually implemented in the kernel (the operating system).
Division of Computer Engineering, S.O.E. 22
AVR Web Server
2.2.3 Port Numbers
Different applications can use TCP or UDP at any time. The Transport layer
protocols store an identifier in the headers they generate to identify the application.
Both TCP and UDP use 16-bit port numbers to identify applications. TCP and UDP
store the source port number and the destination port number in those respective
headers. Servers are normally known by their well-known port number. Every TCP/IP
implementation with a FTP server provides that service on TCP port 21. Every Telnet
server is on TCP port 23. Services provided by any implementation of TCP/IP have
well-known port numbers between 1 and 1023. The well-known ports are managed by
the Internet Assigned Numbers Authority (IANA).
The combination of an IP address and a port number is called a socket.
2.2.4 Encapsulation
When an application sends data using TCP, the data is sent down the protocol
stack, through each layer, until it is sent as a stream of bits across the network. Each
layer adds information to the data by prepending headers and adding trailers to the
data it receives. Figure 2.17 shows this process.
Some abbreviations:
• TCP segment: The unit of data that TCP sends to IP.
• IP datagram: The unit of data that IP sends to the network interface.
• Frame: The stream of bits that flows across the Ethernet.
IP (Internet Protocol) adds an identifier to the IP header it generates to indicate
which layer the data belongs to. IP handles this by storing an 8-bit value in its header
called the protocol field. Similarly, many different applications can be using TCP or
UDP at any time. The Transport Layer protocol stores an identifier in the header they
generate to identify the application. Both TCP and UDP use 16-bit port numbers to
identify applications.
Division of Computer Engineering, S.O.E. 23
AVR Web Server
Fig 2.17: Encapsulation of data as it goes down the protocol stack
The TCP and UDP store the source port number and the destination port
number in their respective headers. The network interface sends and receives frames
on behalf of IP, ARP, RARP. There must be some form of identification in the
Ethernet header indicating which network layer protocol generates the data. To handle
this, there is a 16- bit frame type field in the Ethernet header.
2.2.5 Internet Addresses
Every interface on the internet has a unique Internet Address (IP Address).
The addresses are 32-bit numbers. Following figure 2.18 shows the structure and the
five different classes of Internet addresses:
Division of Computer Engineering, S.O.E. 24
AVR Web Server
Fig 2.18: Five different classes of internet addresses
The 32-bit addresses are normally written as four decimal numbers, one for
each byte of the address. This notation is called dotted-decimal. Since every interface
on internet must have a unique IP address, there must be one central authority for
allocating these addresses for networks connected to the worldwide Internet. Internet
Network Information Center (NIC) is the responsible authority. Table 3 gives the
dotted decimal notation of classes of IP.
Table 3: Classes of IP
Division of Computer Engineering, S.O.E. 25
AVR Web Server
2.2.6 IP (Internet Protocol)
All TCP, UDP and ICMP data get transmitted as IP datagrams. IP provides an
unreliable, connectionless datagram delivery service. There is no guarantee that an IP
datagram successfully gets to its destination. When something goes wrong, IP has a
simple error handling algorithm: Throw away datagram and try to send an ICMP
message back to the source. Any required reliability must be provided by the upper
layers.
2.2.6.1 IP Header
Figure 2.19 shows the format of an IP datagram. The normal size of the IP
header is 20 bytes, unless options are present. The most significant bit is numbered 0
at the left, and the least significant bit of a 32-bit value is numbered 31 on the right.
The 4 bytes in the 32-bit value are transmitted in the order: bits 0 - 7, then bits 8 - 15
and so on. This is called Big-Endian byte ordering, which is the byte ordering
required for all binary integers in the TCP/IP headers as they traverse a network. This
is called the network byte order.
Fig 2.19: IP headers fields
Header length:
The header length is the number of 32-bit words (4 bytes per word) in the header,
including any options. This limits the header length to 60 bytes.
Division of Computer Engineering, S.O.E. 26
AVR Web Server
Type of Service (TOS):
The field, (TOS) is composed of a 32-bit precedence field (which is currently
ignored), 4 TOS bits, and an unused bit that must be 0. The 4 TOS bits are: minimize
delay, maximize throughput, maximize reliability and minimize monetary cost. Only
1 of these bits can be turned on. If all 4 bits are 0, it implies normal service.
Total Length:
This is the total length of the IP datagram in bytes. Using this field and the header
length field, we know where the data portion of the IP datagram starts and its length.
Since this is a 16-bit field, the maximum size of an IP datagram is 65535 bytes.
Identification:
This field uniquely identifies each datagram sent by a host. It normally increments by
One each time a datagram is sent.
Time To Live:
Time-to-live sets an upper limit on the number of routers through which datagram can
pass. It limits the lifetime of the datagram. It is initialized by the sender to some value
(often 32 or 64) and decrements by one in every router that handles the datagram.
Then this field reaches 0, the datagram is discarded, and the sender is notified with an
ICMP message. This prevents the packet from getting caught in eternal routing loops.
Protocol:
Protocol is used by IP to demultiplex incoming datagrams. It identifies which protocol
gave the data for IP to send.
Header Checksum :
The Header checksum is calculated over the IP header only. It does not cover any data
that follows the header. ICMP, UDP and TCP all have a checksum in their own
headers to cover their own header and data. Every IP datagram contains the source IP
address and the destination IP address. These are 32-bit values.
Division of Computer Engineering, S.O.E. 27
AVR Web Server
The Option Field:
This is a variable-length list of optional information for the datagrams. The options
are rarely used and not all hosts and routers support the option.
2.2.7 TCP (Transmission Control Protocol)
TCP and UDP use the same network layer (IP), but TCP provides a totally
different service to the Application Layer. TCP provides a connection-oriented,
reliable, byte stream service. The term connection-oriented means the two
applications using TCP must establish a TCP connection with each other before they
can exchange data.
TCP provides reliability by doing the following:
• The application data is broken into what TCP considers the best sized chunks to
send. This is totally different from UDP, where each write by the application generate
a UDP datagram of that size. The unit of information passed by TCP to IP is called a
segment.
• When TCP sends a segment it maintains a timer, waiting for the other end to
acknowledge reception of the segment. If an acknowledge is not received in time, the
segment is retransmitted.
• When TCP receives data from the other end of the connection, it sends an
acknowledgment. This acknowledgment is not sent immediately, but normally
delayed a fraction of a second.
• TCP maintains a checksum on its data header page. This is an end-to-end checksum
whose purpose is to detect any modifications of the data in transit. If a segment
arrives with an invalid checksum, TCP discards it and does not acknowledge
receiving it. This expects the sender to time out and retransmits.
Division of Computer Engineering, S.O.E. 28
AVR Web Server
• Since TCP segments are transmitted as IP datagrams, and since IP datagrams can
arrive out of order, TCP segments can also arrive out of order. A receiving TCP
resequences the data if necessary, passing the received data in the correct order to the
application.
• Since IP datagrams can get duplicated, a receiving TCP must discard duplicate data.
• TCP also provides flow control. Each end of a TCP connection has a finite amount
of buffer space. A receiving TCP only allows the other end to send as much data as
the receiver has buffer for. This prevents a fast host from taking the entire buffer on a
slower host.
TCP data is encapsulated in an IP datagram, as shown in fig 2.20
Fig 2.20: Encapsulation of TCP data in IP datagram
2.2.7.1 TCP Header
Figure 2.21 shows the format of the TCP header. Its normal size is 20 bytes, unless
options are present.
Sequence Number:
This identifies the byte stream of data from the sending TCP to the receiving TCP that
the first byte of data in this segment represents. TCP numbers each byte with a
sequence number. The sequence number is a 32-bit unsigned number that wraps back
around to 0 after reaching 232-1.
Division of Computer Engineering, S.O.E. 29
AVR Web Server
Fig 2.21: TCP header fields
Acknowledge Number:
This contains the next sequence number that the sender of the acknowledgment
expects to receive. This is therefore the sequence number plus 1 of the last
successfully received byte of data. This field is only valid if the ACK flag is set. The
32-bit acknowledgment number field is always part of the header, as is the ACK flag.
This field is always set and the ACK FLAG is on.
Header Length:
This gives the length of the header in 32-bit words. This is required because the length
of the options field is variable. With a 4-bit field, TCP is limited to a 60-byte header.
Without options, however, the normal size is 20 bytes.
Flag Bits:
There are six flag bits in the TCP header – one or more of them can be turned on at
the same time:
1. URG – The urgent pointer is valid.
2. ACK – The acknowledgment number is valid.
3. PSH – The receiver should pass data to the application as soon as possible.
4. RST – Reset the connection.
5. SYN – Synchronize sequence numbers to initiate a connection.
6. FIN – the sender is finished sending data.
Division of Computer Engineering, S.O.E. 30
AVR Web Server
Window Size:
TCP’s flow control is provided by each end advertising a window’s size. This is the
number of bytes, starting with the one specified by the acknowledgment number field,
that the receiver is willing to accept. This is a 16-bit field, limiting the window to
65535 bytes.
Checksum:
Checksum covers the TCP segment: the TCP header and the TCP data. This is a
mandatory field and must be calculated and stored by the sender and then verified by
the receiver.
Urgent Pointer:
The urgent pointer is valid only if the URG flag is set. This pointer is a positive offset
that must be added to the sequence number field of the segment to yield the segment
number of the last byte of urgent data. TCP’s urgent mode is a way for the sender to
transmit emergency data to the other end.
Checksum:
The most common option field is the MSS (maximum segment size). Each end of a
connection normally specifies this option on the first segment exchanged (the one sent
with the SYN flag set to establish the connection). It specifies the maximum size
segment that the sender wants to receive.
Data:
The data portion of the TCP header is optional. A header without data is used to
acknowledge received data if there is no data to be transmitted in that direction. There
are also some cases dealing with time-outs when a segment can be sent without any
data.
Division of Computer Engineering, S.O.E. 31
AVR Web Server
2.2.8 Ethernet Encapsulation
Ethernet encapsulation is performed before sending the IP datagram over the
transmission lines. A typical Ethernet frame looks like as in fig. 2.22:
Fig 2.22: Ethernet Encapsulation
Some of its fields are:
Destination Address:
This field contains the 48-bit destination MAC address.
Source Address:
This field contains the 48-bit source MAC address.
Ethernet Type:
Identifies the type of data that follows.
Division of Computer Engineering, S.O.E. 32
AVR Web Server
CRC:
Cyclic redundancy checksum used to detects errors in the rest of the frame.
Preamble:
The Ethernet frame begins with 8 byte preamble field to synchronize the sender’s
clock with the receiver clock.
Minimum Size:
For an Ethernet frame it is 46 bytes. To handle this, pad bytes are inserted to assure
that the frame is sufficiently large
2.2.9 HTTP (Hyper Text Transfer Protocol)
The HTTP protocol is a protocol that allows a (web) client to request files or
other resources from a server. Various types of requests can be sent by the client. The
most basic are the “GET” request and the “POST” request which are used to fetch and
post data, respectively. The server processes the request, returns a header containing a
status code and either a file or an HTML document attached after the header. Finally,
the server closes the connection.
2.2.9.1 HTTP Message
An HTTP message consists of requests from client to server and responses
from server to client. The message format is similar in many ways to that used by
Internet Mail and the Multipurpose Internet Mail Extension (MIME) as defined in
RFC 822 and RFC 1521.
HTTP Request Message
A request message consists of a request-line followed by some header-lines
specifying the request. Example (POST) request is shown in figure 2.23.
Division of Computer Engineering, S.O.E. 33
AVR Web Server
HTTP Response Message
The response message consists of a response-line followed by header-lines and the
entity body. The entity body is separated from the headers by a null line. Example of
(GET) response is shown in figure 2.24:
Fig 2.23: Example POST request
Fig 2.24: HTTP response message
2.2.9.2 HTTP Methods
The first word in the request line is the name of the method to be executed.
The common methods are listed in table 4.
2.2.9.3 Status Codes
Every request gets a response starting with a status line. The status line consists of the
protocol version followed by a numeric status code and its associated textual phrase.
Division of Computer Engineering, S.O.E. 34
AVR Web Server
The common HTTP/1.0 status codes are listed in table 5.
Table 4: HTTP Methods
Table 5: HTTP status code
Division of Computer Engineering, S.O.E. 35
AVR Web Server
2.3 Software Packages
In this section we will discuss in brief about the software packages used in the
project. The software packages used in the project are:
WinAVR
AVR Studio
PonyProg
2.3.1 WinAVR
WinAVR (pronounced "whenever") is a suite of executable, open source
software development tools for the Atmel AVR series of RISC microprocessors
hosted on the Windows platform. It includes the GNU GCC compiler for C and C++.
It provides libraries for various inbuilt functions.
WinAVR contains all the tools for developing of an AVR application. This
includes Programmers Notepad (editor), avr-gcc (compiler), avrdude (programmer),
avr-gdb (debugger).
2.3.2 AVR Studio version 4
AVR Studio 4 is the new professional Integrated Development Environment
(IDE) for writing and debugging AVR applications in Windows 9x/NT/2000/XP
environments. It provides a C compiler, assembler and Simulator.
2.3.3 PonyProg
A software Programmer is a program which sends the hex code generated
from the compiler/assembler to the microcontroller via Serial/Parallel/USB port link.
Division of Computer Engineering, S.O.E. 36
AVR Web Server
A hardware programmer is a circuit used to interface Microcontroller with the
Computer to burn the hex code from the computer onto the microcontroller.
PonyProg is a serial device programmer software with a user friendly GUI
framework available for Windows95/98/ME/NT/2000/XP and Intel Linux. Its purpose
is reading and writing every serial device. At the moment it supports I²C Bus,
Microwire, SPI eeprom, the Atmel AVR and Microchip PIC micro.
Division of Computer Engineering, S.O.E. 37
AVR Web Server
CHAPTER 3
SOFTWARE CODE
3.1 Header Files
The header files are written by declaring the necessary Macros and Function
into a file ending with .h extension. The real definition of the function appears in the
C program with the same file name as header file but ending with .C extension.
Most of the header files are obtained under GNU general public license and are
rewritten for our convenience. Some of these headers files are discussed here:
3.1.1 enc28j60.h
It provides the driver for ENC28J60 IC. Some of the functions defined in this
header file are:
enc28j60_init (): Used to initialize ENC28J60.
enc28j60_packet_send (): Send packet to network.
enc28j60_tx_checksum (): It adds the checksum calculated to the packet to be
send.
enc28j60_packet_receive (): check received packet and return length of data
3.1.2 arp.h
ARP (Address Resolution Protocol) is the method for finding a host's
hardware address when only its network layer address is known. Some of the
functions written in it are:
Division of Computer Engineering, S.O.E. 38
AVR Web Server
arp_generate_packet (): Used for generating an arp packet.
arp_send_request (): Used for sending an arp request packet. It calls function
arp_generate_packet.
arp_send_reply (): Send reply if recieved packet is ARP and IP address is
match with avr_ip
arp_packet_is_arp (): check received packet, that packet is match with arp and
avr ip or not?
arp_who_is(): send arp request to destination ip, and save destination MAC to
dest_mac.
3.1.3 ip.h
This function implements basic IP protocol. Some of the functions provided
by this header file are:
ip_packet_is_ip (): It checks whether a received packet is an IP packet or not.
ip_generate_header (): It generates all IP headers.
3.1.4 tcp.h
Used to implement basic TCP protocol. Some of functions defined in this
header file are:
tcp_get_dlength ( ): It calculates the data length of the received tcp segment.
tcp_get_hlength ( ): It calculates the header length of the received tcp segment.
Division of Computer Engineering, S.O.E. 39
AVR Web Server
tcp_puts_data_p ( ): It puts data from program memory to tx buffer.
tcp_puts_data (): It puts data from Atmega32 RAM to tx buffer of ENC28J60.
tcp_send_packet (): It sends the tcp packet to the network.
3.1.5 http.h
This header file implements basic http protocol.
Some of the global values declared are:
web_title[] = "AVR Web Server";
tag_br[] = "<br>";
tag_hr[] = "<hr width=\"100%\" size=\"1\"><br>";
tag_form[] = "<form action=\"./?\" method=\"get\">";
Some of the functions declared in this header file are:
http_webserver_process(): Used for initial connection to web server.
http_get_ip(): Used for getting the IP address from the buffer.
http_get_variable(): Used to get http variable from ‘GET’ method.
hex2int (): Used to convert hexadecimal number into integer number.
urldecode (): Used to decode the URL by separating characters like % or +.
http_put_request (): Used to put http put request.
Division of Computer Engineering, S.O.E. 40
AVR Web Server
http_home (): It prepares the web page by writing the HTML data to the TCP
send buffer.
3.1.6 menu.h
This header file implements Menu structure used in 16x2 LCD display.
Functions defined in this header file are:
my_strcpy(): copy string (end '\0') from program memory to ram and return
pointer to end of string.
print_decimal(): Print decimal to buffer, up to 5 digits.
print_temp(): Print ADC0 and temparature to buffer.
print_ip(): Print ip address format to buffer e.g. 10.1.1.1
standby_display(): Display board status such as AVR ip, server IP,
temperature etc.
menu_init(): Used to initialize the Menu.
display_menu(): Display LCD user interface menu on LCD.
menu_process(): Used to process the menu using the up and down keys.
Following are the functions related to the two keys:
a) key_up_process (): Used to move up in the menu.
b) key_dw_process(): Used to move down the menu.
Division of Computer Engineering, S.O.E. 41
AVR Web Server
3.1.7 main.h
This is the main header file where the infinite loop is implemented. It also has
some function defined as Server Process which is called by main loop. The infinite
loop is implemented as:
for(;;)
{ // wait until timer1 overflow
while ( (TIFR & _BV ( TOV1 )) == 0 );
TIFR |= _BV(TOV1);
TCNT1 = 1536; // Timer1 overflow every 1/16MHz * ( 65536 -
1536 ) = 4ms, 250Hz
time_base (); // general time base, generate by timer1
adc_read_temp(); // read temperature
server_process (); // server process response for arp, icmp, http
menu_process (); // lcd user interface menu
standby_display (); // display AVR ethernet status
}
return 0;
}
Here since the AVR is clocked at 16 MHz and the counter is set to count downward
from 65536 to 1536, this loops runs at 250 Hz (or 4 ms).
Division of Computer Engineering, S.O.E. 42
AVR Web Server
CHAPTER 4
EXECUTION
This section deals with the testing, debugging and execution of the program.
The program is written based on the header files which we have discussed in the
previous section.
4.1 Testing and Debugging
All the codes were written on AVR Studio (refer Appendix 1). Each of the
function was independently tested with the set of inputs and was simulated by inbuilt
Simulator of AVR Studio. After integration of all the functions a sample input was
provided to check the output. Also in between code LCD display messages were
provided so as to perform debugging through LDC display.
The project is tested with different versions of browsers running on different
operating systems. All browsers supporting HTTP V1.0 are able to communicate with
the Microcontroller. And through the interface of the web page devices were
controlled.
4.2 Procedure for Execution:
When the whole software code is written in C in AVR Studio environment,
the output hex file is transferred to the Microcontroller with the help of
PonyProg(refer appendix 1, 2 and 3).
Now plug one of the RJ 45 connector of the cross over cable to the RJ 45 jack
of AVR web server and the other end connector to the RJ 45 Jack of CPU. Manually
configure the Internet Connection. If the AVR IP is set to 10.1.1.1, then type this
address in the address bar of the web browser and hit enter. After a short period of
time a web page will be displayed which shows the current status of the devices
Division of Computer Engineering, S.O.E. 43
AVR Web Server
attached to the microcontroller. Now through the interface of this web page devices
attached to the microcontroller can be controlled.
Following is one of the screenshot of the web page:
Fig 4.1: AVR web server screen shot
Division of Computer Engineering, S.O.E. 44
AVR Web Server
CHAPTER 5
CONCLUSION
The project on “AVR Microcontroller based Web Server” has been developed
which hosts a small web page. The web page is stored onto the ATmega32 Flash
memory.
Through the interface of the web page a user is able to control the devices
remotely. A user can also monitor the devices remotely by embedding each device to
be controlled or monitored with the AVR web server. Each device now has a separate
IP address assigned to it. When the IP address is type onto the address bar of the web
browser the web page associated with that device get opens.
The Project can be further developed to provide interfacing with SD/MMC
cards or an IDE hard disk, so that a user can also upload files onto this web server
through the web page interface. In a similar way the Microcontroller can be interfaced
with a Camera and can be used for Remote Surveillance through web page.
Division of Computer Engineering, S.O.E. 45
AVR Web Server
REFERENCES
[1] Atmel ATmega32 Datasheet, Atmel Corporation. www.atmel.com/dyn/resources/prod_documents/doc2503.pdf [2] AVR 460 Application Note, Atmel Corporation. www.atmel.com/atmel/acrobat/doc2396.pdf [3] Berners-Lee, Fielding, T.R. Irvine, H. UC, Frystyk. Request for
Comment:1945, May 1996. http://www.faqs.org/rfcs/rfc1945.html [4] ENC28J60 Datasheet, Microchip Technology Inc. http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022889 [5] Gary Desrosiers,99. Embedded Ethernet. http://www.embeddedethernet.com/ [6] Postel, Jon, Information Science Institute. University of Southern California.,
Network Working Group, Request for Comment: 791, September 1981. http://www.faqs.org/rfcs/rfc791.html [7] Postel, Jon, Information Science Institute. University of Southern California.,
Network Working Group, Request for Comment: 792, April 1984 http://www.faqs.org/rfcs/rfc792.html [8] Plummer, David C., Network Working Group. Request for Comment: 826,
November 1982. http://www.faqs.org/rfcs/rfc826.html
Division of Computer Engineering, S.O.E. 46
AVR Web Server
Appendices
Appendix 1
Working with AVR Studio:
Perform the installation of WinAVR before installing AVR Studio. It helps in locating
the libraries by AVR Studio.
Step1: Open AVR Studio and Select New Project
Fig 7.1: Select New Project in AVR Studio
Step 2: Select AVR GCC compiler and enter a name for the project
Division of Computer Engineering, S.O.E. 47
AVR Web Server
Fig 7.2: Select AVR GCC in AVR Studio
Step 3: Select AVR Simulator and device to be used (here ATmega32)
Fig 7.3: Select Microcontroller type
Division of Computer Engineering, S.O.E. 48
AVR Web Server
Step 4: Start writing your program
Fig 7.4: Write the program in the editor
Step 5: Goto Build and click Build
When the build is successful a build successful message is shown otherwise any error
occurred is reported.
If the build is successful a hex file of the above code is generated in a directory called
‘Default’ where the project is saved. Now transfer this hex file to the Microcontroller.
Division of Computer Engineering, S.O.E. 49
AVR Web Server
Appendix 2
Transfering Code to the Micrcontroller (Using PonyProg)
Step 1: Open PonyProg and goto Interface setup
Fig 7.5: Setup the interface of PonyProg
Step2: Make the settings depending upon your hardware programmer type
Fig 7.6: Select the appropiate hardware programmer type
Division of Computer Engineering, S.O.E. 50
AVR Web Server
Step 3: Click on “Setup” menu and click on “Calibration”, click Yes to Calibrate.
Step5: Click on “Security and Configuration Bits”. Click on read, make the
appropriate changes depending upon the Oscillator used. Here we are using external
16 MHz crystal. Click on write after the changes are done.
Fig 7.7: Write appropriate configuration bits
Step 6: Open the hex file generated by AVR studio and click on “Write All” under
“Command” tab, then click yes.
Fig 7.8: Burn the code onto the Microcontroller
Division of Computer Engineering, S.O.E. 51
AVR Web Server
If a write successful message appears, then the Code was successfully written onto the
microcontroller.
If an error like this appears
Fig 7.9: Error message of PonyProg
Then following possibilities are there:
Power supply is not ON.
Length of the programming cable is too large
Programmer Circuit is not correctly implemented
Problem with the CPU parallel port or serial port
Otherwise, the Microcontroller used is dead.
Division of Computer Engineering, S.O.E. 52
AVR Web Server
Appendix 3
Programmer Hardware:
A simple hardware programmer for AVR microcontroller using parallel port is shown
here. There are several other programmer hardware circuit available using Serial and
USB port, but using Parallel Port is the easiest one.
Fig 7.10: Parallel Port Programmer Hardware
The length of the wire to target should not exceed more than 20 cm, otherwise the
SCK line starts oscillating and there would be no synchronization between the
Microcontroller and the CPU
Division of Computer Engineering, S.O.E. 53