Вы находитесь на странице: 1из 19

Mono Graph

On

Embedded System Design


By

Contents
Page No.

1. Introduction
1.1 Definition of Embedded systems
2. Hardware
2.1 Microcontrollers and Microprocessors

Page |1
2.2 The 8,16 and 32-Bit controllers
2.3 Embedded Microcontrollers
2.4 Memory organization
3. Software’s
3.1 Embedded C
3.2 Keil µVision IDE
3.3 Proteus
3.4 Prog ISP
4. Hardware Programmer
5. Design Steps

1. Introduction
This chapter introduces the world of embedded systems. Everything that we look around
us today is electronic. The days are gone where almost everything was manual. Now even the
food that we eat is cooked with the assistance of a microchip (oven) and the ease at which we
wash our clothes is due to the washing machine. This world of electronic items is made up of

Page |2
embedded system. In this chapter we will understand the basics of embedded system right from
its definition.

1.1 DEFINITION OF AN EMBEDDED SYSTEM

A general-purpose definition of embedded systems is that they are devices used to control,
monitor or assist the operation of equipment, machinery or plant. “Embedded” reflects the fact
that they are an integral part of the system. In many cases, their “embeddedness” may be such
that their presence is far from obvious to the casual observer.

Simply can be defined as


An embedded system is a combination of 3 things:
a. Hardware
b. Software
c. Mechanical Components
And it is supposed to do one specific task only.

APPLICATION OF EMBEDDED SYSTEM

The application areas and the products in the embedded domain are countless.

1. Consumer Electronics: Camcorders, Cameras.


2. Household appliances: Washing machine, Refrigerator.
3. Automotive industry: Anti-lock breaking system (ABS), engine control.
4. Home automation & security systems: Air conditioners, sprinklers, fire alarms.
5. Telecom: Cellular phones, telephone switches.
6. Computer peripherals: Printers, scanners.
7. Computer networking systems: Network routers and switches.
8. Healthcare: EEG, ECG machines.
9. Banking & Retail: Automatic teller machines, point of sales.

2. Hardware

In hardware the Microcontroller is the heart of the embedded system. Microcontrollers


have only been with us for a few decades but their impact (direct or indirect) on our lives is
profound. Usually these are supposed to be just data processors performing exhaustive numeric
operations.
Creating applications for the microcontrollers is different than any other development job
in electronics and computing. Before selecting a particular device for an application, it is
important to understand what the different options and features are and what they can mean with
regard to developing the application.

The purpose of this chapter is to introduce the concept of microcontrollers, how it differs
from microprocessors and different type of commercial microcontrollers available as well as
their applications. The reminder of the book will go through and present different types of

Page |3
microcontrollers and also programming and interfacing techniques of microcontroller, mainly
8051, in detail.

Simply an embedded controller is a controller that is embedded in a greater system. One


can define an embedded controller as a controller (or computer) that is embedded into some
device for some purpose other than to provide general purpose computing. Is an embedded
controller is the same as a microcontroller? The answer is definitely no. One can state devices
such as 68000, 32032, x86, Z80, and so on that are used as embedded controllers but they aren’t
microcontrollers.

2.1 MICROCONTROLLERS AND MICROPROCESSORS

A controller is used to control some process. At one time, controllers were built
exclusively from logic components, and were usually large, heavy boxes. Later on,
microprocessors were used and the entire controller could fit on a small circuit board. This is still
common one can find many controllers powered by one of the many common microprocessors
(including Zilog Z80, Intel 8088, Motorola 6809, and others).

As the process of miniaturization continued, all of the components needed for a controller
were built right onto one chip. A one chip computer, or microcontroller was born. A CPU built
into a single VLSI chip is called microprocessor. The simplified block diagram of the CPU is
shown in the Fig. 1.1. It contains arithmetic and logic unit (ALU), Instruction decodes and
control unit, Instruction register, Program counter (PC), clock circuit (internal or external), reset
circuit (internal or external) and registers. For example,
Intel 8085 is 8-bit microprocessor and Intel 8086/8088 is 16-bit microprocessor. Microprocessor
is general-purpose digital computer central processing unit (CPU). The microprocessor is
general-purpose device and additional external circuitry is added to make it microcomputer.

