You are on page 1of 64

CHAPTER 1

1.1 COMPANY PROFILE


1.1.1 ORIGIN
Emtech Foundation is founded by highly skilled and enthusiastic young embedded engineers.
The founding members of the company are having a rich industrial experience in embedded
system designing. The company is located in New Delhi (India).

1.1.2 CEO
Mr. Naveen Kumar is the Founder Chairman and CEO of the company. He has been the Project
and Chief Training Manager in the relevant industry. He has organized the embedded workshops
in northern and western India, with a high exposure in the robotics design and system analysis.

1.1.3 WORK
Emtech Foundation has highly skilled team for customized product design including hardware
and software, Multilayer PCB Design, prototyping and robot programming. Emtech Foundation
is also having Excellent Training Center on the relevant technologies.

1.1.4 MISSION
Our mission to setup the best Robotic Design Center in India. The Company has a mission to
ready the innate engineer from basic level to a skilled one by providing them training on 8 bit
microcontroller/microprocessor to 64-bit for embedded and robotic design. The Mission
summery is to build the nation with real robotic engineers by providing them right training and
infrastructure.

1
1.1.5 VISION
The time is ruled by NANOTECHNOLOGY AND THE ROBOTICS. The things are getting
automated day by day and we are getting more dependent on machine and auto life.

The coming time will demand for highly skilled robotic engineers and embedded technologists.
All the technologies, whether it is telecommunication, medical engineering, integrated securities
or space technologies all are demanding embedded engineers with a high level of basics.

Emtech Foundation is having a vision over this. We are preparing the real engineers by providing
them excellent infrastructure and highly processed environment to pack them with an extra in the
mean time. The seminars and workshops by edge industry representatives have been proved
unbeatably productive.

Our focus is on engineering students from 3rd semester to the final year. Because the embedded
technologies can give best result and a better direction while one is a student. This focus can
change the view of young engineers over embedded technologies. We have a vision of specified
and easy going theory and practical sessions. Emtech Foundation is having highly equipped labs
and skilled guides.

We, Engineering the Engineers, Emtech Foundation…igniting minds……………..

2
1.2 INTRODUCTION

Microcontrollers 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 performs one task only namely getting the data
and printing it. Contrast this with Pentium based PC. A PC can be used for any no. of
applications such as word processor, print server, bank teller terminal, video game player,
network server or internet terminal. Software for variety of applications can be loaded and run.
Of course the reason a PC can perform multiple task is that it has RAM memory and an
operating system that loads the application software into RAM & lets the CPU run it. In and
Embedded system there is only one application software that is typically burn into ROM. An
x86PC Contain or its connected to various Embedded Products such as keyboard, printer,
modem, Disc controller, Sound card, CD-Rom Driver, Mouse & so on. Each one of these
peripherals as a microcontroller inside it that performs only one task. For example inside every
mouse there is microcontroller to perform the task of finding the mouse position and sending it to
PC.
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, Motorola, AMD & Cyrix have targeted their
microprocessors for the high end of Embedded market. While INTEL, AMD, Cyrix push their
x86 processors for both the embedded and desktop pc market, Motorola is determined to keep
the 68000 families alive by targeting it mainly for high end of embedded system.

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 based on the x86 and 680x0 have low power consumptions in additions to some
forms of I/O, Com port & 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 us.

3
CHAPTER 2
LITERATURE REVIEW
2.1 What IS EMBEDDED SYSTEM?

2.1.1DEFINITION:

 An embedded system is a combination of Hardware and Software design to meet a specific


need with performance in a given time frame.
 An embedded controller is a device that is embedded into some device for some purpose
other than to provide general purpose computing.

FIG 2.1:- EMBEDDED SYSTEM

4
2.2FEATURES OF AN EMBEDDED SYSTEM

2.2.1 REAL TIME AND REACTIVE OPERATIONS

Real time system operation means that the correctness of a computation depends, in part, on the
time at which it is delivered. In many cases the system design must take into account worst case
performance. Predicting the worst case may be difficult on complicated architectures, leading to
overly pessimistic estimates erring on the side of caution. The Signal Processing and Mission
Critical example systems have a significant requirement for real time operation in order to meet
external I/O and control stability requirements. Reactive computation means that the software
executes in response to external events. These events may be periodic, in which case scheduling
of events to guarantee performance may be possible.

On the other hand, many events may be a periodic, in which case the maximum event arrival
rate must be estimated in order to accommodate worst case situations. Most embedded systems
have a significant reactive component.

2.2.2 SMALL AND LOW WEIGHT SIZE

Many embedded computers are physically located within some larger artifact. Therefore, their
form factor may be dictated by aesthetics, form factors existing in pre-electronic versions, or
having to fit into interstices among mechanical components. In transportation and portable
systems, weight may be critical for fuel economy or human endurance. Among the examples, the
Mission Critical system has much more stringent size and weight requirements than the others
because of its use in a flight vehicle, although all examples have restrictions of this type.

SAFE AND RELIABLE

Some systems have obvious risks associated with failure. In mission-critical applications such as
aircraft flight control, severe personal injury or equipment damage could result from a failure of

5
the embedded computer. Traditionally, such systems have employed multiply-redundant
computers or distributed consensus protocols in order to ensure continued operation after an
equipment failure. However, many embedded systems that could cause personal or property
damage cannot tolerate the added cost of redundancy in hardware or processing capacity needed
for traditional fault tolerance techniques. This vulnerability is often resolved at the system level
as discussed later.

HARSH ENVIRONMENT

Many embedded systems do not operate in a controlled environment. Excessive heat is often a
problem, especially in applications involving combustion (e.g., many transportation
applications). Additional problems can be caused for embedded computing by a need for
protection from vibration, shock, lightning, power supply fluctuations, water, corrosion, fire, and
general physical abuse. For example, in the Mission Critical example application the computer
must function for a guaranteed, but brief, period of time even under non-survivable fire
conditions.

COST SENSITIVITY

Even though embedded computers have stringent requirements, cost is almost always an issue
(even increasingly for military systems). Although designers of systems large and small may talk
about the importance of cost with equal urgency, their sensitivity to cost changes can vary
dramatically. A reason for this may be that the effect of computer costs on profitability is more a
function of the proportion of cost changes compared to the total system cost, rather than
compared to the digital electronics cost alone. For example, in the Signal Processing system cost
sensitivity can be estimated at approximately $1000 (i.e., a designer can make decisions at the
$1000 level without undue management scrutiny).

6
However, with in the Small system decisions increasing costs by even a few cents attract
management attention due to the huge multiplier of production quantity combined with the
higher percentage of total system cost it represents.

2.2 APPLICATIONS:-
2.3.1 TELECOM

 Modems and routers

2.3.2 AUTOMOTIVE APPLICATIONS

 Braking system
 Traction control
 Airbag release system

2.3.3 DOMESTIC APPLIANCE

Dishwashers, televisions, Washing machines, Microwave ovens, Video recorders

2.3.4 ROBOTICS

Fire fighting robots, automatic floor cleaner, robotic arm

2.3.5 AEROSPACE APPLICATIONS

Flight control system, engine controller, autopilots

2.3.6 MEDICAL APPLICATION

ECG monitors, MRI scanners

7
2.3.7 DEFENSE SYSTEM

Radar system, radio system, missile guidance system

2.3.8 OFFICE AUTOMATION

Laser printers, fax machines, pagers, cash registers, credit/debit card reader

And Many More….


2.4 WHAT IS A MICROCONTROLLER?

2.4.1 INTRODUCTION:
A microcontroller is a computer-on-a-chip used to control electronic devices. It is a type of
microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a general-
purpose microprocessor, the kind used in a PC. A typical microcontroller contains all the
memory and I/O interfaces needed, whereas a general purpose microprocessor requires
additional chips to provide these necessary functions.
“An embedded controller is a device that is embedded into some device for some purpose
other than to provide general purpose computing.”
Figure shows the block diagram of a typical microcontroller, which is a true computer on a chip.
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.

CPU RAM ROM


A single chip
Serial
I/O Timer COM
Port Port

8
FIG 2.2:- MICROCONTROLLER AS A COMPUTER CHIP

2.5 WHAT IS MICROPROCESSOR?


