Upload
shivangi-dwivedi
View
261
Download
2
Tags:
Embed Size (px)
Citation preview
A Summer Training Report On
Embedded system & Interfacing with ATmega8
In partial fulfillment of the degree of
Bachelor of Technology
In
Electronics And Communication Engineering
Submitted To: Submitted By:
Ms.Pushpa Gothwal Shivangi Dwivedi
Department Of Electronics B.Tech - ECE,
7th sem
Amity School of Engineering & Technology
Amity University Rajasthan
DECLARATION
I do, hereby, declare that the industrial training report entitled “ Embedded system & interfacing with
ATmega8” is an authentic work developed by me at “Skyphi technologies,jaipur(rajasthan)” under the
guidance of Mr.Rahul Agrawal and submitted as 7th
semester training work for the degree of B.Tech. ECE
at Amity School of Engineering & Technology, Amity University Rajasthan, Jaipur.
I also declare that, any or all contents incorporated in this report have not been submitted in any form for the
award of any degree or diploma of any other institution or university.
shivangi dwivedi
A20405111238
ASET, AUR
CONTENTS
Acknowledgement (iii)
Abstract (ix)
List Of Figures
1.Embedded Systems
1.1 Introduction 1
1.2Examples of embedded system 1
1.3 Characteristics of Embedded System 3
1.4 CATEGORIES OF EMBEDDED SYSTEMS 3
1.5 Application Areas of Embedded Systems 5
1.6 Overview of embedded systems architecture 6
1.7 Specialties of an Embedded Systems 8
1.8 Microprocessor (MPU) 9
1.9 Microcontroller (MCU) 9
1.10 Comparision Between Microprocessor And Microcontroller 10
1.11 Types of Microcontroller 11
2.8051 Microcontroller
2.1About 8051 12
2.2 Block diagram 12
2.3 Typical applications 13
2.4 Pinout Description 14
2.5 Programming Model Of 8051 16
2.6 Accumulator 16
2.7 B Register 17
2.8 PSW (Program Status Word) Register 17
2.9 Data Pointer Register (DPTR) 19
2.10 Stack Pointer (SP) Register 19
2.11 Internal memory 20
2.11.1 Internal RAM 20
2.11.2 Additional RAM 21
2.11.3 Internal ROM 21
2.11.4 Memory Expansion 22
3.AVR MICROCONTROLLER
3.1 Introduction 23
3.2 Classification of AVR's 23
3.3AVR Architecture 23
3.4 Programming interfaces 24
3.4.1 ISP 24
3.4.2PDI 25
3.4.3 High voltage serial 25
3.4.4High voltage parallel 25
3.4.5 Bootloader 25
3.4.6 ROM 25
3.3.6 aWire 26
3.5 CHARACTERISTICS OF AVR 26
4.ATmega8 Microcontroller
4.1 Introduction 27
4.2 Pin Diagram 27
4.3 Pin Description 28
4.4 Internal Architecture 29
4.5 Features 30
4.6 PROGRAMMING IN ATmega8 31
4.7 Interfacing Of Data Bus With Different Units 32
5.Interfacing with ATmega8
5.1 LED 33
5.2 LCD 34
5.2.1 LCD controller 35
5.2.2 LCD Display 35
5.2.3 Configurations 37
5.3 Seven segment display 37
5.4 Relay 39
5.5 DC Motor 41
5.5.1 L293D 42
5.5.2Pin diagram 42
5.6 DTMF 43
5.6.1 HT9170 44
5.6.2 PIN diagram 45
5.6.3 Pin Description 45
5.7 ADC Interfacing 46
5.7.1 DAC 46
5.7.2 Interfacing with ATmega8 46
5.7.3 Temperature Sensor 48
5.7.4 LM35 48
5.8 Serial Communication 49
5.8.1 RS-232 49
5.8.2 I2C 49
5.8.3 SPI 49
5.8.4 DTE DCE Devices 49
5.8.5 UART 50
5.9 Interfacing of pc to microcontroller 51
5.10 Interfacing of microcontroller to PC
6 .Conclusion 52
List Of Figures
S.No Title Page. No
1. Fig:1.1 uses of embedded system 2
2. Fig:1.2 Architecture of Embedded system 7
3. Fig:1.3 Block diag of microcontroller 10
4. Fig:2.1 Block Diag of 8051 12
5. Fig 2.2 PIN diag of 8051 14
6. Fig:2.3 Crystal oscillator of 8052 15
7. Fig:2.4 Accumulator Register 17
8. Fig:2.5 B register 17
9. Fig:2.6 Program Status Word Register 18
10. Fig:2.7 Data Pointer Register 19
11. Fig:2.8 Stack Pointer Register 20
12. Fig:2.9 RAM Memory Space Allocation 21
13. Fig:3.1 AVR Architecture 22
14. Fig:4.1 Pin diag of ATmega8 27
15. Fig:4.2 Architecture of ATmega8 29
16. Fig :4.3 Registers of ATmega8 31
17. Fig:5.1 LED 33
18. Fig:5.2 Interfacing of LED 34
19. Fig: 5.3 LCD 35
20. Fig:5.4 Interfacing of LCD 36
21. Fig:5.5 Prototype of LCD 37
22. Fig:5.6 SevenSegment Display 38
23. Fig:5.7 Common anode 38
24. Fig:5.8 Common cathode 38
25. Fig:5.9 Interfacing of seven segment 39
26. Fig:5.10 Relay 40
27. Fig:5.11 Interfacing of relay 41
28. Fig:5.12 Interfacing of dc motor 41
29. Fig:5.13 Pin diagram of L293D 42
30. Fig:5.14 Dc motor with Atmega8 42
31. Fig:5.15 DTMF 43
32. Fig:5.16 Flow chart fot DTMF 44
33. Fig:5.17 Pin diagram of HT9170 45
34. Fig:5.18 Temp.Sensor with ATmega8 48
35. Fig:5.19 LM35 48
36. Fig:5.20 Serial transmission 49
37. Fig:5.21 Max 232IC 49
38. Fig:5.22 Interfacing of PC with microcontroller 51
ACKNOWLEDGEMENT
I would like to extend my heartfelt thanks and deep sense of gratitude to all those who helped me in practical
training .First and foremost, I would like to express my sincere thanks to the trainer, Mr.Rahul Agrawal
and entire staff at training centre from the core of my heart because they encouraged and persuaded me to
get a well training.
I would like to express my thanks to my guide Ms.Pushpa Gothwal for the inspiration and blessings
bestowed upon me by them.
I am indebted to all my colleagues for guiding and helping me in the preparation of the training report. The
most sincere and important acknowledgement and gratitude is to my parents, who have given their moral
boosting support and encouragement at every stage of this Endeavour.
In the end, I convey my thanks to all those who extend their cooperation directly or indirectly in completion
of the training report.
Shivangi Dwivedi
ABSTRACT
Embedded systems are increasingly becoming integral parts of almost all technology-
oriented applications. Embedded systems are the unsung heroes of much of the
technology we use today- video games, washing machines etc. The appliances using
embedded systems are pre programmed to perform a dedicated or narrow range of
functions as part of a large system, usually with minimal end user interaction and
optimum performance. Embedded systems are used in navigation tools like global
positioning systems (GPS), automated teller machines(ATM’s), networking
equipments such as Echo cancellation, facsimile etc. the coming together of embedded
systems and the internet, which made possible the networking of several embedded
systems to operate as part of a large system across networks- be it a LAN, WAN, or
the Internet. This convergence of embedded systems with the Internet is going to
transfer the way we live.
The Embedded systems are fast achieving ubiquity, blurring the lines between science
fiction and hard reality.
1
1. Embedded System
1.1 Introduction
Microcontroller are widely used in Embedded System products. An Embedded product uses
the microprocessor(or microcontroller) to do one task & one task only. A printer is an
example of Embedded system since the processor inside it perform one task only namely
getting the data and printing it. Although microcontroller are preferred choice for many
Embedded systems, There are times that a microcontroller is inadequate for the task. For this
reason in recent years many manufactures of general purpose microprocessors such as
INTEL, Motorolla, AMD & Cyrix have targeted their microprocessors for the high end of
Embedded market.One of the most critical needs of the embedded system is to decrease
power consumptions and space. This can be achieved by integrating more functions into the
CPU chips. All the embedded processors have low power consumptions in additions to some
forms of I/O,ROM all on a single chip. In higher performance Embedded system the trend is
to integrate more & more function on the CPU chip & let the designer decide which feature
he/she wants to use.
Embedded System
An Embedded System employs a combination of hardware & software to perform a specific
function. Software is used for providing features and flexibility hardware(Processors,
Memory...) is used for performance & sometimes security.An embedded system is a special
purpose system in which the computer is completely encapsulated by the device it controls.
Unlike a general purpose computer, such as a PC, an embedded system performs predefined
task’s usually with very specific tasks design engineers can optimize it reducing the size and
cost of the product. Embedded systems are often mass produced, so the cost savings may be
multiplied by millions of items.The core of any embedded system is formed by one or several
microprocessor or micro controller programmed to perform a small number of tasks. In
contrast to a general purpose computer, which can run any software application, the user
chooses, the software on an embedded system is semi-permanent, so it is often called
firmware.
1.2 Examples of Embedded System
1. Automated tiller machines (ATMS).
2
2. Integrated system in aircraft and missile.
3.Cellular telephones and telephonic switches.
4. Computer network equipment, including routers timeservers and firewalls
5. Computer printers, Copiers.
6. Disk drives (floppy disk drive and hard disk drive)
7. Engine controllers and antilock brake controllers for automobiles.
8. Home automation products like thermostat, air conditioners sprinkles and security
monitoring system.
9. House hold appliances including microwave ovens, washing machines, TV sets DVD
players/recorders.
10. Medical equipment.
11. Measurement equipment such as digital storage oscilloscopes, logic analyzers and
spectrum analyzers.
12. Multimedia appliances: internet radio receivers, TV set top boxes.
13. Small hand held computer with P1M5 and other applications.
14. Programmable logic controllers (PLC’s) for industrial automation and monitoring.
15. Stationary video game controllers.
Fig: 1.1
3
1.3 Characteristics of an Embedded System : The important characteristics of an
embedded system are
Speed (bytes/sec) : Should be high speed
Power (watts) : Low power dissipation
Size and weight : As far as possible small in size and low weight
Accuracy (% error) : Must be very accurate
Adaptability : High adaptability and accessibility.
Reliability : Must be reliable over a long period of time.
So,an embedded system must perform the operations at a high speed so that it can be
readily used for real time applications and its power consumption must be very low and the
size of the system should be as for as possible small and the readings must be accurate with
minimum error.The system must be easily adaptable for different situations.
1.4 CATEGORIES OF EMBEDDED SYSTEMS : Embedded systems can be
classified into the following 4 categories based on their functional and performance
requirements.
Stand-alone embedded systems
Real-time embedded systems -- Hard real-time systems & Soft real-time system
Networked embedded systems and
Mobile Embedded systems.
Based on the performance of the Microcontroller they are also classified into (i) Small scaled
embedded system (ii) Medium scaled embedded system and (iii) Large scaled embedded
system.
Stand alone Embedded systems : A stand-alone embedded system works by itself. It is a
self-contained device which do not require any host system like a computer.. It takes either
digital or analog inputs from its input ports, calibrates, converts, and processes the data, and
outputs the resulting data to its attached output device, which either displays data, or controls
and drives the attached devices. Temperature measurement systems, Video game consoles ,
MP3 players, digital cameras, and microwave ovens are the examples for this category.
Real-time embedded systems : An embedded system which gives the required output in a
specified time or which strictly follows the time dead lines for completion of a task is known
as a Real time system. i.e a Real Time system , in addition to functional correctness, also
satisfies the time constraints .
4
There are two types of Real time systems.(i) Soft real time system and (ii) Hard real time
system.
Soft Real-Time system : A Real time system in which ,the violation of time constraints will
cause only the degraded quality, but the system can continue to operate is known as a Soft
real time system. In soft real-time systems, the design focus is to offer a guaranteed
bandwidth to each real-time task and to distribute the resources to the tasks.
Ex: A Microwave Oven , washing machine ,TV remote etc.
Hard Real-Time system : A Real time system in which ,the violation of time constraints will
cause critical failure and loss of life or property damage or catastrophe is known as a Hard
Real time system.
These systems usually interact directly with physical hardware instead of through a human
being .The hardware and software of hard real-time systems must allow a worst case
execution (WCET) analysis that guarantees the execution be completed within a strict
deadline. The chip selection and RTOS selection become important factors for hard real-time
system design.
Ex: Deadline in a missile control embedded system , Delayed alarm during a Gas leakage ,
car airbag control system , A delayed response in pacemakers ,Failure in RADAR
functioning etc.
Networked embedded systems : The networked embedded systems are related to a network
with network interfaces to access the resources. The connected network can be a Local
Area Network (LAN) or a Wide Area Network (WAN), or the Internet. The connection can
be either wired or wireless.
The networked embedded system is the fastest growing area in embedded systems
applications. The embedded web server is such a system where all embedded devices are
connected to a web server and can be accessed and controlled by any web browser.
Ex: A home security system is an example of a LAN networked embedded system where all
sensors (e.g. motion detectors, light sensors, or smoke sensors) are wired and running on the
TCP/IP protocol.
Mobile Embedded systems : The portable embedded devices like mobile and cellular phones
, digital camaras,MP3 players, PDA (Personal Digital Assistants) are the example for mobile
embedded systems. The basic limitation of these devices is the limitation of memory and
other resources.
5
Small scaled embedded system : An embedded system supported by a single 8–16 bit
Microcontroller with on-chip RAM and ROM designed to perform simple tasks is a Small
scale embedded system.
Medium scaled embedded system : An embedded system supported by 16–32 bit
Microcontroller /Microprocessor with external RAM and ROM that can perform more
complex operations is a Medium scale embedded system.
Large scaled embedded system: An embedded system supported by 32-64 bit multiple
chips which can perform distributed jobs is considered as a Large scale embedded system.
1.5 Application Areas of Embedded Systems: The embedded systems have a huge
variety of application domains which varies from very low cost to very high cost and from
daily life consumer electronics to industry automation equipments, from entertainment
devices to academic equipments, and from medical instruments to aerospace and weapon
control systems. So,the Embedded systems span all aspects of our modern life. The following
table gives the various applications of embedded systems.
S.No Embedded System Application
1 Home Appliances Dishwasher, washing machine, microwave, Top-set
box, security system , HVAC system, DVD,
answering machine, garden sprinkler systems etc..
2 Office Automation Fax, copy machine, smart phone system, modern,
scanner, printers.
3 Security Face recognition, finger recognition, eye recognition,
building security system , airport security system,
alarm system.
4 Academia Smart board, smart room, OCR, calculator, smart
cord.
5 Instrumentation Signal generator, signal processor, power
supplier,Process instrumentation,
6 Telecommunication Router, hub, cellular phone, IP phone, web camera
7 Automobile Fuel injection controller, anti-locking brake system,
air-bag system, GPS, cruise control.
8 Entertainment MP3, video game, Mind Storm, smart toy.
9 Aerospace Navigation system, automatic landing system, flight
attitude controller, space explorer, space robotics.
6
10 Industrial automation Assembly line, data collection system, monitoring
systems on pressure, voltage, current, temperature,
hazard detecting system, industrial robot.
11 Personal PDA, iPhone, palmtop, data organizer.
12 Medical CT scanner, ECG , EEG , EMG ,MRI, Glucose
monitor, blood pressure monitor, medical diagnostic
device.
13 Banking & Finance ATM, smart vendor machine, cash register ,Share
market
14 Miscellaneous: Elevators, tread mill, smart card, security door etc.
Table no. 1.1
1.6 Overview of embedded systems architecture:
Every embedded system consists of customer-built hardware components supported by a
Central Processing Unit (CPU), which is the heart of a microprocessor (µP) or
microcontroller (µC). A microcontroller is an integrated chip which comes with built-in
memory, I/O ports, timers, and other components. Most embedded systems are built on
microcontrollers, which run faster than a custom-built system with a microprocessor, because
all components are integrated within a single chip. Operating system play an important role
in most of the embedded systems. But all the embedded systems do not use the operating
system. The systems with high end applications only use operating system. To use the
operating system the embedded system should have large memory capability. So, This is not
possible in low end applications like remote systems, digital cameras,MP3 players , robo toys
etc.The architecture of an embedded system with OS can be denoted by layered structure as
shown below. The OS will provide an interface between the hardware and application
software. will run the application with out any host system.
Coming to the hardware details of the embedded system, it consists of the following
important blocks.
CPU(Central Processing Unit)
RAM and ROM
I/O Devices
Communication Interfaces
Sensors etc. (Application specific circuitary)
This hardware architecture can be shown by the following block diagram.
7
Fig: 1.2
Central Processing Unit : A CPU is composed of an Arithmetic Logic Unit (ALU), a Control
Unit (CU), and many internal registers that are connected by buses. The ALU performs all
the mathematical operations (Add, Sub, Mul, Div), logical operations (AND, OR), and
shifting operations within CPU .The timing and sequencing of all CPU operations are
controlled by the CU, which is actually built of many selection circuits including latches and
decoders .The CU is responsible for directing the flow of instruction and data within the CPU
and continuously running program instructions step by step.
The CPU works in a cycle of fetching an instruction, decoding it, and executing it, known as
the fetch-decode-execute cycle. The cycle begins when an instruction is fetched from a
memory location pointed to by the PC to the IR via the data bus.
For embedded system design, many factors impact the CPU selection, e.g., the maximum size
(number of bits) in a single operand for ALU (8, 16, 32, 64 bits), and CPU clock frequency
for timing tick control, i.e. the number of ticks (clock cycles) per second in measures of MHz.
Memory : Embedded system memory can be either on-chip or off-chip. On chip memory
access is much fast than off-chip memory, but the size of on-chip memory is much smaller
than the size of off-chip memory. Usually, it takes at least two I/O ports as external address
lines plus a few control lines such as R/W and ALE control lines to enable the extended
memory. Generally the data is stored in RAM and the program is stored in ROM.
8
I/O Ports : The I/O ports are used to connect input and output devices. The common input
devices for an embedded system include keypads, switches, buttons, knobs, and all kinds of
sensors (light, temperature, pressure, etc).
The output devices include Light Emitting Diodes (LED), Liquid Crystal Displays (LCD),
printers, alarms, actuators, etc. Some devices support both input and output, such as
communication interfaces including Network Interface Cards (NIC), modems, and mobile
phones.
Communication Interfaces :To transfer the data or to interact with other devices ,the
embedded devices are provided the various communication interfaces like RS232, RS422,
RS485 ,USB, SPI(Serial Peripheral Interface ) ,SCI (Serial Communication Interface)
,Ethernet etc.
Application Specific Circuitry : The embedded system some times receives the input from a
sensor or actuator. In such situations certain signal conditioning circuitry is needed. This
hardware circuitry may contain ADC , Op-amps ,DAC etc. Such circuitry will interact with
the embedded system to give correct output.
Power supply: Most of the embedded systems now days work on battery operated supplies.
Because low power dissipation is always required. Hence the systems are designed to work
with batteries.
1.7 Specialties of an Embedded Systems : An embedded system has certain
specialties when compared to a normal computer system or a workstation or a mainframe
computer system.
(i).Embedded systems are dedicated to specific tasks, whereas PCs are generic computing
platforms.
(ii).Embedded systems are supported by a wide array of processors and processor
architectures
(iii). Embedded systems are usually cost sensitive.
(iv). Embedded systems have real-time constraints.
(v).If an embedded system use an operating system , it is most likely using a real-time
perating system (RTOS), but not Windows 9X, Windows NT, Windows 2000, Unix,
Solaris, etc.
(vi). The implications of software failure is much more severe in embedded systems than in
desktop systems.
9
(vii) Embedded systems often have power constraints.
(ix). Embedded systems must be able to operate under extreme environmental conditions.
(x). Embedded systems utilizes fewer system resources than desktop systems.
(xi). Embedded systems often store all their object code in ROM.
(xii). Embedded systems require specialized tools and methods to be efficiently designed
when compared to desktop computers.
(xiii). Embedded microprocessors often have dedicated debugging circuitry.
(xiv).Embedded systems have Software Up gradation capability
(xv). Embedded systems have large User Interfaces for real time applications.
DIFFERENT TYPES OF PROCESSORS OF EMBEDDED SYSTEMS
1.Microprocessors
2.Microcontrollers
3.Digital signal processor.
1.8 Microprocessor (MPU)
A microprocessor is a general-purpose digital computer central processing unit(CPU).
Although popularly known as a ―computer on a chip‖ is in no sense a complete digital
computer. The block diagram of a microprocessor CPU is shown, which contains an
arithmetic and logical unit (ALU), a program counter (PC), a stack pointer (SP),some
working registers, a clock timing circuit, and interrupt circuits.
1.9 Microcontroller (MCU)
Figure shows the block diagram of a typical microcontroller. The design incorporates all of
the features found in micro-processor CPU: ALU, PC, SP, and registers. It also added the
other features needed to make a complete computer: ROM, RAM, parallel I/O, serial I/O,
counters, and clock circuit.
10
Fig:1.3
1.10 Comparision Between Microprocessor And Microcontroller
The microprocessor must have many additional parts to be operational as a computer whereas
microcontroller requires no additional external digital parts.
1. The prime use of microprocessor is to read data, perform extensive calculations on that
data and store them in the mass storage device or display it. The prime functions of
microcontroller is to read data, perform limited calculations on it, control its environment
based on these data. Thus the microprocessor is said to be general-purpose digital computers
whereas the microcontroller are intend to be special purpose digital controller.
2. Microprocessor need many opcodes for moving data from the external memory to the
CPU, microcontroller may require just one or two, also microprocessor may have one or two
types of bit handling instructions whereas microcontrollers have many.
3. Thus microprocessor is concerned with the rapid movement of the code and data from the
external addresses to the chip, microcontroller is concerned with the rapid movement of the
bits within the chip.
4. Lastly, the microprocessor design accomplishes the goal of flexibility in the hardware
configuration by enabling large amounts of memory and I/O that could be connected to the
address and data pins on the IC package. The microcontroller design uses much more limited.
11
1.11 Types of Microcontroller:
Microcontrollers are divided into categories according to their memory, architecture, bits and
instruction sets. So let’s discuss types of microcontrollers:-
Bits:
8 bits microcontroller executes logic & arithmetic operations. Examples of 8 bits micro
controller is Intel 8031/8051.
16 bits microcontroller executes with greater accuracy and performance in contrast to 8-bit.
Example of 16 bit microcontroller is Intel 8096.
32 bits microcontroller is employed mainly in automatically controlled appliances such as
office machines, implantable medical appliances, etc. It requires 32-bit instructions to carry
out any logical or arithmetic function.
Memory:
External Memory Microcontroller – When an embedded structure is built with a
microcontroller which does not comprise of all the functioning blocks existing on a chip it
is named as external memory microcontroller. For illustration- 8031 microcontroller does
not have program memory on the chip.
Embedded Memory Microcontroller – When an embedded structure is built with a
microcontroller which comprise of all the functioning blocks existing on a chip it is named
as embedded memory microcontroller. For illustration- 8051 microcontroller has all
program & data memory, counters & timers, interrupts, I/O ports and therefore its
embedded memory microcontroller.
Instruction Set:
CISC- CISC means complex instruction set computer, it allows the user to apply 1
instruction as an alternative to many simple instructions.
RISC- RISC means Reduced Instruction Set Computers. RISC reduces the operation time
by shortening the clock cycle per instruction.
Memory Architecture:
Harvard Memory Architecture Microcontroller
Princeton Memory Architecture Microcontroller
12
2.8051 Microcontroller
THE 8051 ARCHITECTURE
2.1About the 8051
The Intel 8051 is an 8-bit microcontroller which means that most available operations are
limited to 8 bits. There are 3 basic "sizes" of the 8051: Short, Standard, and Extended. The
Short and Standard chips are often available in DIP (dual in-line package) form, but the
Extended 8051 models often have a different form factor, and are not "drop-in compatible".
2.2 Block Diagram
Figure 2.1:Block Diagram of 8051
All these things are called 8051 because they can all be programmed using 8051 assembly
language, and they all share certain features (although the different models all have their own
special features).Some of the features that have made the 8051 popular are:
4 KB on chip program memory.
128 bytes on chip data memory(RAM).
4 register banks.
13
8-bit data bus
16-bit address bus
32 general purpose registers each of 8 bits
16 bit timers (usually 2, but may have more, or less).
3 internal and 2 external interrupts.
Bit as well as byte addressable RAM area of 16 bytes.
Four 8-bit ports, (short models have two 8-bit ports).
16-bit program counter and data pointer.
1 Microsecond instruction cycle with 12 MHz Crystal.
8051 models may also have a number of special, model-specific features, such as
UARTs, ADC, OpAmps, etc...
2.3 Typical applications
8051 chips are used in a wide variety of control systems, telecom applications, and
robotics as well as in the automotive industry. By some estimation, 8051 family chips
make up over 50% of the embedded chip market.The 8051 has been in use in a wide
number of devices, mainly because it is easy to integrate into a project or build a
device around. The following are the main areas of focus:
1.Energy Management:Efficient metering systems help in controlling energy usage in
homes and industrial applications. These metering systems are made capable by
incorporating microcontrollers.
2.Touch screens:A high number of microcontroller providers incorporate touch-
sensing capabilities in their designs. Portable electronics such as cell phones, media
players and gaming devices are examples of microcontroller-based touch screens.
3.Automobiles: The 8051 finds wide acceptance in providing automobile solutions.
They are widely used in hybrid vehicles to manage engine variants. Additionally,
functions such as cruise control and anti-brake system have been made more efficient
with the use of microcontrollers. So the microcontroller 8051 has great advantage in
the field of the automobiles.
4. Medical Devices: Portable medical devices such as blood pressure and glucose
monitors
use microcontrollers will to display data, thus providing higher reliability in providing
medical results.
14
2.4 Pinout Description
Fig:2.2
Pin 1-8(Port 1): Each of these pins can be configured as an input or an output.
Pin 9(RST): A logic one on this pin disables the microcontroller and clears the contents
ofmost registers. In other words, the positive voltage on this pin resets the microcontroller.
By applying logic zero to this pin, the program starts execution from the beginning. Pin 9 is
the RESET pin. It is an input and is active high. Upon applying a high pulse to this pin the
microcontroller well reset and terminate all activities. This is often referred to as a power on
reset .Activating a power on reset will cause all values the registers to be lost. It will set
program counter to all 0s.In order for the RESET input to be effective it must have a
minimum duration of two machine cycles. In other words the high pulse must be high for a
minimum of two machine cycles before it is allowed to go low.
Pin 10-17(Port 3): Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions:
Pin 10(RXD):Serial asynchronous communication input or Serial synchronous
communication output.
15
Pin 11(TXD):Serial asynchronous communication output or Serial synchronous
communication clock output.
Pin 12(INT0):Interrupt 0 input.
Pin 13(INT1):Interrupt 1 input.
Pin 14(T0):Counter 0 clock input.
Pin 15(T1):Counter 1 clock input.
Pin 16(WR):Write to external (additional) RAM.
Pin 17(RD):Read from external RAM.
Pin 18, 19(X2,X1):Internal oscillator input and output. The 8051 has an on chip oscillator but
requires an external clock to run it. Most often a quartz crystal oscillator is connected to
inputs XTAL1 (pin 19) and XTAL2 (pin 18). The quartz crystal oscillator connected to
XTAL1 and XTAL2 also needs two capacitors of 30 pf value. One side of each capacitor is
connected to the ground. Speed refers to the maximum oscillator frequency connected to
XTAL
Fig:2.3
Pin 20(GND):Ground.
Pin 21-28(Port 2):If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher address
byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of
64Kb is not used, which means that not all eight port bits are used for its addressing, the rest
of them are not available as inputs/outputs.
16
Pin 29(PSEN):This is an output pin. PSEN stands for ―program store enable‖. If external
ROM is used for storing program then a logic zero (0) appears on it every time the
microcontroller reads a byte from memory.
Pin 30(ALE):ALE stands for ―address latch enable. It is an output pin and is active high.
When connecting an 8031 to external memory, port 0 provides both address and data. In
other words the 8031 multiplexes address and data through port 0 to save pins. The ALE pin
is used for de-multiplexing the address and data.
Pin 31(EA):EA which stands for ―external access‖ is pin number 31 in the DIP packages. It is
an input pin and must be connected to either Vcc or GND. In other words it cannot be
unconnected. By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that even
there is a program written to the microcontroller, it will not be executed. Instead, the program
writtento external ROM will be executed. By applying logic one to the EA pin, the
microcontroller will use both memories, first internal then external (if exists).
Pin 32-39(Port 0): Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE
pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40(Vcc):+5V power supply.
2.5 Programming Model Of 8051
In programming model of 8051 we have different types of registers are available and these
registers are used to store temporarily data is then the information could be a byte of data to
be processed or an address pointing to the data to be fetched the majority of registers is 8051
are 8-bikt registers.
2.6 Accumulator (Register A)
Accumulator is a mathematical register where all the arithmetic and logical operations are
done is this register and after execution of instructions the outpour data is stored in the
register is bit addressable near. We can access any of the single bit of this register.A register
is a general-purpose register used for storing intermediate results obtained during operation.
Prior to executing an instruction upon any number or operand it is necessary to store it in the
accumulator first. All results obtained from arithmetical operations performed by the ALU
are stored in the accumulator. Data to be moved from one register to another must go through
17
the accumulator. In other words, the A register is the most commonly used register and it is
impossible to imagine a microcontroller without it. More than half instructions used by the
8051 microcontroller use somehow the accumulator.
Figure2.4:Accumulator Register
2.7 B Register:
B register is same as that of accumulator of. It is also an 8 bit register and every bit of this is
accessible. This is also a mathematical register B which is used mostly for multiplication and
division.
Figure2.5:B register
2.8 PSW (Program Status Word) Register
Program status word register is an 8 bit register. It is also referred to as the flag register.
Although the PSW register is 8 bits wide, only 6 bits of it are used by the 8051. The unused
bits are user-definable flags. Four of the flags are called conditional flags, meaning that they
Indicate some conditions that result after an instruction is executed. These four are CY
(carry), AC (auxiliary carry), P (parity) and OV (overflow).
CY PSW.7 Carry Flag
AC PSW.6 Auxiliary Carry Flag
F0 PSW.5 Available to the user for
General Purpose
RS1 PSW.4 Register Bank Selector Bit 1
RS0 PSW.3 Register Bank Selector
Bit 0
OV PSW.2 Overflow Flag
-- PSW.1 User Definable Bit
P PSW.0 Parity Flag.
18
Figure2.6: Program Status Word Register
PSW register is one of the most important SFRs. It contains several status bits that reflect the
current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two
register bank select bits, Overflow flag, parity bit and user-definable status flag.
RS1 (PSW.4) RS0 (PSW.3)
Bank 0 0 0
Bank 1 0 1
Bank 2 1 0
Bank 3 1 1
Table 2.1: PSW Bit Bank selection
P (Parity bit): If a number stored in the accumulator is even then this bit will be automatically
set (1), otherwise it will be cleared (0). It is mainly used during data transmit and receive via
serial communication.
Bit 1: This bit is intended to be used in the future versions of microcontrollers.
OV( Overflow): Occurs when the result of an arithmetical operation is larger than 255 and
cannot be stored in one register. Overflow condition causes the OV bit to be set (1).
Otherwise, it will be cleared (0).
1RS0, RS1 (Register bank select bits): These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four
banks of RAM.
F0 (Flag 0): This is a general-purpose bit available for use.
AC (Auxiliary Carry Flag):This is used for BCD operations only.
19
CY (Carry Flag):This is the (ninth) auxiliary bit used for all arithmetical operations and shift
instructions.
2.9 Data Pointer Register (DPTR)
DPTR register is not a true one because it doesn't physically exist. It consists of two separate
registers: DPH (Data Pointer High) and (Data Pointer Low). For this reason it may be treated
as a 16-bit register or as two independent 8-bit registers. Their 16 bits are primarly used for
external memory addressing. Besides, the DPTR Register is usually used for storing data and
intermediate results.
Figure 2.7:Data Pointer Register
2.10 Stack Pointer (SP) Register
Figure2.8:Stack Pointer Register
A value stored in the Stack Pointer points to the first free stack address and permits stack
availability. Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack pops
decrement its value by 1. Upon any reset and power-on, the value 7 is stored in the Stack
Pointer, which means that the space of RAM reserved for the stack starts at this location. If
another value is written to this register, the entire Stack is moved to the new memory
location.
20
2.11 Internal Memory
The 8051 has two types of memory and these are Program Memory and Data Memory.
Program Memory (ROM) is used to permanently save the program being executed, while
Data Memory (RAM) is used for temporarily storing data and intermediate results created
and used during the operation of the microcontroller. 128 or 256 bytes of RAM is used.
2.11.1 Internal RAM
As already mentioned, Data Memory is used for temporarily storing data and intermediate
results created and used during the operation of the microcontroller. Besides, RAM memory
built in the 8051 family includes many registers such as hardware counters and timers,
input/output ports, serial data buffers etc. The previous models had 256 RAM locations,
while for the later models this number was incremented by additional 128 registers. However,
the first 256 memory locations (addresses 0-FFh) are the heart of memory common to all the
models belonging to the 8051 family. Locations available to the user occupy memory space
with addresses 0-7Fh, i.e. first 128 registers. This part of RAM is divided in several blocks.
The first block consists of 4 banks each including 8 registers denoted by R0-R7. Prior to
accessing any of these registers, it is necessary to select the bank containing it. The next
memory block (address 20h-2Fh) is bit- addressable, which means that each bit has its own
address (0-7Fh). Since there are 16 such registers, this block contains in total of 128 bits with
separate addresses (address of bit 0 of the 20h byte is 0, while address of bit 7 of the 2Fh byte
is 7Fh). The third group of registers occupy addresses 2Fh-7Fh, i.e. 80 locations, and does not
have any special functions or features.
21
Figure2.9: RAM Memory Space Allocation
2.11.2 Additional RAM
In order to satisfy the programmers’ constant hunger for Data Memory, the manufacturers
decided to embed an additional memory block of 128 locations into the latest versions of the
8051 microcontrollers. However, it’s not as simple as it seems to be… The problem is that
electronics performing addressing has 1 byte (8 bits) on disposal and is capable of reaching
only the first 256 locations, therefore. In order to keep already existing 8-bit architecture and
compatibility with other existing models a small trick was done.What does it mean? It means
that additional memory block shares the same addresses with locations intended for the SFRs
(80h- FFh). In order to differentiate between these two physically separated memory spaces,
different ways of addressing are used. The SFRs memory locations are accessed by direct
addressing, while additional RAM memory locations are accessed by indirect addressing.
2.11.3 Internal ROM
The first models of the 8051 microcontroller family did not have internal program memory. It
was added as an external separate chip. These models are recognizable by their label
beginning with 803 (for example 8031 or 8032). All later models have a few Kbyte ROM
embedded. Even though such an amount of memory is sufficient for writing most of the
programs, there are situations when it is necessary to use additional memory as well. A
22
typical example are so called lookup tables. They are used in cases when equations
describing some processes are too complicated or when there is no time for solving them. In
such cases all necessary estimates and approximates are executed in advance and the final
results are put in the tables (similar to logarithmic tables).EA=0In this case, the
microcontroller completely ignores internal program memory and executes only the program
stored in external memory.EA=1In this case, the microcontroller executes first the program
from built-in ROM, then the program stored in external memory.In both cases, P0 and P2 are
not available for use since being used for data and address transmission. Besides, the ALE
and PSEN pins are also used.
2.11.4 Memory Expansion
In case memory (RAM or ROM) built in the microcontroller is not sufficient, it is possible to
add two external memory chips with capacity of 64Kb each. P2 and P3 I/O ports are used for
their addressing and data transmission.From the user’s point of view, everything works quite
simply when properly connected because most operations are performed by the
microcontroller itself. The 8051 microcontroller has two pins for data read RD(P3.7) and
PSEN. The first one is used for reading data from external data memory (RAM), while the
other is used for reading data from external program memory (ROM). Both pins are active
low.Even though additional memory is rarely used with the latest versions of the
microcontrollers, we will describe in short what happens when memory chips are connected
according to the previous schematic. The whole process described below is performed
automatically.Similar occurs when it is necessary to read location from external RAM.
Addressing is performed in the same way, while read and write are performed via signals
appearing on the control outputs RD (is short for read) or WR (is short for write).
23
3.AVR MICROCONTROLLER
3.1 Introduction
The AVR is a modified Harvard architecture 8-bit RISC single chip microcontroller which
was developed by Atmel in 1996. The AVR was one of the first microcontroller families to
use on-chip flash memory for program storage, as opposed to one-time programmable
ROM, EPROM, or EEPROM used by other microcontrollers at the time.
Mega AVR chips became extremely popular after they were designed into the 8-
bit Arduino platform.
The AVR is a modified Harvard architecture machine where program and data are stored in
separate physical memory systems that appear in different address spaces, but having the
ability to read data items from program memory using special instructions.
3.2 Classification of AVR's
tinyAVR — the ATtiny series
0.5–16 kB program memory
6–32-pin package
Limited peripheral set
megaAVR — the ATmega series
4–512 kB program memory
28–100-pin package
Extended instruction set (multiply instructions and instructions for handling larger
program memories)
Extensive peripheral set
XMEGA — the ATxmega series
16–384 kB program memory
44–64–100-pin package (A4, A3, A1)
Extended performance features, such as DMA, "Event System", and cryptography
support.
Extensive peripheral set with ADCs
Application-specific AVR
megaAVRs with special features not found on the other members of the AVR family,
such as LCD controller, USB controller, advanced PWM, CAN, etc.
FPSLIC (AVR with FPGA) FPGA 5K to 40K gates
SRAM for the AVR program code, unlike all other AVRs
AVR core can run at up to 50 MH
3.3 AVR ARCHITECTURE
• RISC architecture with CISC instruction set
24
• Powerful instruction set for C and Assembly
• Scalable
• Same powerful AVR core in all devices
• Single cycle execution
• One instruction per external clock
• Low power consumption
• 32 Working Registers
• All Directly connected to ALU!
• Very efficient core
• 20 MIPS @ 20MHz
• High System Level Integration
• Lowest total system cost
Fig:3.1
3.4 Programming interfaces
There are many means to load program code into an AVR chip. The methods to program
AVR chips varies from AVR family to family.
3.4.1 ISP
The in-system programming (ISP) programming method is functionally performed
through SPI, plus some twiddling of the Reset line. As long as the SPI pins of the AVR are
25
not connected to anything disruptive, the AVR chip can stay soldered on a PCB while
reprogramming. All that is needed is a 6-pin connector and programming adapter. This is the
most common way to develop with an AVR.
The Atmel AVR ISP mkII device connects to a computer's USB port and performs in-system
programming using Atmel's software.
AVRDUDE (AVR Downloader/UploaDEr) runs on Linux, FreeBSD, Windows, and Mac OS
X, and supports a variety of in-system programming hardware, including Atmel AVR ISP
mkII, Atmel JTAG ICE, older Atmel serial-port based programmers, and various third-party
and "do-it-yourself" programmers.
3.4.2 PDI
The Program and Debug Interface (PDI) is an Atmel proprietary interface for external
programming and on-chip debugging of XMEGA devices. The PDI supports high-speed
programming of all non-volatile memory (NVM) spaces; flash, EEPROM, fuses, lock-bits
and the User Signature Row. This is done by accessing the XMEGA NVM controller through
the PDI interface, and executing NVM controller commands. The PDI is a 2-pin interface
using the Reset pin for clock input (PDI_CLK) and a dedicated data pin (PDI_DATA) for
input and output.
3.4.3 High voltage serial
High-voltage serial programming (HVSP) is mostly the backup mode on smaller AVRs. An
8-pin AVR package does not leave many unique signal combinations to place the AVR into a
programming mode. A 12 volt signal, however, is something the AVR should only see during
programming and never during normal operation
3.4.4 High voltage parallel
High voltage parallel programming (HVPP) is considered the "final resort" and may be the
only way to fix AVR chips with bad fuse settings.
3.4.5Bootloader
Most AVR models can reserve a bootloader region, 256 B to 4 KB, where re-programming
code can reside. At reset, the bootloader runs first, and does some user-programmed
determination whether to re-program, or jump to the main application. The code can re-
program through any interface available, it could read an encrypted binary through an
Ethernet adapter like PXE. Atmel has application notes and code pertaining to many bus
interfaces.
3.4.6 ROM
The AT90SC series of AVRs are available with a factory mask-ROM rather than flash for
program memory.[21]
Because of the large up-front cost and minimum order quantity, a mask-
ROM is only cost-effective for high production runs.
26
3.4.7 aWire
aWire is a new one-wire debug interface available on the new UC3L AVR32 devices.
3.5 CHARACTERISTICS OF AVR
• High performance • Low power consumption • High code density • Advanced memory technology • High integration
27
4.ATmega8 Microcontroller
4.1 Introduction The ATmega8A has 3 timers, and 3 PWM channels. There are 6 10-bit ADC channels,
and a single analog comparator. The QFP and MLF packages have 2 more ADC channels,
for a total of 8. It is pin compatible with the newer, more powerful ATmega88/168/328
devices. It supersedes the ATmega8, which was retired in 2010. It has a wider supply
voltage range, and a faster clock than the ATmega8. ATmega8 microcontroller has 23 programmable input/output (I/O) pins which can be used
for interfacing with external world. It is possible to configure them as input or output by
setting a particular register value through programming. This IC comes in 3 different
packages, but we are using the popular 28-Pin PDIP
package (Atmega8-16PU). Note that Atmega8 is available in 2 versions; ATmega8 and
Atmega8L.
Atmega8L is a low frequency version which works up to 8MHz frequency.
CMOS RISC, ATmega8 AVR 8-BIT Microcontroller, In-system Programmable with Flash
code storage, re-programmable up to 1000 times. Features 32 working registers, single
clock cycle...
4.2 PIN DIAGRAM
Fig:4.1
28
4.3 PIN DESCRIPTION
VCC- Digital supply voltage.
GND -Ground.
Port B- (PB7..PB0)
XTAL1/XTAL2/TOSC1/
TOSC2
Port B -is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port B output buffers have symmetrical drive characteristics with both
high sink and source capability. As inputs, Port B pins that are externally pulled low
will source current if the pull-up resistors are activated. The Port B pins are tri-stated
when a reset condition becomes active, even if the clock is not running.
Depending on the clock selection fuse settings, PB6 can be used as input to the inverting
Oscillator amplifier and input to the internal clock operating circuit.
Depending on the clock selection fuse settings, PB7 can be used as output from the inverting
Oscillator amplifier.
If the Internal Calibrated RC Oscillator is used as chip clock source, PB7..6 is used as
TOSC2..1 input for the Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set.
Port C- (PC5..PC0) Port C is an 7-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port C output buffers have symmetrical drive characteristics
with both high sink and source capability. As inputs, Port C pins that are externally
pulled low will source current if the pull-up resistors are activated. The Port C pins are
tri-stated when a reset condition becomes active, even if the clock is not running.
PC6/RESET- If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note
that the electrical characteristics of PC6 differ from those of the other pins of Port C.
If the RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low level on this
pin for longer than the minimum pulse length will generate a Reset, even if the clock is not
running. The minimum pulse length is given in Table 15 on page 38. Shorter pulses are not
guaranteed to generate a Reset.
Port D (PD7..PD0)- Port D is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port D output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port D pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset
condition becomes active, even if the clock is not running.
RESET- Reset input. A low level on this pin for longer than the minimum pulse length will
generate a reset, even if the clock is not running.
AVCC -AVCC is the supply voltage pin for the A/D Converter, Port C (3..0), and ADC
(7..6). It should be externally connected to VCC, even if the ADC is not used. If the ADC is
used, it should be connected to VCC through a low-pass filter. Note that Port C (5..4) use
digital supply voltage, VCC.
AREF -AREF is the analog reference pin for the A/D Converter.
ADC7..6 -(TQFP and QFN/MLF Package Only)
In the TQFP and QFN/MLF package, ADC7..6 serve as analog inputs to the A/D converter
29
4.4 INTERNAL ARCHITECTURE
Fig:4.2
30
4.5 Features
Memory: It has 8 Kb of Flash program memory (10,000 Write/Erase cycles durability), 512
Bytes of EEPROM (100,000 Write/Erase Cycles). 1Kbyte Internal SRAM
I/O Ports: 23 I/ line can be obtained from three ports; namely Port B, Port C and Port D.
Interrupts: Two External Interrupt source, located at port D. 19 different interrupt vectors
supporting 19 events generated by internal peripherals.
Timer/Counter: Three Internal Timers are available, two 8 bit, one 16 bit, offering various
operating modes and supporting internal or external clocking.
SPI (Serial Peripheral interface): ATmega8 holds three communication devices integrated.
One of them is Serial Peripheral Interface. Four pins are assigned to Atmega8 to implement
this scheme of communication.
USART: One of the most powerful communication solutions is USART and ATmega8
supports both synchronous and asynchronous data transfer schemes. It has three pins assigned
for that. In many projects, this module is extensively used for PC-Micro controller
communication.
TWI (Two Wire Interface): Another communication device that is present in ATmega8 is
Two Wire Interface. It allows designers to set up a commutation between two devices using
just two wires along with a common ground connection, As the TWI output is made by
means of open collector outputs, thus external pull up resistors are required to make the
circuit.
Analog Comparator: A comparator module is integrated in the IC that provides comparison
facility between two voltages connected to the two inputs of the Analog comparator via
External pins attached to the micro controller.
Analog to Digital Converter: Inbuilt analog to digital converter can convert an analog input
signal into digital data of 10bit resolution. For most of the low end application, this much
resolution is enough.
Advanced RISC Architecture
- 130 Powerful Instructions - Most Single Clock Cycle Execution
- 32 x 8 General Purpose Working Registers
- Up to 6 MIPS Throughput at 16MHz
- Fully Static Operation
- On-chip 2-cycle Multiplier.
The 23 I/O ports of ATmega8 are organised into 3 groups:
Port B (PB0 to PB7)
Port C (PC0 to PC6)
Port D (PD0 to PD7)
31
All of these I/O pins have secondary functions, which are shown in parenthesis on the pinout
diagram shown here. Each of these registers are 8 bits wide, with each bit corresponding to a
single pin (an exception is bit 7 of the Port C register -PC6- most often used as the RESET
pin, not an I/O). Registers used for reading and writing to the I/O ports are described below.
Fig:4.3
4.6 PROGRAMMING IN ATmega8
Programming the ATmega8 is done by placing the part into RESET and applying serial
commands and data to the data in pin while clocking the sck pin. Data read back from the
part is clocked in on the data out pin.
There are commands to read and write program memory, EEPROM memory, and the
configuration area (fuse bytes, lock bits, signature bytes, and calibration bytes).
The programmer hardware consists of a 28 pin socket for the ATmega8 and a 14 pin header
for connecting to the SBC2's onboard 65C22.
The Atmega8 requires a valid clock input during programming. If the fuses are set to use an
external clock source, then one will need to be provided. I chose to use the 65C22 Timer 1
output through PB7 to supply the clock. This ensures a valid clock is always present.
Therefore, we will use Port B of the 65C22 to access the Programmer.
This simple AVR Programmer will allow you to painlessly transfer hex programs to most
ATMEL AVR microcontrollers without sacrificing your budget and time. It is more reliable
than most other simple AVR programmers available out there and can be built in very short
amount of time.
AVR programmer consists of in-circuit serial programmer (dongle) and small pcb with a DIP
socket where you can fit your microcontroller and have it quickly programmed.
You may also use this programmer as a stand alone in-circuit serial programmer that can be
used to conveniently program AVR microcontrollers without removing them from the target
circuit.
32
Entire AVR programmer has been build with using common parts and fits in the case of the
serial connector. The socket pcb has been created to fit a 28-DIP AVR ATmega8
microcontroller, but you can build a socket pcb for any other AVR microcontroller out there.
This AVR programmer is compatible with a popular PonyProg software that shows you a
status bar of the programming progress.
4.7 Interfacing Of Data Bus With Different Units
In order to maximize performance and parallelism, the AVR uses a 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.The fast-access Register
File contains 32 x 8-bit general purpose working registers with a single clock cycle access
time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU
operation, two operands are output from the Register File, the operation is executed, and the
result is stored back in the Register File in one clock cycle.
Six of the 32 registers can be used as three 16-bit indirect address register pointers for Data
Space addressing enabling efficient address calculations. One of the these address pointers
can also be used as an address pointer for look up tables in Flash Program memory. These
added function registers are the 16-bit X, Y and Z-register.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.The Program flow is
provided by conditional and unconditional jump and call instructions, able to directly address
the whole address space. Most AVR instructions have a single 16-bit word format. Every
Program memory address contains a 16- or 32-bit instruction.
Program Flash memory space is divided in two sections, the Boot program section and the
Application program section. Both sections have dedicated Lock Bits for write and read/write
protection. The SPM instruction that writes into the Application Flash memory section must
reside in the Boot program section.During interrupts and subroutine calls, the return address
Program Counter (PC) is stored on the Stack. The Stack is effectively allocated in the general
data SRAM, and consequently the Stack size is only limited by the total SRAM size and the
usage of the SRAM. All user programs must initialize the SP in the reset routine (before
subroutines or interrupts are executed).
33
5.Interfacing with ATmega8
5.1 LED- Like a normal diode, an LED consists of a chip of semiconducting material
impregnated, or doped, with impurities to create a p-n junction. As in other diodes, current
flows easily from the p-side, or anode, to the n-side, or cathode, but not in the reverse
direction. Charge-carriers—electrons and holes—flow into the junction from electrodes with
different voltages. When an electron meets a hole, it falls into a lower energy level, and
releases energy in the form of a photon. The wavelength of the light emitted, and therefore its
color, depends on the band gap energy of the materials forming the p-n junction. In silicon or
germanium diodes, the electrons and holes recombine by a non-radiativetransition which
produces no optical emission, because these are indirect band gap materials. The materials
used for an LED have a direct band gap with energies corresponding to near-infrared, visible
or near-ultraviolet light. LED development began with infrared and red devices made with
gallium arsenide. Advances in materials science have made possible the production of devices
with ever-shorter wavelengths, producing light in a variety ofcolors.Conventional LEDs are
made from a variety of inorganic semiconductor materials, producing the following colors:
Aluminium gallium arsenide (AlGaAs) — red and infrared
Aluminium gallium phosphide (AlGaP) — green
Aluminium gallium indium phosphide (AlGaInP) — high-brightness
orange-red, orange, yellow, and green
Gallium arsenide phosphide (GaAsP) — red, orange-red, orange, and yellow
Gallium phosphide (GaP) — red, yellow and green
Gallium nitride (GaN) — green, pure green (or emerald green), and blue
also white (if it has an AlGaN Quantum Barrier)
34
Fig : 5.1
Fig :5.2
5.2 LCD
A liquid crystal display (LCD) is a thin, flat electronic visual display that uses the light
modulating properties of liquid crystals(LCs). LCs do not emit light directly.it is
an electronically-modulated optical device made up of any number of pixels filled with liquid
crystals and arrayed in front of alight source (backlight) or reflector to produce images in
colour or monochrome.
Each pixel of an LCD typically consists of a layer of molecules aligned between
two transparent electrodes, and two polarizing filters, the axes of transmission of which are
(in most of the cases) perpendicular to each other. With no actual liquid crystal between the
35
polarizing filters, light passing through the first filter would be blocked by the second
(crossed) polarizer. In most of the cases the liquid crystal has double refraction.
Before applying an electric field, the orientation of the liquid crystal molecules is determined
by the alignment at the surfaces of electrodes.
The main objective of serialLCD is to control any kind of alphanumeric LCD display using
a single signal line which communicates with LCD controller using serial communication
technique. My serialLCD prototype consist of 2 major blocks:
5.2.1 LCD controller:
It is ATmega8 microcontroller @ 8MHz internal osc. Programmed in Arduino IDE. It uses
no-xtal bootloader which provide arduino compatibility without 16Mhz external crystal &
also it is open-source. Using 8Mhz internal osc. Reduces hardware & improves power
efficiency. ATmega8 uses its native serial port (USART) to communicate with master
microcontroller. It acts as bridge between master controller & LCD. ATmega8 can be
replaced by mega168/328 without changing code. (You must change bootloader.). The
source file is provided as Firmware file in attachments.
5.2.2 LCD display:
It’s a regular 16x2 alphanumeric display. There are no more customizations in LCD.
Fig:5.3
36
Table of Pin Description of LCD :
Table:5.1
Schematic:
Fig:5.4
37
PROTOTYPE
Fig 5.5
5.2.3 Configurations
Here,PORTB(PB0-PB7) set as data port in 8 bit mode LCD display.Connect D0-D7 with the
PORTB. Ground the first lead of the lcd(vss) display.
Connect vcc to a 5v power supply.
Conncet VEE with a pot.It's used to adjust the contrast of the LCD display
15th and 16th leads are used to power the back light of the LCD.Connect 15th with 5v and
ground 16th lead.
5.3 Seven segment display interfacing
The seven-segment LED display has four individual digits, each with a decimal point. Each
of the seven segments (and the decimal point) in a given digit contains an individual LED.
When a suitable voltage is applied to a given segment LED, current flows through and
illuminates that segment LED. By choosing which segments to illuminate, any of the nine
digits can be shown. For example, as shown in the figure below, a 2 can be displayed by
38
illuminating segments a, b, d, e, and g.seven segment
displays come in two varieties - common anode (CA) and
common cathode (CC). In a CA display, the anodes for the
seven segments and the decimal point are joined into a single
circuit node. To illuminate a segment in a CA display, the
voltage on a cathode must be at a suitably lower voltage
(about .7V) than the anode. In a CC display, the cathodes are
Fig:5.6 joined together, and the segments are illuminated by bringing the anode voltage
higher than the cathode node (again, by about .7V). The seven LEDs in each digit are labeled
a-g. Since the Digilab board usesCA displays, the anodes for each of the four digits are
connected in a common node, so that four separate anode circuit nodes exist (one per
digit).Similar cathode leads from each digit have also been tied together to form seven
common circuit nodes, so that one node exists for each segment type. These four anode and
seven cathode circuit nodes are available at the J2connector pins labeled A1-A4 and CA-CG.
With this scheme, any segment of any digit can be driven individually. For example, to
illuminate segments and c in the second digit, the b and c cathode nodes would be brought to
a suitable low voltage (by connecting the corresponding circuit node available at the J2
connector to ground), and anode 2 would be brought to a suitablehigh voltage (by connecting
the corresponding circuit node available at theJ2 connector to Vdd).
This will be of 2 types :
1.Common Anode
2.Common Cathode
Fig :5.7 Common anode Fig:5.8 common cathode
39
Fig:5.9
5.4 Relay interfacing
The electromagnetic relay consists of a multi-turn coil, wound on an iron core, to form an
electromagnet. When the coil is energized, by passing current through it, the core becomes
temporarilymagnetized. The magnetized core attracts the iron armature. The armature is
pivoted which causes it to operate one or more sets of contacts. When the coil is de-energized
the armature and contacts are released. The coil can reenergized from a low power source
such as a transistor while the contacts can switch high powers such as the mains supply. The
relay can also be situated remotely from the control source. Relays can generate a very high
voltage across the coil when switched off.This can damage other components in the circuit.
To prevent this a diode is connected across the coil.As there are always some chances of high
voltage spikes back from the switching circuit i.e. heater so an opt coupler/isolator MCT2e is
used. It provides and electrical isolation between the microcontroller and the heater. MCT2e
is a 6-pin IC with a combination of optical transmitter LED and an optical receiver as
phototransistor. Microcontroller is connected to pin no 2 ofMCT2e through a 470-ohm
resistor. Pin no.1 is given +5V supply and pin no.4 is grounded. To handle the current drawn
by the heater a power transistor BC-369 is used as a current driver. Pin no.5 of opt coupler is
connected to the base of transistor. It takes all its output to Vandactivates the heater through
relay circuit. The electromagnetic relay consists of a multi-turn coil, wound on an iron core,
to form an electromagnet. When the coil is energized, by passing current through it, the core
40
becomes temporarily magnetized. The magnetized core attracts the iron armature. The
armature is pivoted which causes it to operate one or more sets of contacts. When the coil is
de-energized the armature and contacts are released. Relays can generate a very high voltage
across the coil when switched off. This can damage other components in the circuit. To
preventthis diode is connected across the coil. Relay has five points. Out of the 2 operating
points one is permanently connected to the ground and the other point is connected to
thecollector side of the power transistor. When Vreaches the collector side i.e. signal is given
to the operating points the coil gets magnetized and attracts the iron armature. The iron plate
moves from normally connected (NC) position to normally open (NO) position. Thus the
heater gets the phase signal and is ON. To remove the base leakage voltage when no signal is
present a 470-ohmresistance is used.
Fig:5.10
The output port pins of microcontrollers can can only source few Milli amperes of current, so
they cannot be directly used to energize relays. To solve this and interface a relay with any
microcontroller or other logic chips we need a transistor.
Here you can see that output from microcontroller enter transistor via resistor R1 (4K7). This
resistor limit the current and only very small current flows from the base to the emitter. When
microcontrollers output port is in low state (0) no current flows to the base and the transistor
is in off state. When microcontroller makes the output line high (binary 1), the transistor is
switched on. Current flows from the 12v input to the relay and then to the ground via the
transistors collector pin. This current switches on the relay which in turn switches on the AC
load (the bulb)
The diode D1 (1N4007) is used as a Flyback diode. Whenever an inductive load (the the coils
of relay) is switched off, a large voltage is generated across its terminal. This voltage can
damage the transistor. To protect the transistor we put a diode in such a way that it short
circuits this voltage.
41
Fig:5.11
5.5 INTERFACING OF DC MOTOR
It simply has two terminals and by reverting voltage at these terminals we can change the
direction of rotation of motor. But to run it from atmega16 microcontroller we should need to
attach a driver ic because atmega16 gives 20 mA current in output which is not sufficient to
drive a simple 12v of 1 A current rating motor. Basically L293D IC is used to drive the
motor.
Fig:5.12
42
5.5.1 L293D
L293D is a typical motor driver or Motor circuit IC which allows DC motor to drive on either
directio. L293D is a 16-pin IC which can control a set of two DC motors simultaneously in
any direction.It means we can control two DC motors with a single L293D.
5.5.2 PIN DIAGRAM OF L293D.
Fig:5.13
Left input pins will regulate the rotation of motor connected across left side and right input
for motor on the right side.The motors are rotated on the basis of the inputs provided across
the inputs pins as LOGIC 0 or LOGIC 1.
Fig:5.14
43
There are 4 inputs in L293D motor driver IN1,IN2 ,IN3,IN4.
These are connected to any port of the microcontroller
one motor is attatched to OUT1,OUT2
pin no.4,5,13&12 are connected to the ground.
EN1,EN2,Vss are connected to +5V supply.
5.6 DTMF INTERFACING
DTMF is a signalling system for identifying the keys or the number dialed on
a pushbutton or DTMF keypad. The early telephone systems used pulse dialling or
loop disconnect signalling. This was replaced by multi frequency (MF) dialling.
DTMF is a multi frequency tone dialling system used by the push button keypads in
telephone and mobile sets to convey the number or key dialled by the caller. DTMF
has enabled the long distance signalling of dialled numbers in voice frequency range
over telephone lines. This has eliminated the need of telecom operator between the
caller and the callee and evolved automated dialling in the telephone switching
centres.
DTMF (Dual tone multi frequency) as the name suggests uses a combination of two
sine wave tones to represent a key. These tones are called row and column
frequencies as they correspond to the layout of a telephone keypad.
Fig: 5.15
44
A DTMF keypad (generator or encoder) generates a sinusoidal tone which is mixture of the
row and column frequencies. The row frequencies are low group frequencies. The column
frequencies belong to high group frequencies. This prevents misinterpretation of the
harmonics. Also the frequencies forDTMF are so chosen that none have a harmonic
relationship with the others and that mixing the frequencies would not produce sum or
product frequencies that could mimic another valid tone. The high-group frequencies (the
column tones) are slightly louder than the low-group to compensate for the high-frequency
roll off of voice audio systems.
The row and column frequencies corresponding to a DTMF keypad have been indicated in
the above figure.
DTMF tones are able to represent one of the 16 different states or symbols on the keypad.
This is equivalent to 4 bits of data, also known as nibble.
Fig:5.16
Now received tone tone is produced by ardino with the help of DTMF Decoder.
Here we used HT9170 & decodes the DTMF tone into its equivalent binary digit & this
binary number is send to the ardino ,the ardino is preprogrammed to take decisions for any
given input & outputs its decision to motor drivers in order to drive the motors in either
forward and backward directions.
5.6.1 HT9170 HT9170 is the series of Dual Tone Multi Frequency (DTMF) receivers. They employ digital
counting techniques to detect and decode the 16 DTMF tones into 4 bit output code.
HT9170 series receivers do not require any external filters as they use highly accurate
switched capacitor filters for filtering low and high frequency signals from the DTMF tones.
They also support power down (PWDN) and inhibit (INH) modes. PWDN mode is used to
power off the crystal, while INH mode to inhibit the A, B, C & D DTMF tones. The clock is
provided by a 3.58 MHz crystal.
In simple terms, HT9170 IC detects and decodes the 16 DTMF tones into 4 bit output. In case
the tones are not detected, the four output bits remain low. The DV pin goes high on
detection of a valid tone.
45
5.6.2 PIN DIAGRAM OF HT9170
Fig :5.17
5.6.3Pin Description:Table 5.
Pin No Function Name
1 Operational amplifier non-inverting input VP
2 Operational amplifier inverting input VN
3 Operational amplifier output terminal GS
4 Reference voltage output terminal VREF
5 Active high. It inhibits the detection of tones corresponding
to A, B, C and D. It is internally pulled down. INH
6 Active high. It leads the chip to power down mode and
inhibits the oscillator. It is internally pulled down PWDN
7 Connection for standard 3.579545 MHz crystal
X1
8 X2
9 Ground (0V) VSS
10 Active high; Enables output D0-D3 OE
11
Output terminals
D0
12 D1
13 D2
14 D3
15 Data valid. It goes high on reception of valid DTMF signal;
otherwise remains low DV
16 Early steering output EST
17 Tone acquisition time and release time can be set by using
external resistor and capacitor RT/GT
18 Supply voltage; 5V (2.5V-5.5V) VDD
46
5.7 ADC
An Analog-Digital Converter (ADC) is a widely used electronic component that converts an
analog electric signal (usually a voltage) into a digital representation. The ADCs are at the
front-end of any digital circuit that needs to process signals coming from the exterior world.
The output of a microphone, the voltage at a photodiode or the signal of an accelerometer are
examples of analog values that need to be converted so that a microprocessor can work with
them.
5.7.1 Digital to Analog Converter
In modern life, electronic equipment is frequently used in different fields such as
communication, transportation, entertainment, etc. Analog to Digital Converter (ADC) and
Digital to Analog Converter (DAC) are very important components in electronic equipment.
Since most real world signals are analog, these two converting interfaces are necessary to
allow digital electronic equipments to process the analog signals. Take the audio signal
processing in Figure 1 as an example, ADC converts the analog signal collected by audio
input equipment, such as a microphone, into a digital signal that can be processed by
computer. The computer may add sound effect such as echo and adjust the tempo and pitch of
the music. DAC converts the processed digital signal back into the analog signal that is used
by audio output equipment such as a speaker.
5.7.2 Interfacing with ATmega8
ADC means Analog to Digital converter. ADC is a inbuilt peripheral available in almost every AVR
Microcontrollers. ADC feature of Atmega8 enables us to communicate with real-world data such
as temperature, weight, pressure, voltage, resistance etc easily. Atmega8 has a ADC with
1. 6 channel (PC0 to PC5) and
2. 10 bit Resolution.
3. Here channel means the available pins (connections) in a chip that can convert analog
data into digital value separately. At the above i wrote that Atmega8 has six channels
means you can get 6 digital values of 6 analog signals separately at the same time.
4.
5. Now 10 bits resolution means 2 to the power 10 equals to 1024 division
of reference volt. means suppose we want to measure a analog voltage which is being
varied from 0 to +5 volt and reference voltage is given +5 volt then ADC circuit built
in a atmega will divide the reference volt (+5) by 1024, (5/1024=0.0048828125 volt)
and now adc value which is simply a number will be incremented by 1 on each
0.0048828125 volt, for example we give 2.5 volt to a adc channel then the digital
value will be 2.5/0.0048828125 = 512 (converted digital value of that analog volt). So
a reference voltage is a voltage (to AREF pin) to compare that analog data being
varied from 0 to reference voltage.
For connection with ATmega8
PIN 20 (AVCC) and 22 (GND) are power supply to ADC
PIN 21 (AREF) is supply pin to the reference volt of ADC.
PIN 23 to 28 are six ADC channel
47
PIN 7 and 8 are power supply to main chip.
For interfacing we need 3 more registers:
1. ADCSRA (ADC Control and Status Register A)
2. ADMUX (ADC multiplexer)
3. ADC data register, ADCH and ADCL (ADC data High and Low)
ADCSRA Register
The main use of this Register is to enable the ADC features in AVR's I/O Port, Starting the
conversion of analog, Enabling Interrupt, Setting a flag bit after conversion, Declaring mode
either it will be free running or Single Conversion mode, and defining the Prescaler .
ADMUX Register This Register is used to select :
1. Reference voltage source to ADC (AREF)
2. Analog port channel to used for conversion (PC0.....PC5)
3. How the result will be stored in Data Register either Left justified or Right
justified. Since the Digital value of corresponding Analog vary from 0 to 1024, value
can't be stored in a single register that's why two registers (ADCH & ADCL) are used
to store that digital value.
ADC DATA Registers ADCH and ADCL ADCH and ADCL are Data registers used to store the Digital result, converted from Analog.
Since Atmega8 has 10 bits resolution, result may vary from 0 to 1023 (1024 in count) so that
it can not be stored in a single 8 bit register, two registers are used ADCH & ADCL (ADC
register High and Low) because Atmega8 have 8 bit architecture. By default, the result is
presented right adjusted, but can optionally be presented left adjusted by setting the ADLAR
bit in ADMU If the result is left adjusted and no more than 8-bit precision is required, it is
sufficient to read AD CH. Otherwise, ADCL must be read first, then ADCH. The ADC has
its own interrupt which can be triggered when a conversion completes. When ADC access to
the Data Registers is prohibited between reading of ADCH and ADCL, the interrupt will
trigger even if the result is lost.
5.7.3 Temperature sensor
48
Fig :5.18
5.7.4 What is LM35
The LM35 is an integrated circuit sensor that can be used to measure temperature
with anelectrical output proportional to the temperature .
Fig :5.19
5.8 SERIAL COMMUNICATION
Serial communication is the process of sending data one bit at a time, sequentially, over
a communication channel or computer bus.
49
Fig: 5.20
There are several popular types of serial communications. Here are a few worth noting:
RS232. Peer-to-peer (i.e. communications between two devices)
USB (Universal Serial Bus). Replaced RS232 on desktop computers.
CAN (Controller Area Network). Multi-point. Popular in the automotive industry.
SPI (Serial Peripheral Interface). Developed by Motorola. Synchronous master/slave
communications.
I2C (Inter-Integrated Circuit).Developed by Philips. Multi-master communications.
5.8.1 RS-232
RS-232 stands for Recommend Standard number 232 and C is the latest revision of the
standard. The serial ports on most computers use a subset of the RS-232C standard. The full
RS-232C standard specifies a 25-pin "D" connector of which 22 pins are used. Most of these
pins are not needed for normal PC communications, and indeed, most new PCs are equipped
with male D type connectors having only 9 pins.
• Offers a immediate link between microcontroller
to pc
.
Fig:5.21
5.8.2 I2C
I²C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-
ended, serial computer bus invented by Philips Semiconductor, known today as NXP
Semiconductors, used for attaching low-speed peripherals to
50
computer motherboards and embedded systems. Alternatively I²C is
spelled I2C (pronounced I-two-C) or IIC (pronounced I-I-C).
5.8.3 SPI
Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by
microcontrollers for communicating with one or more peripheral devices quickly over short
distances. It can also be used for communication between two microcontrollers.
5.8.4 DCE and DTE Devices
Two terms you should be familiar with are DTE and DCE. DTE stands for Data Terminal
Equipment, and DCE stands for Data Communications Equipment. These terms are used to
indicate the pin-out for the connectors on a device and the direction of the signals on the pins.
Your computer is a DTE device, while most other devices are usually DCE devices.
If you have trouble keeping the two straight then replace the term "DTE device" with "your
PC" and the term "DCE device" with "remote device" in the following discussion.
The RS-232 standard states that DTE devices use a 25-pin male connector, and DCE devices
use a 25-pin female connector. You can therefore connect a DTE device to a DCE using a
straight pin-for-pin connection. However, to connect two like devices, you must instead use a
null modem cable.
5.8.5 UART Communication
UART is a type of asynchronous receiver/transmitter and is an integrated circuit used for
serial communications over a computer or peripheral devices serial port. It is usually used to
connect to an RS232 interface for modems, printers and similar peripherals. The UART has a
feature that, handshake lines for control of an external modem, which is controlled by
software. Most of the microcontrollers are included with the UART. For the better
coordination of data stream between computer and serial devices, buffering of data are
provided by the UARTs. Each UART contains a shift register which performs the conversion
of serial and parallel forms. The modem’s maximum transmission rate is easily handled by
the computer’s UART.
UART converts parallel data into serial data.
Baud rate=1200 Fcpu=12MHz(Tx) & 8MHz(Rx)
UBRR=(Fcpu/16baud)-1
5.9 INTERFACING OF PC AND ATmega8 (using UART)
USART means Universal Synchronous Asynchronous Transmitter and Receiver. USART
communication has provisions for full duplex communication, i.e. simultaneous transmission
and reception. Synchronous means that a single clock source would be shared by end devices
to facilitate communication. Asynchronous means, there would be no synchronized clock
source b/w the end devices. But to receive a serial incoming data there is always a need for
sampling. In addition to that, the symbol rate (i.e. the baud rate) should be known. That’s
why each USART or UART module has an internal baud rate generator module. In earlier
micro controllers, no separate baud rate generation unit was there. They used one of the
51
internal timer counter for baud rate generation.
The frame (i.e. number of bits in each transmission) can consist of 5,6,7,8 or 9 data bits. Start
bit starts the data transmission. There is one/two stop bit also included. There may be an
even/odd parity bit included or there may not be any parity bits. The USART data register
(Known as UDR for AVR micro controllers) is a double buffer register. It consists of
transmitter buffer and receiver buffer. Both of them share the same I/O address. But when
Data written to UDR, the data is saved to the transmitter buffer and serially shifted out from
the TXD pin. And when UDR is read, the content in the receiver buffer is read which stores
the serial incoming bits from the RXD pins.
USART module in ATmega8 have got 5 registers (4 8-bit, 1-16bit) associated with it. They
are
1. UCSRA : USART Control and Status Register A. In this Register, three Bits indicates
the status of transmission and reception. Only two bits are enough for basic programming.
These are:
aTXC-TransmissionComplete
b) RXC-ReceptionComplete
These bits are checked before reading or writing data to UDR (USART Data Register)
2. UCSRB : Control and Status Register B. This register is very important to enable the
USART Transmitter and Receiver. The bits associated are
a) TXEN: Transmitter Enable Bit. This enables the USART transmitter.
b) RXEN: Receiver Enable Bit. This enables the USART receiver.
Fig: 5.22
52
6. CONCLUSIONS:
Many embedded systems have requirements that differ significantly both in details and in
scope from desktop computers. In particular, the demands of the specific application and the
interface with external equipment may dominate the system design. Also, long life-cycles and
in some cases extreme cost sensitivity require more attention to optimization based on these
goals rather than maximizing the computational throughput.
Recent interest in hardware/software codesign is a step in the right direction, as it permits
tradeoffs between hardware and software that are critical for more cost-effective embedded
systems. However, to be successful future tools may well need to increase scope even further
to include life cycle issues and business issues.
53