COMPARING MICROPROCESSORS AND MICROCONTROLLERS

• Microprocessor is a single chip CPU, microcontroller contains, a CPU and much of the
remaining circuitry of a complete microcomputer system in a single chip.
Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt
schedule circuitry (in addition to CPU) in a single chip.
RAM is smaller than that of even an ordinary microcomputer, but enough for its
applications.
Interrupt system is an important feature, as microcontrollers have to respond to control
oriented devices in real time. E.g., opening of microwave ovens door cause an interrupt to stop
the operation. (Most microprocessors can also implement powerful interrupt schemes, but
external components are usually needed).
Microprocessors are most commonly used as the CPU in microcomputer systems.
Microcontrollers are used in small, minimum component designs performing control-oriented
activities.
Microprocessor instruction sets are _processing intensive_, implying powerful
addressing modes with instructions catering to large volumes of data. Their instructions operate
on nibbles, bytes, etc. Microcontrollers have instruction sets catering to the control of inputs and

Page |4
outputs. Their instructions operate also on a single bit. E.g., a motor may be turned ON and OFF
by a 1-bit output port. Before going in to details of microcontrollers it will be beneficial to go
through common and frequently used terminology encountered in the description of
microcontrollers.

CENTRAL PROCESSING UNIT (CPU)

CPU is the brain of the computer system, administers all activity in the system and
performs all operations on data. It continuously performs two operations: fetching and executing
instructions. It understands and executes instructions based on a set of binary codes called the
instruction set.

TYPES OF MICROCONTROLLERS

Microcontrollers can be classified on the basis of internal bus width, architecture, memory and
instruction set. Below figure a, shows the various types of microcontrollers.

2.2 THE 8, 16 AND 32-BIT MICROCONTROLLERS

THE 8-BIT MICROCONTROLLER

When the ALU performs arithmetic and logical operations on a byte (8-bits) at an instruction, the
microcontroller is an 8-bit microcontroller. The internal bus width of 8-bit microcontroller is of
8-bit. Examples of 8-bit microcontrollers are Intel 8051 family and Motorola MC68HC11
family.

THE 16-BIT MICROCONTROLLER

When the ALU performs arithmetic and logical operations on a word (16-bits) at an instruction,
the microcontroller is an 16-bit microcontroller. The internal bus width of 16-bit microcontroller
is of 16-bit. Examples of 16-bit microcontrollers are Intel 8096 family and Motorola MC68HC12
and MC68332 families. The performance and computing capability of 16 bit microcontrollers are
enhanced with greater precision as compared to the 8-bit microcontrollers.

THE 32-BIT MICROCONTROLLER

When the ALU performs arithmetic and logical operations on a double word (32- bits) at
an instruction, the microcontroller is an 32-bit microcontroller. The internal bus width of 32-bit
microcontroller is of 32-bit. Examples of 32-bit microcontrollers are Intel 80960 family and
Motorola M683xx and Intel/Atmel 251 family. The performance and computing capability of 32
bit microcontrollers are enhanced with greater precision as compared to the 16-bit
microcontrollers.

Page |5
Fig a: Types of Microcontrollers

2.3 EMBEDDED MICROCONTROLLERS

When an embedded system has a microcontroller unit that has all the functional blocks
(including program as well as data memory) available on a chip is called an embedded
microcontroller. For example, 8051 having Program & Data Memory, I/O Ports, Serial
Communication, Counters and Timers and Interrupt Control logic on the chip is an embedded
microcontroller.

MICROCONTROLLER ARCHITECTURAL FEATURES

There are mainly two categories of processors, namely, Von-Neuman (or Princeton) architecture
and Harvard Architecture. These two architecture differ in the way data and programs are stored
and accessed.

VON-NEUMAN ARCHITECTURE

Microcontrollers based on the Von-Neuman architecture have a single _data_ bus that is
used to fetch both instructions and data. Program instructions and data are stored in a common
main memory. When such a controller addresses main memory, it first fetches an instruction, and
then it fetches the data to support the instruction.

Page |6
The two separate fetches slows up the controller’s operation. Figure 1.5 shows the Von-
Neuman Architecture. The Von-Neuman architecture’s main advantage is that it simplifies the
microcontroller design because only one memory is accessed. In microcontrollers, the contents
of RAM can be used for data storage and program instruction storage. For example, the Motorola
68HC11 microcontroller Von- Neuman architecture.