2.5.1 INTRODUCTION
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. A microprocessor fetches each program instruction in sequence, decodes the
instruction, and executes it. The central processing unit (CPU) is the most well known
microprocessor. Microprocessor means chip used for general purpose programming. For
example 8085, 8086, 80286, 80386, 80486, Pentium etc.
These up contain no RAM, no ROM and no other I/O ports devices on the chip itself.

2.5.2 BLOCK DIAGRAM

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.

Data Bus
CPU
General-
Purpose Serial
Micro- RAM ROM I/O Timer COM
processor Port Port

FIG 2.3:- BLOCK DIAGRAM OF A MICROPROCESSOR

MEMORY:

9
Memory section is mixture of RAM and ROM. the first purpose is to store the binary codes for
the sequences of instructions you want the computer to carry out. Second purpose of the memory
is to store the binary coded data with which the computer is going to be working.

INPUT/OUTPUT PORTS:
The actual physical devices used to interface the computer buses to external systems are often
called ports. An input port allows data from keyboard or some other source to be read into the
computer under control of the CPU .An output port is used to send data from the computer to
some peripheral devices.

CENTRAL PROCESSING UNIT:


CPU controls the operation of the computer. CPU fetches binary-coded instructions from
memory, decodes the instructions into a series of simple action, and carries out these actions in a
sequence of steps.

ADDRESS BUS:
The address bus consists of 6, 20, 24 or 32 parallel signal lines. On these lines the CPU sends out
the address of the memory location that is to be written to or read from.

DATA BUS:
The data bus consists of 8, 6 or parallel signal lines. Indicated by double arrows i.e.; bidirectional
this means CPU can read data in from memory or from a port on these lines.

CONTROL BUS:
The control bus consists of to parallel signal lines. The CPU sends out signals on the control bus
to enable the outputs of addressed memory devices or port devices.

2.6 DIFFERENCE BETWEEN MICRO-PROCESSOR AND MICRO-


CONTROLLER:-

10
Microcontroller and microprocessor stems from the same basic idea yet there exist some
differences. Table1.1 clearly differentiates between microprocessor and microcontroller.

TABLE 2.1:- MICROPROCESSOR V/S MICROCONTROLLER

S.NO. Feature Microprocessor Microcontroller


1. Memory No on chip Ram/Rom On chip Ram/Rom
2. Application General purpose Specific purpose
3. Timer No on chip timer Two on chip timer
4. Opcodes Many opcodes for moving Microcontrollers may
data from external memory have one or two
to the C.P.U. opcodes.
5. Example 8086,80186 8051

2.7 TYPES OF MICROCONTROLLER:

Every application demands a microcontroller that offers the right amount of functionality at the
minimum cost. Applications vary from controlling an appliance to controlling an automobile. No
single microcontroller design can economically meet these demands, so semiconductor
manufacturers offer an array of microcontrollers designed to handle data in 4-, 8-, 16- and 32-bit
words.

2.7.1 FOUR-BIT MICROCONTROLLER:

In terms of sheer volume, 4-bit microcontroller may be used more than any other type. For a
commodity microcontroller, cost depends as much on the volume of the package and the number

11
of pins as on the amount of silicon inside. Pin count, in turn, depends on the number of data bits
commonly handled by the microcontroller, and its I/O capability. Using 4-bits reduces package
cost and pin count to a minimum. Employed in applications ranging from alphanumeric
LED/LCD display drivers to portable battery chargers, these are the least expensive “smart
chips” available. An example of contemporary 4-bit microcontroller is the Renasas M34501, in a
20-pin DIP.

RAM ROM Counters I/O Pins Other Features


256 4k 2 14 A/D

2.7.2 EIGHT-BIT MICROCONTROLLER:

Eight-bit microcontrollers are perhaps the most popular microcontrollers in use today,
Judging from the number of semiconductor companies making them. Eight-bit have proven to be
a very useful word size for everyday controller tasks. Capable of 256 decimal values, or quarter-
percent resolution, the 1-byte data word is adequate for many control and monitoring
applications. Serial ASCII code is also byte size, making 8-bits the natural choice for data
communication applications. In addition, most low-cost RAM and ROM memories store 1-byte
per memory location for easy interfacing to an 8-bit microcontroller.
One indication of the popularity of 8-bit microcontrollers is the fact that some 44 manufacturers
produce over 600 models based on the 8051 architecture alone. Other popular microcontrollers,
such as those designed by Microchip, Motorola, and Zilog, add hundreds of additional choices to
the 8-bit menu. Here is what the 8051 offers when mounted in a 40-pin DIP:

RAM ROM Counters I/O Pins Other Features


128 bytes 4k 2 32 UART

2.7.3 SIXTEEN-BIT MICROCONTROLLERS:

Sixteen-bit microcontrollers offer much of the generality of 8-bit models, but with greatly
increased memory size and speed. Sixteen-bit microcontrollers are much better suited for
programming in high-level languages, such as C.

12
Application of 16-bit microcontrollers are calculation and data intensive and include disk drives,
modems, printers, scanners, pattern recognition, and automotive and servomotor control. A
typical 16-bit microcontroller, the Motorola 68HC16Z3, has these attributes when mounted in a
144-lead LQFP package:

RAM ROM Counters I/O Pins Other Features


4k 8k 2 24 A/D,UART

2.7.4 THIRTY-TWO-BIT MICROCONTROLLERS:

Thirty-two-bit microcontrollers are currently evolving away from general purpose applications to
targeted markets such as PDAs, GPS, automotive control, communication networks, robotics,
entertainment/game boxes, digital cameras, cell phones, and similar high-end uses. As an
example, the Sharp LH79520 housed in a 176-pin LQFP package offers following features, most
of which could be used to implement a notebook computer: 32k RAM, color LCD controller,
three UARTs, synchronous serial, two PWMs, 64 I/O pins, four counters, WDT , real-time-
clock, PLL, and direct memory access (DMA). Clearly the development of 32-bit
microcontrollers is driven by large, well-defined markets.

Sales
in
million

FIG 2.4:- COMPARISON OF DIFFERENT MICROCONTROLLERS

2.8 8051 MICROCONTROLLER


2.8.1 A BRIEF HISTORY:
 In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051.

13
 This microcontroller had 128 bytes of RAM, 4k bytes of on-chip ROM, two timers, one
serial port, and four ports9 each 8-bits wide) all on a single chip. At that time I was referred
to as a “system on a chip”.
 The 8051 is an 8-bit processor, meaning that the CPU can work only 8 bits of data at a time.
Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU.
 Intel refers to it as MCS-51 now.

2.8.2 STANDARD FEATURES:


 8 bit data path and ALU.
 4k*8 ROM-program memory.

 128*8 RAM-data memory.


 Multiple 16-bit Timer/Counter.
 On chip clock oscillator.

2.8.3 Family members of 8051:

Family members of 8051 microcontroller are 8031, 8032 and 8052. Table 1.2 shows the features
of different family members 8051.

TABLE 2.2: FAMILY MEMBERS OF 8051

Feature 8051 8031 8052 8032

ROM 4K 0K 8K 0K

RAM(bytes) 128 128 256 256

Timers 2 2 3 3

I/O Pins 32 32 32 32

Serial Port 1 1 1 1

Interrupt 6 6 7 7
sources

14
2.8.4 VERSION OF 8051 MICROCONTROLLER:

Intel allowed other manufacturers to make and market any version of 8051 depending upon the
speed and on chip ROM. All versions are code compatible.

 AT89C51from ATMEL CORPORATION:


On chip ROM flash memory, erase cycles in seconds, furnish fast development.

 DS5000 from Dallas Semiconductor:


On chip ROM in form of NV-RAM form. NV-RAM has the ability to change the ROM
contents one byte at a time.

 OTP( one time programmable) version of 8051:


For mass production, low cost

 8051 family from Philips:


One of the largest selections of 8051 microcontrollers, various features like ADC, DAC,
extended I/O, both OTP and flash.

“There are more than 50 companies like ST, TI, SIEMENS, and WINBOND
etc. making microcontroller chips based on Intel 8051 architecture world
wide.”

2.9 BLOCK DIAGRAM OF 8051

15
FIG 2.5: BLOCK DIAGRAM OF 8051

2.9.1 INTERRUPT CONTROL

The interrupt control basically handles the interrupts whether they should be handled or.
For the same purpose two registers of 8-bits are present i.e. IP and IE i.e. interrupt
priority and interrupt enable.