HARVARD ARCHITECTURE

Microcontrollers based on the Harvard Architecture have separate data bus and an
instruction bus. This allows execution to occur in parallel. As an instruction is being “pre-
fetched”, the current instruction is executing on the data bus. Once the current instruction is
complete, the next instruction is ready to go. This pre-fetch theoretically allows for much faster
execution than Von-Neuman architecture, on the expense of complexity. Figure 1.6 shows the
Harvard Architecture. The Harvard Architecture executes instructions in fewer instruction cycles
than the Von-Neuman architecture.

The 8051 micro-controller architecture

The 8051 is the name of a big family of microcontrollers. The device which we are going
to use along this tutorial is the ‘AT89S52’ which is a typical 8051 microcontroller manufactured
by Atmel. Note that this part doesn’t aim to explain the functioning of the different components
of a 89S52 microcontroller, but rather to give you a general idea of the organization of the chip
and the available features, which shall be explained in detail along this tutorial.

The block diagram provided by Atmel in their datasheet showing the architecture the 89S52
device can seem very complicated, and since we are going to use the C high level language to
program it, a simpler architecture can be represented as the below figure.

Page |7
This figures shows the main features and components that the designer can interact with. You
can notice that the 89S52 has four different ports, each one having eight Input/output lines
providing a total of 32 I/O lines. Those ports can be used to output DATA and orders do other
devices, or to read the state of a sensor, or a switch. Most of the ports of the 89S52 have ‘dual
function’ meaning that they can be used for two different functions: the fist one is to perform
input/output operations and the second one is used to implement special features of the
microcontroller like counting external pulses, interrupting the execution of the program
according to external events, performing serial data transfer or connecting the chip to a computer
to update the software.

Each port has eight pins, and will be treated from the software point of view as an 8-bit variable
called ‘register’, each bit being connected to a different Input/output pin.

Page |8
You can also notice two different memory types: RAM and EEPROM. Shortly, RAM is used to
store variable during program execution, while the EEPROM memory is used to store the
program itself, that’s why it is often referred to as the ‘program memory’. The memory
organization will be discussed in detail later.

The special features of the 89S52 microcontroller are grouped in the blue box at the bottom of
above figure. At this stage of the tutorial, it is just important to note that the 89S52 incorporates
hardware circuits that can be used to prevent the processor from executing various repetitive
tasks and save processing power for more complex calculations. Those simple tasks can be
counting the number of external pulses on a pin, or generating precise timing sequences.

It is clear that the CPU (Central Processing Unit) is the heart of the microcontrollers, It is the
CPU that will Read the program from the FLASH memory and execute it by interacting with the
different peripherals discussed above.

Above figure shows the pin configuration of the 89S52, where the function of each pin is
written next to it, and, if it exists, the dual function is written between brackets. The pins are
written in the same order as in the block diagram of figure 1.2.A, except for the VCC and GND
pins which I usually note at the top and the bottom of any device.

Page |9
Note that the pin that has dual functions can still be used normally as an input/output pin. Unless
you program uses their dual functions, all the 32 I/O pins of the microcontroller are configured
as input/output pins.

Most of the function of the pins of the 89S52 microcontroller will be discussed in detail, except
for the pins required to control an external memory, which are the pins number 29, 30 and 31.
Since we are not going to use any external memory, pins 29 and 30 will be ignored through all
the tutorial, and pin 31 (EA) always connected to VCC (5 Volts) to enable the micro-controller
to use the internal on chip memory rather than an external one (connecting the pin 31 to ground
would indicate to the microcontroller that an external memory is to be used instead of the
internal one).

2.4 .Memory organization

A RAM stands for Random Access Memory, it has basically the same purpose of the
RAM in a desktop computer, which is to store some data required during the execution time of
different programs. While an EEPROM, also called FLASH memory is a more elaborated ROM
(Read Only Memory) which is the memory where the program being executed is stored. Even if
that’s not exactly true, you can compare an EEPROM to the Hard-Disk of a desktop computer
from a general point of view. The EEPROM term stands for Electronically Erasable and
Programmable Read Only Memory.

In microcontrollers, like in any digital system, memory is organized in Registers, Which


is the basic unit of construction of a memory. Each register is composed of a number of bits
(usually eight) where the data can be stored. In the 8051 family of microcontrollers for example,
most registers are 8-bit register, capable of storing values ranging from 0 to 255. In order to use
bigger values, various register can be used simultaneously. Below figure shows a typical 8-bit
registers, where the notation D0 to D7 stands for the 8 DATA bits of the register.

figure 1.3.A
As you shall see, the RAM memory of the 89S52, which contains 256 registers, is
divided into two main parts, the GPR part, and the SFR part. GPR stands for ‘General Purpose
Register’ and are the registers that you can use to store any data during the execution of your
program. SFRs (Special function Register) are registers used to control the functioning of the
microcontroller and to assist the processor through the various operations being executed. For
example, SFRs can be used to control Input/output lines, to retrieve data transmitted through the
serial port of a desktop computer, or to configure one of the on-chip counters and timers.

In a memory each register has a specific address which is used by the processor to read
and write from specific memory location. Figure 1.3.B shows the memory organization of the
256 registers of the RAM of the 89S52 microcontroller. The address is noted in Hexadecimal
format as this notation simplifies digital logic calculations for the designers, 00 corresponds to
the first location and FF which is equal to 256 corresponds to the last location.

P a g e | 10
A programmer that would use the assembly language, have to take this memory
organization into consideration while choosing the locations where his variables are stored, as
writing general purpose data into special function registers could prevent the microcontroller
from working correctly, but since we will use the C language using the KEIL IDE (integrated
development environment), this part will be totally handled by the compiler.

Clock concept

The clock concept is found in all modern digital electronics, it is a simple circuit that will
generate pulses of electricity at a very specific frequency. Those pulses will cadence all the
events happening inside a microcontroller, those pulses will also assure the synchronization of
the events between various components inside the microcontroller. For example, if the CPU is
waiting for some result of mathematical operation from the ALU (Arithmetic and Logic Unit), it
will be known – according to very specific protocol – when and where the resulting data will be
delivered to the CPU. The synchronization of those two devices is maintained because they share
the same clock.

The clock has another very important role which is to enable the microcontroller to count
timing. Without a precise clock, it would be impossible to build a ‘Real Time System‘, or any
other device that relies on time measurements. It can be deduced that the precision of the timing
of a microcontroller depends on the frequency of its clock.

In the 89S52 microcontroller, the clock can be fixed to different value by connecting a crystal
to the pins 18 and 19. Those crystals are sold with the frequency written on them in Mega Hertz.
The maximum operating frequency of the AT89S52 is 33 Mhz, however other manufacturers
like Philips built similar 8051 microcontrollers that can run at frequencies up to 120 Mhz.

3. Software’s
In the software section there is a need of three major software’s.

1. Embedded C
2. Keil µVision IDE
3. Proteus
4. Prog ISP

EMBEDDED SYSTEMS PROGRAMMING

Embedded systems programming is different from developing applications on a desktop


computers. Key characteristics of an embedded system, when compared to PCs, are as follows:

Embedded devices have resource constraints (limited ROM, limited RAM, and limited
stack space, less processing power)

P a g e | 11
Components used in embedded system and PCs are different; embedded systems
typically uses smaller, less power consuming components. Embedded systems are more tied to
the hardware.
Two salient features of Embedded Programming are code speed and code size. Code
speed is governed by the processing power, timing constraints, whereas code size is governed by
available program memory and use of programming language. Goal of embedded system
programming is to get maximum features in minimum space and minimum time.

Embedded systems are programmed using different type of languages:


· Machine Code
· Low level language, i.e., assembly
· High level language like C, C++, Java, Ada, etc.
· Application level language like Visual Basic, scripts, Access, etc.

Assembly language maps mnemonic words with the binary machine codes that the
processor uses to code the instructions. Assembly language seems to be an obvious choice for
programming embedded devices. However, use of assembly language is restricted to developing
efficient codes in terms of size and speed. Also, assembly codes lead to higher software
development costs and code portability is not there. Developing small codes are not much of a
problem, but large programs/projects become increasingly difficult to manage in assembly
language. Finding good assembly programmers has also become difficult nowadays. Hence high
level languages are preferred for embedded systems programming.