2.9.2 ON CHIP FLASH


Flash memory is present on the chip.

2.9.3 ON CHIP RAM


RAM is also present on the chip.

2.9.4 TIMER
Timer control registers of 8 bits are also present on the chip. The counter input is given
to the timers.

16
2.9.5 SERIAL PORTS
The serial ports are also present on chip which allows the microcontroller to
communicate serially.

2.9.6 I/O PORTS


The I/O ports basically provides the input and output ports. These are present on the chip
of microcontroller itself. They are of 8 bits. Basically there are 4 ports i.e. port 0, port 1,
port 2 and port 3. PORT 0 provides both data and addresses along with I/O pins. PORT 1
provides only I/O pins. PORT 2 provides I/O pins and the remaining addresses. PORT 3
provides I/O pins and WR, RD, T0, T1, INT0, INT1, RXD, TXD.

2.9.7 BUS CONTROL


The control registers are present i.e. TCON, TMOD, SCON, PCON, IP, IE.

2.9.8 OSCILLATOR
A particular frequency is provided i.e. 11.0592 MHz by a crystal oscillator.
2.10 PIN DIAGRAM OF 8051:

17
FIG 2.6:- PIN DIAGRAM OF 8051
2.10.1 PIN DESCRIPTION:

18
8051 is a 40 pin IC packed in DIP (Dual line packaging). This means that the pin performs the
dual functions. Basically 8051 is a 40 pin IC but it performs 64 functions. This is due to the
reason that 24 pins are multiplexed pins. So these pins perform dual functions and make it a total
of 64 functions.

 PORT 0-PINS(32-39)
• Input/output pins.
• Required external pull-up resistors of 10K ohm.
• Used both as I/O port and higher address byte.

FIG 2.7:- PORT 0 WITH PULL-UP RESISTOR

 PORT 1-PINS (1-8):


• Input /output pins.
• Contains internal pull-ups.

 PORT 3-PINS (10-17):

19
• Input/output pins.
• Contains internal pull-ups.
• Alternate functions to provide signals such as interrupts.

PINS : DESCRIPTION
RXD (P3.0) : Serial input port
TXD (P3.1) : Serial output port
INT0 (P3.2) : External interrupt
INT1 (P3.3) : External interrupt
T0 (P3.4) : Timer 0 external input
T1 (P3.5) : Timer 1 external input
WR (P3.6) : External data memory writes strobe
RD (P3.7) : External data memory read strobe

 PORT 2-PINS (21-28):


• Input/output port.
• Contains internal pull-ups.
• Used both as I/O port and higher address byte.

 PSEN-(PIN 29): PROGRAM STORE ENABLE


• Active low input
• Used while accessing external memory.
• Connected to OE pin of external ROM.

 ALE-(PIN 30): ADDRESS LATCH ENABLE


• Active high.
• Used for de-multiplexing the address and data by connecting G pin of 74LS373.

 EA-(PIN 31): EXTERNAL ACCESS


• Active low input.
• To access external ROM it must be grounded.

20
 XTAL1 AND XTAL2-(PIN 18 AND PIN 19):
• Provides electric field to quartz crystal oscillator for oscillations.

 RESET-(PIN 9):
• Active high input.
• Terminate all activities of microcontroller.
• Sets PC to 0000h
• Requires minimum 2 machine cycles.

TABLE 2.3- RESET VALUE OF SOME 8051

REGISTER RESET VALUE

PC 0000 h
ACC 0000 h
B 0000 h
PSW 0000 h
SP 0007 h
DPTR 0000 h

 VCC-(PIN 40):
• Provides supply voltage to the chip. The voltage source is+5v.

 GND-(PIN 20):
• This pin is grounded

 CRYSTAL CONNECTION:
• The 8051 has an on-chip oscillator but requires an external clock to run it. Most
often a quartz crystal is connected to inputs XTAL1 (pin 19) and XTAL2 (pin18). The
quartz crystal connected to XTAL1 and XTAL2 also needs two capacitors of 30pf value.
One side of each capacitor is connected to ground as shown in figure 1.8.

21
C2
2
XTAL2
33pf

33pf

XTAL1
C1
11

GROUND

FIG 2.8:- CRYSTAL CONNECTION TO 8051

• If a frequency source other than a crystal oscillator, such as TTL oscillator then it will be
connected to XTAL1 and XTAL2 is left unconnected as shown in figure.

NC XLAT1

External
XLAT2
oscillator signal

GROUND

FIG 3.8:-CRYSTAL CONNECTION TO AN EXTERNAL CLOCK SOURCE

• The time to execute any instruction can be found by multiplying the no. of cycles by 12
and then dividing the product by the crystal frequency:

Tinst = (C*12)/CRYASTAL FREQUENCY

2.11 INTERNAL MEMORY:

22
A functioning computer must have memory for program code bytes, commonly in ROM, and
RAM memory for variable data that can be altered as the program runs. The 8051 has internal
RAM and ROM memory for these functions.

2.11.1 INTERNAL RAM:

The 128-byte internal RAM, which is organized into three distinct areas:

1. Thirty-two bytes from address 00h to 1Fh that makes up 32 working registers organized as
four banks of eight register each. The four banks are numbered 0 to 3and are made up of
eight registers named R0 to R7. Each register can be addressed by name or by its RAM
address. Thus R0 of bank 3 is R0 (if bank 3 is currently selected0 or by its RAM address 18h
(whether bank 3 is selected or not). Bits RS0 and RS1 in the PSW determine which bank of
registers is currently in use at any time when the program is running. Register bank not
selected can be used as general purpose RAM. Bank 0 is selected on reset.
2. A bit-addressable area of 16 bytes occupies RAM byte addresses 20h to 2Fh, forming a
total of 128 addressable bits.
3. A general purpose RAM area above the bit area, from 30h to 7Fh, addressable as bytes.

2.11.2 STACK AND STACK POINTER:

 The Stack refers to an area of internal RAM that is used in conjunction with certain opcodes
to store and retrieve data quickly. The 8-bit Stack Pointer (SP) register is used by the 8051 to
hold an internal RAM address that is called “the top of the stack”. The address held in SP
register is the location in internal RAM where the last byte of data was stored by a stack
operation.
 When data is to be placed on the stack, the SP increments before storing data on the stack so
that the stack grows up as data is stored. As data is retrieved from the stack, the byte is read
from the stack, and then the SP decrements to point to the next available byte of stored data.
 Operation of the stack and the SP register is shown in figure. The stack is set to 07h when
8051 is reset and can be changed to any internal RAM address by the programmer, using a
data move command.

23
PUSH POP

SP=0A Store Data Address 0A Get Data SP=0A

Address 09 SP=09
SP=09 Store Data Get Data

Address 08 SP=08
SP=08 Store Data Get Data

Address 07 SP=07
SP=07

Storing data on the Stack Internal RAM Getting data from the Stack
(Increment then store) (Get then decrement)

FIG 2.9: -STACK OPERATION

2.11.3 INTERNAL ROM:


The 8051 is organized so that data memory and program code memory can be in two entirely
different physical memory entities. Each has the same address ranges. The structure of internal
RAM has been discussed previously. A corresponding block of internal ROM occupies code
address space 0000h to 0FFFh. Following are some features internal ROM:
 Begins from location 0000h
 Each interrupt is assigned a fixed location in it (0000-0023H)
The PC is used to address program code bytes from addresses 0000h to 0FFFh.

Byte

0000
INTERNAL
ROM

0FFF
FIG 2.10:- INTERNAL ROM

24
2.11.4 MACHINE CYCLE AND STATE:

 The smallest interval of time to accomplish any simple instruction, or part of a complex
instruction is called a machine cycle.
 The machine cycle is itself made up of six states.
 A state is the basic time interval for discrete operations of the microcontroller such as
fetching an opcode byte, decoding an opcode, executing an opcode, or writing a data byte.
 Two oscillator pulses define each state. The clock frequency, f, establishes the smallest
interval of time within the microcontroller, called the pulse, p, time.
 Program instructions may require one, two, or four machine cycles to be executed, depending
on the type of instruction.
 If number of cycles to execute an instruction are known, then execution time of that
instruction is given by:
T (instruction) = (C*12)/crystal frequency
P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2

State 1 State 2 State 3 State 4 State 5 State 6

One Machine Cycle

FIG 2.11:-ONE COMPLETE MACHINE CYCLE

2.11.5 SPECIAL FUNCTION REGISTER:


 The 8051 operations that don’t use the 128-byte internal RAM addresses from 00h to 7Fh are
done by a group of specific internal register, each called a Special Function register (SFR),
which may be addressed much like internal RAM, using addresses 80h to FFh.

25
 Some SFRs are also bit addressable, as in the case for bit area of RAM. This feature allows
the programmer to change only what needs to be altered, leaving the remaining bits in the
SFR unchanged.
 Special Function Register Map is shown in figure 1.16.
 SFR map includes following registers:

 CPU Register
- ACC : ACCUMULATOR
- B : B REGISTER

 I/O PORT
- P0 : PORT 0 LATCH
- P1 : PORT 1 LATCH
- P2 : PORT 2 LATCH
- P3 : PORT 3 LATCH

 TIMERS
- TMOD : TIMER/COUNTER MODE CONTROL
- TCON : TIMER/COUNTER CONTROL
- TH0 : TIMER 0 LOW BYTE
- TL0 : TIMER 0 HIGH BYTE
- TH1 : TIMER 1 LOW BYTE
- TL1 : TIMER 1 HIGH BYTE

 SERIAL I/O
- SCON : SERIAL PORT CONTROL
- SBUF : SERIAL PORT DATA BUFFER

 OTHER
- PCON : POWER CONTROL
26
2.11.6 A AND B REGISTER:

The 8051 contains 34 general-purpose or working registers. Two of these, register A and B, hold
results of many instructions, particularly math and logical operations, of the 8051 central
processing unit (CPU).

 A (ACCMULATOR)
• 8-bit register and is used as working register for the arithmetic and logical instructions.
• Also used for all data transfer between the 8051 and any external memory
• Can be used as working register.
• Necessary for some instructions.

 B REGISTER:
• 8-bit register and can be used as general purpose register.
• Necessary for the instructions MUL and DIV

2.11.7 FLAGS AND THE PROGRAM STATUS WORD (PSW):


 Flags are 1-bit registers provided to store the results of certain program instructions. Other
instructions can test the condition of the flags and make decisions based on the flag states. In
order that the flags may be conveniently addressed, they are grouped inside the program
status word (PSW) and the power control (PCON) registers.
 The 8051 has four math flags that respond automatically to the outcomes of math operations
and three general-purpose user flags that can be set to1 or cleared to 0 by the programmer as
desired. The math flag include Carry (C), Auxiliary Carry (AC), Overflow (OV), and parity
(P). User flags are named F0, GF0, and GF1; they are general-purpose flags that may be used
by the programmer to record some event in the program.

27
 The program status word is shown in figure. The PSW contains the math flags, user program
flag F0, and the register select bits that identify which of the four general-purpose register
banks is currently in use by the program.

TABLE 2.4: PROGRAM STATUS WORD


7 6 5 4 3 2 1 0
CY AC F0 RS1 RS0 OV -------- P

BIT SYMBOL FUNCTION

7 CY Carry flag; used in arithmetic, jump, rotate and Boolean


instruction

6 AC Auxiliary Carry flag; used for BCD arithmetic

5 F0 User flag 0

4 RS1 Register bank select bit 1

3 RS0 Register bank select bit 0

RS1 RS0
0 0 Select register bank 0
0 1 Select register bank 1
1 0 Select register bank 2
1 1 Select register bank 3

2 OV Overflow flag; used in arithmetic instructions

1 ----- Reserved for future use

0 P Parity flag; shows parity of register A: 1= Odd parity

3.9 COUNTERS addressable


“BitAND TIMERS as PSW.0 to PSW.1”

Many microcontroller applications require the counting of external events, such as the frequency
of a pulse train, or the generation of precise internal time delays between computer actions. Both
of these tasks can be accomplished using software techniques, but software loops for counting or

28
timing keep the processor occupied so that other, perhaps more important, functions are not
done. To relieve the processor of this burden, two 16-bit up counters, named T0 and T1, are
provided for the general use of the programmer. Each counter may be programmed to count
internal clock pulses, acting as a timer, or programmed to count external pulses as a counter.

2.12 TIMER
Both timer 0 and timer 1 are 16 bits wide. Since the 8051 has an 8-bit architecture, each 16-bit
timer is accessed as two separate registers of low byte and high byte.

2.12.1 TIMER 0 REGISTER:


The 16-bit register of timer 0 is accessed as low and high byte. The low byte register is called
TL0 (timer 0 low byte) and the high byte register is referred to as TH0 (timer 0 high byte). These
registers can be accessed like any other register, such as A, B, R0, R1, R2 etc. For example, the
instruction “MOV TL0, #4Fh” moves the value 4Fh into TL0, the low byte of timer 0. These
registers can also be read like any other register. For example, “MOV R5, TH0” saves TH0 (high
byte of timer 0) in R5.

TH0 TL0

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

FIG 2.11: TIMER 0 REGISTER


2.12.2 TIMER 1 REGISTER:
Timer 1 is also 16 bits, and its 16-bit register is split into two bytes, referred to as TL1 (timer 1
low byte) and TH1 (timer 1 high byte). These registers are accessible in the same way as the
registers of timer0.

TH1 TL1

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

FIG 2.12: TIMER 1 REGISTER

29
2.12.3 TIMER ACTION:
All counter action is controlled by bit states in the timer mode control register (TMOD), the
timer/counter control register (TCON), and certain program instructions.

 THE TIMER CONTROL (TCON) SPECIAL FUNCTION REGISTER:

TABLE 2.5: TCON REGISTER


7 6 5 4 3 2 1 0
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

BIT SYMBOL FUNCTION


7 TF1 Timer 1 Overflow flag. Set when timer rolls from all 1s to 0.
Cleared when processor vectors to execute interrupt service
routine located at program address 001Bh.

6 TR1 Timer 1 run control bit. Set to 1 by program to enable timer


to count; cleared to 0 by program to halt timer. Does not
reset timer.

5 TF0 Timer 0 Overflow flag. Set when timer rolls from all 1s to 0.
Cleared when processor vectors to execute interrupt service
routine located at program address 000Bh.

4 TR0 Timer 0 run control bit. Set to 1 by program to enable timer


to count; cleared to 0 by program to halt timer. Does not
reset timer

3 IE1 External interrupt 1 Edge flag. Set to 1 when a high-to-low


edge signal is received on port 3 pin 3.3. Cleared when
processor vectors to interrupt service routine located at
program address 0013h. Not related to timer operations.

2 IT1 External interrupt 1 signal type control bit. Set to 1 by


program to enable external interrupt 1 to be triggered by a
falling edge signal. Set to 0 by program to enable a low-
level signal on external interrupt 1 to generate an interrupt.

1 IE0 External interrupt 0 Edge flag. Set to 1 when a high-to-low


edge signal is received on port 3 pin 3.2. Cleared when
processor vectors to interrupt service routine located at
program address 0003h. Not related to timer operations.

30
0 IT0 External interrupt 0 signal type control bit. Set to 1 by
program to enable external interrupt 1 to be triggered by a
falling edge signal. Set to 0 by program to enable a low-
level signal on external interrupt 1 to generate an interrupt.

“BIT ADDRESSABLE AS TCON.0 TO TCON.7”

 THE TIMER MODE CONTROL (TMOD) SPECIAL FUNCTION REGISTER:

TABLE 2.6: TMOD REGISTER


7 6 5 4 3 2 1 0

Gate C/T M1 M0 Gate C/T M1 M0


Timer 1 Timer 0

BIT SYMBOL FUNCTION


7/3 GATE OR gate enable bit which controls RUN/STOP of timer
1/0. Set to 1 by program to enable timer to run if bit
TR1/0 in TCON is set and signal on external interrupt
INT1/0 pin is high. Cleared to 0 by program to enable
timer to run if bit TR1/0 in TCON is set.

6/2 Set to 1 by program to make timer 1/0 act as a counter


C/T pulses from external input pins 3.5 (T1) or 3.4 (T0).
5/1 M1 Timer/counter operating mode select bit 1. Set/cleared by
program to select mode.

4/0 M0 Timer/counter operating mode select bit 0. Set/cleared by


program to select mode.
M1 M0 MODE
0 0 0
0 1 1
1 0 2
1 1 3

“TMOD IS NOT BIT ADDRESSABLE”

2.13 TIMER MODES:


The timer may operate in any one of four modes that are determined by the mode bits, M1 and
M0, in the TMOD register. Figure shows the four timer modes.

31
TABLE 2.7: TIMER MODES

M1 M0 MODE OPERATING MODE


0 0 0 13-bit timer mode
8-bit timer/counter THx with TLx
as 5-bit prescalar
0 1 1 16-bit timer mode
16-bit timer/counter THx and TLx
are cascaded; there is no prescalar
1 0 2 8-bit auto reload
8-bit auto reload timer/counter;
THx holds a value which is to be
reloaded into TLx each time it
overflows.
1 1 3 Split timer mode

2.13.1 TIMER MODE 0


Setting timer X mode bits to 00b in the TMOD register results in using the THX register as an 8-
bit counter and TLX as a 5-bit counter; the pulse input is divided by 32d in TL so that TH counts
the original oscillator frequency reduced by a total 384d. As an example, the 6 megahertz
oscillator frequency would result in a final frequency to TH of 15625 hertz. The timer flag is set
whenever THX goes from FFh to00h, or in .0164 seconds for a 6 megahertz crystal if THX starts
at 00h.

PULSE
INPUT TLX 5 Bits THX 8 Bits TFX Interrupt
FIG 2.13:- TIMER MODE 0 13-BIT TIMER/COUNTER

2.13.2 TIMER MODE 1


The following are the characteristics and operation of mode 1:
1. It is a 16-bit timer; therefore, it allows values of 0000h to FFFFh to be loaded into the
timer’s registers TL and TH.
2. After TL and TH are loaded with a 16-bit initial value, the timer must be started. This is
done by “SETB TR0” for timer 0 and “SETB TR1” for timer 1.

32
3. After the timer is started, it starts to count up. It counts up until it reaches its limit of
FFFFh. When it rolls over from FFFFh to 0000, it sets high a flag bit called TF (timer
flag). This timer flag can be monitored. When this timer flag is raised, one option would
be to stop the timer with the instructions “CLR TR0” or “CLR TR1”, for timer 0 and
timer 1, respectively. Again, it must be noted that each timer has its own timer flag; TF0
for timer 0, and TF1 for timer 1.
4. After the timer reaches its limit and rolls over, in order to repeat the process the register
TH and TL must be reloaded with the original value, and TF must be reset to 0.

XTAL TH TF
/12d H
TL
H
Oscillator

TF goes high Overflow


C/T=0 TR When FFFF 0 Flag

FIG 2.14:- TIMER MODE 1 OPERATION

2.13.3 TIMER MODE 2


The following are the characteristics and operation of mode 2:
1. It is an 8-bit timer; therefore, it allows only values of 00 to FFh to be loaded into the
timer’s register TH.
2. After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL. Then the timer
must be started. This sis done by the instruction “SETB TR0” for timer 0and “SETB TR1”
for timer 1.this sis just like mode 1.
3. After the timer is started, it starts to count up by incrementing the TL register. It
counts up until it reaches its limit of FFh. When it rolls over from FFh to 00, it sets high the
TF (timer flag). If we are using timer 0, TF0 goes high; if we are using timer 1, TF1 is
raised.

33
XTAL /12d TL TF
Oscillator

TF
C/T=0 TR GOES
RELOAD HIGH
TH WHEN
FF 0

FIG 2.15:- TIMER MODE 2 OPERATION

4. When the TL register rolls from FFh to 0 and TF is set to 1, TL is reloaded automatically
with the original value kept by the TH register. To repeat the process, we must simply clear
TF and let it go without any need by the programmer to reload the original value. This
makes mode 2 an auto reload, in contrast with mode 1 in which the programmer has to
reload TH and TL. It must be emphasized that mode 2 is an 8-bit timer. However, it has an
auto-reloading capability. In auto-reload, TH is loaded with the initial count and a copy of
it is given to TL. This reloading leaves TH unchanged, still holding a copy of original
value.

2.13.4 TIMER MODE 3


1. Timer 0 and 1 may be programmed to be in mode 0, 1, or 2independently of asimilar
mode for the other timer. This is not true for mode 3; the timers don’t operate
independently if mode 3 is chosen for timer 0. Placing timer 1 in mode 3cause tit to stop
counting; the control bit TR1 and the timer1 flag TF1 are then used by timer 0.
2. Timer 0 in mode 3 becomes two completely separate 8-bit counters. TL0 is controlled by
the gate and sets timer flag TF0whenever it overflows from FFh to 00h. TH0 receives the
timer clock (the oscillator divided by 12) under the control of TR1only and sets the TF1
flag when it overflows.
3. Timer 1 may still be used in modes 0, 1, and 2, while timer 0 in mode 3with one
important exception: NO interrupts will be generated by timer 1 while timer 0 is using the
TF1 overflow flag. Switching timer1 to mode 3 will stop it (and hold whatever count is in
timer 1). Timer 1 can be used for baud rate generation for the serial port, or any other
mode 0, 1, or 2 function that doesn’t depend on an interrupt (or any other use of the TF1
flag) for proper operation.

34
2.14 COUNTING:
In the last section we used the timer/counter of the 8051 to generate time delays. These timers
can also be used as counters counting events happening outside the 8051. For the timer/counter
when it is used as a timer, the 8051’s crystal is used as the source of frequency. However, when
it is used as a counter, it is a pulse outside of the 8051 that increments the TH, TL register. In
counter mode, the TMOD and TH, TL registers are the same as for the timer. The timer’s modes
are the same as well.

2.14.1 C/T BIT IN TMOD:


The C/T bit in the TMOD register decides the source of the clock for the timer. If C/T= 0, the
timer gets pulses from the crystal. In contrast, when C/T= 1, the timer is used as a counter and
gets its pulses from outside the 8051. Therefore, when C/T=1, the counter counts up as pulses are
fed from pin 14 and 15. These pins are called T0 (timer 0 input) and T1 (timer 1 input). In the
case of timer 0, when C/T= 1, pin3.4 provides the clock pulses and the counter counts up for
each clock pulse coming from that pin. Similarly, for timer 1, when C/T=1 each clock pulse
coming in from pin3.5 makes the counter count up.

2.15 8051 SERIAL COMMUNICATION:-


 When a microprocessor communicates with the outside world, it provides the data in byte-
sized chunks. In some cases, such as printers, the information is simply grabbed from the 8-
bit data bus and presented to the 8-bit data bus of the printer. This can work only if the cable
is not too long, since long cables diminish and even distort signals. Furthermore, an 8-bit data
path is expensive. For these reasons, serial communication is used. Figure compares serial
data transfer with parallel data transfers.

35
SERIAL TRANSFER

SENDER RECEIVER

PARALLEL TRANSFER
D0

SENDER RECEIVER

D7

FIG 2.16:- SERIAL COMMUNICATION

 The fact that in serial communication a single data line is used instead of the 8-bit data line of
parallel communication makes it not only much cheaper but also makes it possible for two
computers located in two different cities to communicate over the telephone.
 For serial data communication to work the byte of data must be converted to serial bits using
a parallel-in-serial-out shift register; then it can be transmitted over a single data line. This
also means that at the receiving end there must be a serial-in-parallel-out shift register to
receive the serial data and pack them into a byte. Of course, if data is to be transferred on the
telephone line, it must be converted from 0s and 1s to audio tones, which are sinusoidal-
shaped signals. This conversion is performed by a peripheral device called a modem, which
stands for “modulator/demodulator”.

2.15.1 METHODS:-
Serial data communication uses two methods, asynchronous and synchronous. The synchronous
method transfers a block of data (characters) at a time while the asynchronous method transfers a
single byte at a time. It is possible to write software to use either of these methods, but the
programs can be tedious and long. For this reason, there are special IC chips made by many

36
manufacturers for serial data communication. These chips are commonly referred to as UART
(Universal asynchronous receiver-transmitter). The 8051 has a built-in UART.

SIMPLEX
TRANSMITTER RECEIVER

TRANSMITTER
HALF DUPLEX RECEIVER

TRANSMITTER
RECEIVER

TRANSMITTER
FULL DUPLEX RECEIVER

TRANSMITTER
RECEIVER

FIG 2.17:- SIMPLEX, HALF, AND FULL-DUPLEX

 HALF- AND FULL-DUPLEX TRANMISSION


In data transmission if the data can be transmitted and received, it is a duplex transmission. This
is in contrast to simplex transmissions Duplex transmission can be half or full duplex, depending
on whether or not the transfer can be simultaneous. If data is transmitted on way at a time, it is
referred to as half duplex. If data can go both ways at the same time, it is full duplex.

3.12.2 HOW 8051 PERFORMS DATA TRANSFER


The 8051 uses register SBUF to hold data. Register SCON controls data communication, register
PCON controls data rates, and pin RXD (P3.0) and TXD (P3.1) connect to the serial data
network. SBUF is physically two register. One is write only and is used to hold data to be
transmitted out of the 8051 via TXD. The other is read only and holds received data from
external sources via RXD. Both mutually exclusive registers use address 99h.

 SERIAL PORT CONTROL(SCON):

SM0 SM1 SM2 REN TB8 RB8 TI RI


37
Bits

7 6 5 4 3 2 1 0 Bit No

TABLE 2.8 SCON REGISTER

BIT SYMBOL FUNCTION


7 SM0 Serial port mode bit0. Set / cleared by program
to select mode.
6 SM1 Serial port mode bit0. Set / cleared by program
to select mode.

5 SM2 Multiprocessor communication bit. Set/ cleared


by program to enable multiprocessor communication
4 REN Receive enable bit.
3 TB8 Transmitted bit 8
2 RB8 Receive bit 8
1 TI Transmit interrupt flag.
0 RI Receive interrupt flag.

 POWER MODE CONTROL(PCON):

SMOD -------- -------- -------- GF1 GF0 PD IDL

The various pins of PCON register are explained below:-


TABLE 2.9 PCON REGISTER

BIT SYMBOL FUNCTION


7 SMOD Serial baud rate modify bit. Set to 1 by program to
double baurd rate using timer1.
6-4 ____ Not implemented

3 GF1 General purpose user flag bit1. Set/cleared by


program.
2 GF0 General purpose user flag bit0. Set/cleared by
program.
1 PD Power down bit.

38
0 IDL Idle mode bit.

“PCON is not bit addressable”

2.16 INTERRUPTS:
“Occurrence of any disturbance/ intervention within progress of work is called an
Interrupt.”
TABLE 2.10: INTERRUPT VERSUS POLLING

INETRRUPTS POLLING

The external/internal circuit generates a The microcontroller continuously monitors


signal or request to microcontroller then it the status of pin/device if the condition is
performs the task accordingly. met, then it perform the task assigned.

If more than one interrupts generate request No priority level assignment since it checks
to microcontroller then microcontroller all devices in round-robin fashion.
executes them sequentially as per defined
PRIORITY.

The program which is associated with the Not such condition.


interrupt is called interrupt service routine.

INTERRUPTS

MASKABLE NON-MASKABLE

External interrupts RESET


Timer interrupts
Serial interrupts

FIG 2.18: TYPES OF INTERRUPTS

39
2.16.1 INTERRUPT SERVICE ROUTINE:
 When interrupt is active then microcontroller runs the interrupt service routine.
 For every interrupt there is fixed location in program memory that is known as interrupt
vector table.
 There are six interrupts in 8051 among them RESET is default interrupt.

TABLE 2.11: INTERRUPT SERVICE ROUTINE

INETRRUPT SOURCE VECTOR ADDRESS

System Reset RST 0000H

External 0 IE0 0003H

Timer 0 TF0 000BH

External 1 IE1 0013H

Timer 1 TF1 001BH

Serial port RI or TI 0023H

2.16.2 WHAT HAPPENS WHEN INTERRUPT OCCURS?


When an interrupt signal comes, the following actions are taken automatically by
microcontroller:
1. The current memory location of Program counter saved on to the stack, low byte first.
2. Interrupts of the same and lower priority are blocked.
3. In the case of Timer and External interrupts, the corresponding interrupt flag is cleared.
4. Program execution transfers PC to the corresponding interrupt handle vector address.
5. The interrupt handler routine executes the program.

 IE: INTERRUPT ENABLE REGISTER (BIT ADDRESSABLE):

EA ----- ------ ES ET1 EX1 ET0 EX0

40
EA IE.7 Disables all interrupts if EA=0. If EA=1, interrupt source is
individually enable or disabled by setting or clearing its enable bit.
- IE.6 Not implemented, reserved for future use.
- IE.5 Not implemented, reserved for future use.
ES IE.4 Enable or disable the serial port interrupt
ET1 IE.3 Enable or disable the timer 1 overflow interrupt
EX1 IE.2 Enable or disable external interrupt 1
ET0 IE.1 Enable or disable the timer 0 overflow interrupt
EX0 IE.0 Enable or disable external interrupt 0

 IP: INTERRUPT PRIORITY REGISTER (BIT ADDRESSABLE):

----- ------ ------ PS PT1 PX1 PT0 PX0

-- IP.7 Not implemented, reserved for future use.


-- IP.6 Not implemented, reserved for future use.
-- IP.5 Not implemented, reserved for future use.
PS IP.4 Defines the serial port interrupt priority level.
PT1 IP.3 Defines the timer 1 interrupt priority level.
PX1 IP.2 Defines external interrupt priority level.
PT0 IP.1 Defines the timer 0 interrupt priority level.
PX0 IP.0 Defines the external interrupt 0 priority level.

2.17 8051 PROGRAMING:


8051 can be programmed using assembly and high level language e.g. C

FIG 2.19:-8051 PROGRAMMING LANGUAGES

2.17.1 ASSEMBLY LEVEL LANGUAGE:


41
 Assembly level language is defined by a set of rules that specify the symbols that can be used
and they may be combined to form a line of code.
 The instruction set has a specific format.

[Label:] Mnemonics Operand [; Comment]


 Name of the label should be meaningful giving the reflection of the code functionality. For
example, LED_ON: label indicates the switch on the led.
 First character of a label should be an alphabet. Number of character should not be more
than 8 characters.
 Reserved words must not be used as label. Mnemonics are assembly opcodes.
For example, MOV
ADD
RLC
 The operand can be data or address.
 Mnemonic can be one byte or more.
 Comment begins with semicolon comment indicator. Comments should be small and
meaningful. Assembler ignores comments, but they are indispensable to programmer.

2.17.2 HIGH LEVEL LANGUAGES:


 High level languages are the language whose instruction set is more compatible with human
languages and human thought processes.
 High level languages offer three significant advantages over machine/ assembly language:
1. Simplicity
2. Uniformity
3. Portability
 In high level language the programmer do not concern with internal detail of microcontroller.

2.17.3 WHY USE ASSEMBLY LANGUAGE:


There are at least five reasons to write computer instructions in assembly language:
 To speed computer operation.

42
 To reduce the size of the program.
 To write programs for special situations.
 To save money.
 To better understand how computer operate.

“Speed, size and uniqueness are advantages assembly language programs offer over high
level languages.”

2.17.4 ADDRESSING MODES:


 The various ways of accessing data are called addressing modes.
 The different addressing modes are:
1. Immediate addressing mode.
2. Register addressing mode
3. Direct addressing mode
4. Indirect addressing mode

 IMMEDIATE ADDRESSING MODE:


• The operand comes immediately after the opcode.
• Immediate data must be preceded by the pound (#) sign.
• And can be used to load information into any of the register and memory location.
MOV A,#25h
MOV R0,#65h
MOV 30h,#20h

 REGISTER ADDRESSING MODE:


• This mode involves the use of register to hold the data to be manipulated.
MOV A,R0
MOV R1,A
MOV A,R6

43
 DIRECT ADDRESSSING MODE:
• The data is in Ram memory location and whose address is known.
• The address is given as a part of instruction.
MOV 30h, A
MOV R0,40h
MOV A,20h

 REGISTER INDIRECT ADDRESSING MODE:


• A register is used as pointer to data.
• As the register holds the address of RAM location they must be preceded by “@”
sign.
• Only register R0, R1 are used for this purpose.
MOV @R1, B; Move contents of register B into RAM location whose address is held by R1.

2.17.5 INSTRUCTION SET:


There are four types of instruction which are used in 8051 programming.

44
FIG 2.20:- TYPES OF INSTRUCTION

 ARITHMATIC INSTRUCTIONS:

TABLE 2.12: ARITHMATIC INSTRUCTION

BYTES/CYCLE
MNEMONICS OPERANDS S

ADD A,Rn 1/1


ADDC A,Direct 2/1
SUBB A,@Ri 1/1
A,#data 2/1
INC A 1/1
DEC RN 1/1
DIRECT 2/1
@ Ri 1/
INC DPTR 1/2
MUL AB 1/4
DIV AB 1/4
DA A 1/1

45
 LOGICAL INSTRUCTIONS:

TABLE 2.13 LOGICAL INSTRUCTIONS

MNEMONIC OPERANDS BYTES/CYCLE

ANL A,Rn 1/1

ORL A,direct 2/1

XRL A,@Ri 1/1


A,#data 2/1
Direct,A 2/1
Direct,#data 3/2
C,bit 2/2

CLR A 1/1

 DATA TRANSFER INSTRUCTIONS:

TABLE 2.14: DATA TRANSFER INSTRUCTIONS


3
MNEMONIC OPERANDS BYTES/CYCLE

MOV A, Rn 1/1
A, Direct 2/1
A, Ri 1/1
A, #Data 2/1
Rn, A 1/1
Rn, Direct 2/2
Rn, #Data 2/1
Direct, A 2/1
Direct, Rn 2/2
Direct, Direct 3/2
Direct, @Ri 2/2
Direct, #data 3/2
@Ri, A 1/1

46
@Ri, Direct 2/2
@Ri, #data 2/1
DPTR, #data 16 3/2
C, bit 2/1
Bit, C 2/2
MOVX A, @DPTR 1/2
@DPTR, A 1/2
A, @Ri 1/2
@Ri, A 1/2

MOVC A, @DPTR 1/2


A, @A+PC 1/2

PUSH Direct 2/2

POP Direct 2/2


XCH A, Rn 1/1
A, direct 2/1
A, @Ri 1/1

XCHD A, @Ri 1/1

 BRANCHING INSTRUCTIONS:

TABLE 2.15: BRANCHING INSTRUCTIONS

MNEMONIC OPEARNDS BYTES/CYCLES


JC Rel 2/2

JNC Rel 2/2

JB Bit, rel 3/2

JNB Bit, rel 3/2

JBC Bit, rel 3/2

JZ Rel 2/2

JNZ Rel 2/2

LJMP Addr16 3/2

47
AJMP Addr11 2/2

SJMP Rel 2/2

JMP @A+DPTR ½

LCALL Addr16 3/2

ACALL Addr11 2/2

RET - ½

RETI - ½

CJNE A, Direct, rel 3/2


A, #Data, rel 3/2
Rn, #data,rel 3/2
@Ri, #data, rel 3/2

DJNZ Rn, rel 2/2


Direct, rel 3/2

NOP - 1/1

2.17.6 PROGRAMMING TOOLS:


The different programming tools are Editor, assembler, compiler, emulator etc.

 EDITOR:
o Editor provides the facility to write the programs and then immediate assemble or
compile the program.
o Gives us the facility to create new text, open existing text and save the written
text.

 ASSEMBLER:

48
o Assembler is software which convert assembly language program in to machine
language program called object code.
o After assembling the code it generates a number of files.

Asm file  Lst file  Obj file  Link file  Hex file

o The program developed by the programmer is stored an ASM file.


o The assembler converts the source file into machine code and produces an object
file and list file.
o The linker links all the object files and produces link file.
o The link file is fed into an OH (object to hex converter) which creates a hex file.
o The hex file is programmed into the ROM.

 COMPILER:
o A compiler is a program that translates a high level language program into
machine level instructions.
o A compiler may use an assembly language as an intermediate step in the
translation or may translate the program directly to machine code.
o After assembling the code it generates a number of files like c file, asm file, lst
file, obj file, rel file, link file, hex file etc. depending on the compiler
o The most popular microcontroller compilers are KEIL, SDCC, READS, PIC,
PL/M, from Intel and many more.

 PROGRAMMER:
o Programmer is a device used to program the hex file generated by assembler/
compiler into ROM of microcontroller.
o Programmer can be:
 ISP Programmer
 GANG Programmer

49
 SIMULATOR:
o Program which provides the facility to step through the code to see exactly what
is happening as program runs.
o Contents of register or variable can be altered to change the way the program
runs. A simulator cannot support real interrupts or devices.

 DEBUGGER:
o Debugger is a tool that is used to help identify and fix problems (bugs) in the
program.
o It supports step by step execution of the code and viewing the contents of code
variables.
o It allows the monitoring of register, memory, SFRs and program statements.

 EMULATOR:
o It is similar to Simulator with some advancement.
o An emulator is a sophisticated that pretends that it is the microprocessor itself,
while at the same time capturing information.
o The emulator can either be a stand alone device with its own display, or it can be
interface to a PC.

50
CHAPTER 3: PROJECT WORK “APS CONTROLLER”

3.1 TITLE
TO CONSTRUCT AN AUTOMATIC POWER SUPPLY CONTROLLER USING 8051
MICROCONTROLLER.

3.2 OBJECTIVE
Control any thing we desire all over the world via mobile/landline phone. Reason for using
mobile phones, To increase the range of control . Only this feature makes it different from
remote control devices.

3.3 DESCRIPTION
The project is designed to make control of electrical and electronics components at home. This
project is designed using ATMEL 8051 microcontroller.
Heart of this project is 8870 IC which converts the DTMF tone in BCD circuit. 8870 is a decoder
IC which converts the DTMF tone in BCD code. On the basis of that BCD code we performed
various actions.

3.4 PRINCIPLE
APS controller works on the principle of DUAL tone multiple frequency. On the basis of this
tone M8870 IC decodes different BCD codes. For example when a call in customer care that
says press 1 to know ABT balance, 2 for validity0 these all operations are based upon DTMF
principle.

51
3.5 WORKING

I min
INDIA
FIGURE 3.1: DTMF OPERATION

Transm
itter
I msendingDTMF ToneWs irelessorw
Bypressingkeypad
I
Condenser
Am
plifier cD
oenn
co
Mic FIGURE 3.2: DTMF OPERATION (DTM
Transmitter
Real tim
eglobal call receiverandco
52
Wirele
3.6 COMPONENTS USED

• IC USED

• 8051 MICROCONTROLLER

• M8870 DECODER IC

• OTHER COMPONENTS

• 40 PIN & 20 PIN BASE

• RESISTANCE(4K,10K,1K)

• CAPACITOR(0.1MICROFARAD,1M VARIABLE,22PF)

• CRYSTAL OSCILLATOR(11.095Mhz)

• LCD,CONNECTING WIRES

3.7 CIRCUIT DIAGRAM

FIGURE 3.3 CONNECTION DIAGRAM

53
3.7.1 LED:
 The symbol of a LED is shown in figure.

A=ANODE
K=CATHODE

FIGURE 3.5: LIGHT EMITTING DIODE

 Identification of LED terminals:


The cathode terminal of LED is short in length compared to Anode lead and there is a slight flat
on the periphery of LEDs.

A K

FUNCTION OF LED:
 LED emit light when an electric current passes through them.
 LED must have a resistor in series to limit the current as per rating of LED. Otherwise it will
burn out almost instantly.

3.7.2 SEVEN-SEGMENT DISPLAY:


It is made of seven plus one Led.
It is used for displaying number.

TYPES OF DISPLAY:
 Common Cathode (CC) configuration:
Common Cathode means cathodes of eight LEDs is common. All Leds will glow on applying
‘1’ logic at their segment pins.

54
 Common Anode (CA) configuration:
Common Anode means Anode of eight LEDs is common. All Leds will glow on applying ‘0’
logic at their segment pins.

FIG 3.4: SEVEN SEGMENT DISPLAY

3.7.3 BUZZER:

Buzzer is made up of piezo electric crystals. It produces oscillation when electric field applied to
its terminals. As output oscillations are having frequency in range of 20 Hz to 20 KHz, so it can
be heard easily. Thus, sound/ alarm gets generated.

-
-

55
3.7.4 POWER SUPPLY

The power supply supplies the required energy for both the microcontroller and the associated
circuits. It is the most essential part of the circuit because to run its constituent IC’s circuit has to
be provided with power. These IC’s can run on DC power. Hence the required D.C supply has to
be generated. The main parts of a power supply unit and their function are as follows

D 1 L M 7 8 0 5
1 N 4 0 0 7 + 5 V
1 2
V I N V O U T

GND
J 1 D 2 1 0 0 0 u f
3
2 g n d C 1

3
1 V
D 3

D 4

FIG 3.5: POWER SUPPLY


3.7.5 ULN 2004
It is a HIGH VOLTAGE – HIGH CURRENT DARLINGTON ARRAYS. It is used to drive
relays which require high current. in this if we give high signal on input side then we will get low
signal on output side. Its features are:
• Output Current to 500 mA
• Output Voltage to 95 V
Featuring continuous load current ratings to 500 mA for each of the drivers, the ULN2804 high
voltage, high-current Darlington arrays are ideally suited for interfacing between low-level logic
circuitry and multiple peripheral power loads. Typical power loads totaling over 260 W can be
controlled at an appropriate duty cycle depending on ambient temperature and number of drivers
turned on simultaneously. Typical loads include relays, solenoids, stepping motors, magnetic
print hammers, and heaters. These devices will handle numerous interface needs particularly
those beyond the capabilities of standard logic buffers. These Darlington arrays are furnished in

56
18-pin dual in-line plastic packages. All devices are pinned with outputs opposite inputs to
facilitate ease of circuit board layout.
3.7.6 RELAY
A relay is an electrically operated switch. Due to this it is also called as
ELECTROMECHANICAL SWITCH made up of electromagnet and having set of contacts
inside. A small current flowing through a coil in relay creates a magnetic field that pulls one
switch contact against or away from another.
Relays allow one circuit to switch to a second circuit which can be completely separated from
the first. In relay there are three main parts:
1. coil
2. spring
3. set of electrical contacts made of metal

 WORKING OF RELAY
Current flowing through the coil of the relay creates a magnetic field which attracts a lever and
changes the switch contacts from NC to NO positions. The coil current can be on or off so relays
have two switch positions.
 RELAY DRIVER
The coil of a relay needs relatively large current for excitation. So, we require a current driver/
amplifier for driving relay. The need can be fulfilled by transistors and for more amplification we
can also use darlington pair. The most common ic no. of darlington pair is ULN 2004/ULN
2804.

 PROTECTION OF RELAY
There is generation of residue /stray voltage in reverse polatity across the coil while switching
on/off to the coil current. This voltage may lead to serious effect on working operation of relay.
For prevention , a protection diode (IN4007/IN4148) across the relay coil must be connected.

57
3.8 CODING

ORG 0000H
LCDPORT EQU P0
RS BIT P3.0
EN BIT P3.1
relay1 bit p3.0
relay2 bit p3.1
relay3 bit p3.2
relay4 bit p3.3

BUZZER BIT P1.0


dtmf equ p2

FLAG1 BIT 20H.0


FLAG2 BIT 20H.1
FLAG3 BIT 20H.2
FLAG4 BIT 20H.3
SJMP POWER_ON
ORG 0003H ;EXT INT 0
RETI
ORG 000BH ;TIMER 0
RETI
ORG 0013H ;EXT INT 1
RETI
ORG 001BH ; TIMER 1
RETI
ORG 0023H ;SERIAL INT
RETI
ORG 0030H

POWER_ON:
MOV SP,#70H
MOV IE,#00H
MOV IP,#00H
MOV P0,#0FFH
MOV P1,#0FFH
MOV P2,#0FFH

58
MOV P3,#0FFH

;***************************RAM CLR******************

setb p1.0
RAM_CLR:
MOV R0,#7FH
CLEAR:
MOV @R0,#00H
DJNZ R0,CLEAR
;***************************MAIN*******************

MAIN1:

CLR RELAY2
CLR RELAY3
CLR RELAY1
CLR RELAY4
jnb p2.3,$
MOV R0,#00
mov r1,#0
mov r2,#0
mov r3,#0
KEYSENSE:
;setb p2.0
jnb p2.3,$
MOV A,P2
ANL A,#11110000B
CJNE A,#00010000B,NEXT1
SJMP ISHANT1
NEXT1:
MOV A,P2
ANL A,#11110000B
CJNE A,#00100000B,NEXT2
aJMP ISHANT2
NEXT2:
MOV A,P2
ANL A,#11110000B
CJNE A,#00110000B,NEXT3
aJMP ISHANT3
NEXT3:
MOV A,P2
ANL A,#11110000B
CJNE A,#01000000B,next4
aJMP ISHANT4
NEXT4:

59
MOV A,P2
ANL A,#11110000B
CJNE A,#01010000B,next5
clr p2.0
mov p0,#0d0h

acall delay
sjmp keysense
next5:
MOV A,P2
ANL A,#11110000B
CJNE A,#01100000B,next6
clr p2.0
mov p0,#050h

acall delay
sjmp keysense
next6:
MOV A,P2
ANL A,#11110000B
CJNE A,#01110000B,next7
clr p2.0
mov p0,#097h

acall delay
sjmp keysense
next7:
MOV A,P2
ANL A,#11110000B
CJNE A,#10000000B,keysense
clr p2.0
mov p0,#10h

acall delay
sjmp keysense

ISHANT1:
clr p2.0
mov p0,#0b7h
acall delay
inc r0
cjne r0,#2,device
clr buzzer
keys:
MOV A,P2
ANL A,#11110000B

60
CJNE A,#10010000B,keys
clr p2.0
mov p0,#90h
acall delay

jnb p2.3,$
ajmp keysense
device:
cpl relay1
acall delay
cjne r0,#3,keysense1
setb buzzer

mov r0,#0
ajmp keysense

ISHANT2:
clr p2.0
mov p0,#019h

acall delay

inc r1
cjne r1,#2,device1
clr buzzer
keys1:
MOV A,P2
ANL A,#11110000B
CJNE A,#10010000B,keys1
clr p2.0
mov p0,#90h
;
acall delay
jnb p2.3,$
ajmp keysense
device1:
cpl relay2
acall delay
cjne r1,#3,keysense1
setb buzzer

mov r1,#0
ajmp keysense
ISHANT3:

clr p2.0

61
mov p0,#091h

acall delay

inc r2
cjne r2,#2,device3
clr buzzer

keys3:
MOV A,P2
ANL A,#11110000B
CJNE A,#10010000B,keys3
clr p2.0
mov p0,#90h
acall delay
jnb p2.3,$
ajmp keysense
keysense1:
ljmp keysense
device3:
cpl relay3
acall delay
cjne r2,#3,keysense1
setb buzzer

mov r2,#0
ajmp keysense
ISHANT4:
clr p2.0
mov p0,#0b4h

acall delay

inc r3
cjne r3,#2,device4
clr buzzer
keys4:
MOV A,P2
ANL A,#11110000B
CJNE A,#10010000B,keys4

clr p2.0
mov p0,#90h
acall delay
jnb p2.3,$
ajmp keysense

62
device4:
cpl relay4
acall delay
cjne r3,#3,keysense1
setb buzzer

mov r3,#0
ajmp keysense
ISHANT5:
DELAY:
mov r7,#2
LP1:
MOV 37h,#255D
LP2:
MOV R5,#255D
LP3:
NOP
DJNZ R5,LP3
DJNZ 37h,LP2
djnz r7,LP1
RET

3.9 CHARACTERISTICS
• Globally applicable

• Work in a time constraint

• Can be used by deaf and dumb

• Not much expensive

• Can be applied with auto answering mode at receiver end

• Can be used in noisy environment

3.10 APPLICATION
• Telecom (Detecting number pressed by user at customer care)

• Industries (fire alarm, machines)

• Home Appliances (can be connected to any electrical and electronic device)

63
3.11 BENEFITS
The system is not a time consuming system. In today’s world, people are very busy; they
don’t want to waste their time.

CHAPTER 4:- CONCLUSION

I would like to conclude that the training in the E.M. Tech Foundation gave a though knowledge
about micro controllers & a great chance to learn and understand about embedded systems. This
training increased my knowledge in how micro controllers are useful as well as used in the real
world. I am sure that this training would help me a lot in future.

64

You might also like