Use of C in embedded systems is driven by following advantages:


· It is small and reasonably simpler to learn, understand, program and debug.
· C Compilers are available for almost all embedded devices in use today, and there is a large
pool of experienced C programmers.
· Unlike assembly, C has advantage of processor-independence and is not specific to any
particular microprocessor/ microcontroller or any system. This makes it convenient for a user to
develop programs that can run on most of the systems.
· As C combines functionality of assembly language and features of high level languages, C is
treated as a ‘middle-level computer language’ or ‘high level assembly language’
· It is fairly efficient
· It supports access to I/O and provides ease of management of large embedded projects.

Many of these advantages are offered by other languages also, but what sets C apart from others
like Pascal, FORTRAN, etc. is the fact that it is a middle level language; it provides direct
hardware control without sacrificing benefits of high level languages.
Compared to other high level languages, C offers more flexibility because C is relatively
small, structured language; it supports low-level bit-wise data manipulation.
Compared to assembly language, C Code written is more reliable and scalable, more
portable between different platforms (with some changes). Moreover, programs developed in C
are much easier to understand, maintain and debug. Also, as they can be developed more
quickly, codes written in C offers better productivity. C is based on the philosophy ‘programmers
know what they are doing’; only the intentions are to be stated explicitly. It is easier to write
good code in C & convert it to an efficient assembly code (using high quality compilers) rather

P a g e | 12
than writing an efficient code in assembly itself. Benefits of assembly language programming
over C are negligible when we compare the ease with which C programs are developed by
programmers.
Objected oriented language, C++ is not apt for developing efficient programs in resource
constrained environments like embedded devices. Virtual functions & exception handling of
C++ are some specific features that are not efficient in terms of space and speed in embedded
systems. Sometimes C++ is used only with very few features, very much as C. Ada, also an
object-oriented language, is different than C++. Originally designed by the U.S. DOD, it didn’t
gain popularity despite being accepted as an international standard twice (Ada83 and Ada95).
However, Ada language has many features that would simplify embedded software development.

Java is another language used for embedded systems programming. It primarily finds usage in
high-end mobile phones as it offers portability across systems and is also useful for browsing
applications. Java programs require Java Virtual Machine (JVM), which consume lot of
resources. Hence it is not used for smaller embedded devices.
Dynamic C and B# are some proprietary languages which are also being used in
embedded applications.
Efficient embedded C programs must be kept small and efficient; they must be optimized
for code speed and code size. Good understanding of processor architecture embedded C
programming and debugging tools facilitate this.

Different types of program languages are there. Among that an important and user friendly
language is Embedded C.

3.1 Embedded C

Looking around, we find ourselves to be surrounded by various types of embedded


systems. Be it a digital camera or a mobile phone or a washing machine, all of them has some
kind of processor functioning inside it. Associated with each processor is the embedded
software. If hardware forms the body of an embedded system, embedded processor acts as the
brain, and embedded software forms its soul. It is the embedded software which primarily
governs the functioning of embedded systems.

During infancy years of microprocessor based systems, programs were developed using
assemblers and fused into the EPROMs. There used to be no mechanism to find what the
program was doing. LEDs, switches, etc. were used to check correct execution of the program.
Some ‘very fortunate’ developers had In-circuit Simulators (ICEs), but they were too costly and
were not quite reliable as well.
As time progressed, use of microprocessor-specific assembly-only as the programming
language reduced and embedded systems moved onto C as the embedded programming
language of choice. C is the most widely used programming language for embedded
processors/controllers. Assembly is also used but mainly to implement those portions of the code
where very high timing accuracy, code size efficiency, etc. are prime requirements.
Initially C was developed by Kernighan and Ritchie to fit into the space of 8K and to
write (portable) operating systems. Originally it was implemented on UNIX operating systems.

P a g e | 13
As it was intended for operating systems development, it can manipulate memory addresses.
Also, it allowed programmers to write very compact codes. This has given it the reputation as the
language of choice for hackers too.
As assembly language programs are specific to a processor, assembly language didn’t
offer portability across systems. To overcome this disadvantage, several high level languages,
including C, came up. Some other languages like PLM, Modula-2, Pascal, etc. also came but
couldn’t find wide acceptance. Amongst those, C got wide acceptance for not only embedded
systems, but also for desktop applications. Even though C might have lost its sheen as
mainstream language for general purpose applications, it still is having a strong-hold in
embedded programming. Due to the wide acceptance of C in the embedded systems, various
kinds of support tools like compilers & cross-compilers, ICE, etc. came up and all this facilitated
development of embedded systems using C.

DIFFERENCE BETWEEN C AND EMBEDDED C

Though C and embedded C appear different and are used in different contexts, they
have more similarities than the differences. Most of the constructs are same; the difference lies in
their applications.
C is used for desktop computers, while embedded C is for microcontroller based
applications. Accordingly, C has the luxury to use resources of a desktop PC like memory, OS,
etc. While programming on desktop systems, we need not bother about memory. However,
embedded C has to use with the limited resources (RAM, ROM, I/Os) on an embedded
processor. Thus, program code must fit into the available program memory. If code exceeds the
limit, the system is likely to crash.
Compilers for C (ANSI C) typically generate OS dependant executables. Embedded C
requires compilers to create files to be downloaded to the microcontrollers/microprocessors
where it needs to run. Embedded compilers give access to all resources which is not provided in
compilers for desktop computer applications.
Embedded systems often have the real-time constraints, which is usually not there with
desktop computer applications.
Embedded systems often do not have a console, which is available in case of desktop
applications.
So, what basically is different while programming with embedded C is the mindset; for
embedded applications, we need to optimally use the resources, make the program code efficient,
and satisfy real time constraints, if any. All this is done using the basic constructs, syntaxes, and
function libraries of ‘C’.

3.2 Keil µVision IDE

The µVision IDE from Keil combines project management, make facilities, source code
editing, program debugging, and complete simulation in one powerful environment. The µVision
development platform is easy-to-use and helping you quickly create embedded programs that
work. The µVision editor and debugger are integrated in a single application that provides a
seamless embedded project development environment.

P a g e | 14
The µVision IDE is the easiest way for most developers to create embedded applications
using the Keil development tools. To launch µVision, click on the icon on your desktop or select
Keil µVision4 from the Start Menu.

3.3 Proteus
Proteus developed by Lab center Electronics, is software with which you can easily
generate schematic captures, develop PCB and simulate microprocessor. It has such a simple yet
effective interface that it simplifies the task required to be performed. This one aspect has
attracted many users to select this tool amongst many others offering the same services. Proteus
provides a powerful working environment. The user can design different electronic circuits with
all the necessary components easily accessible from the simple yet effective interface like signal
generators, power supply, simple resistor and a different microcontroller or microprocessor.

VSM (Virtual System Modeling feature allows the real time design simulation. It is
armed with the mixed-mode SPICE simulation. ARES (Advanced Routing and Editing Software)
is another powerful feature that permits you to route or edit the different components which are
used for producing printed circuits. The application is extensively used in the educational
institutions as it is easy to use. Novices can operate it with ease and start producing simulation,
board designs and schematics of higher level. Al in all Proteus 7.1 is a user friendly tool that can
be used for making some high level schematics and simulation. An ideal application for the
students who want to master their skills relating circuit designs and schematics.

P a g e | 15
Features of Proteus 8
Below are some noticeable features which you’ll experience after Proteus 8 free download.

 Easy to use tool.


 Simple but effective interface.
 Circuit designing and schematic making made easy.
 Provides a powerful working environment.
 Real time design simulation with VSM.
 Can route and edit different components using ARES feature.

3.4 Prog ISP

It is Programming Software for the AVR/8051 Programmer. There are several interesting
options, how to use the USBasp programmer. The LC Soft variant was sold with the option to
download a program called Prog ISP V1.72 from the vendor’s site. Also, a schematic was
available as well as the drivers for Windows. Installation was no problem. Usage of the software
is fairly straight forward. This is used to program the microcontroller ROM memory.

P a g e | 16
4. Hardware Programmer

P a g e | 17
This is the programmer is used to dump the hex file created by keil into the
Microcontroller.

Fig: Connections between AVR/8051 Programmer and Microcontroller

P a g e | 18
5. Design Steps

1. Write the program in Keil

References:

1. The 8051 Microcontroller - Kenneth J. Ayala


2.

P a g e | 19

Вам также может понравиться