embedded system ucontrollr
Post on 30-May-2018
216 Views
Preview:
TRANSCRIPT
-
8/9/2019 Embedded System Ucontrollr
1/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 workshopsin 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
-
8/9/2019 Embedded System Ucontrollr
2/64
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 Foundationigniting minds..
2
-
8/9/2019 Embedded System Ucontrollr
3/64
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 isto integrate more & more function on the CPU chip & let the designer decide which feature he/she
wants to us.
CHAPTER 2
3
-
8/9/2019 Embedded System Ucontrollr
4/64
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
2.2FEATURES OF AN EMBEDDED SYSTEM
4
-
8/9/2019 Embedded System Ucontrollr
5/64
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
the embedded computer. Traditionally, such systems have employed multiply-redundant computers
or distributed consensus protocols in order to ensure continued operation after an equipment
5
-
8/9/2019 Embedded System Ucontrollr
6/64
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 physicalabuse. 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 levelwithout undue management scrutiny).
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.
6
-
8/9/2019 Embedded System Ucontrollr
7/64
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
2.3.7 DEFENSE SYSTEM
Radar system, radio system, missile guidance system
7
-
8/9/2019 Embedded System Ucontrollr
8/64
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.
FIG 2.2:- MICROCONTROLLER AS A COMPUTER CHIP
2.5 WHAT IS MICROPROCESSOR?
8
RAM ROM
I/OPort
TimerSerialCOMPort
CPU
A single chip
-
8/9/2019 Embedded System Ucontrollr
9/64
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.
FIG 2.3:- BLOCK DIAGRAM OF A MICROPROCESSOR
MEMORY:
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 :
9
CPUGeneral-PurposeMicro-
processor
RAM ROM I/O
Port
TimerSerialCOM
Port
Data Bus
-
8/9/2019 Embedded System Ucontrollr
10/64
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 outthe 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:-
Microcontroller and microprocessor stems from the same basic idea yet there exist some
differences. Table1.1 clearly differentiates between microprocessor and microcontroller.
10
-
8/9/2019 Embedded System Ucontrollr
11/64
TABLE 2.1:- MICROPROCESSOR V/S MICROCONTROLLER
S.NO. Feature Microprocessor Microcontroller
1. Memory No on chip Ram/Rom On chip Ram/Rom2. Application General purpose Specific purpose3. Timer No on chip timer Two on chip timer 4. Opcodes Many opcodes for moving
data from external memoryto the C.P.U.
Microcontrollers mayhave one or twoopcodes.
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
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
11
-
8/9/2019 Embedded System Ucontrollr
12/64
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 Features128 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.
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-leadLQFP package:
RAM ROM Counters I/O Pins Other Features4k 8k 2 24 A/D,UART
12
-
8/9/2019 Embedded System Ucontrollr
13/64
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.
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.
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.
13
Salesinmillion
-
8/9/2019 Embedded System Ucontrollr
14/64
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
Interruptsources
6 6 7 7
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.
14
-
8/9/2019 Embedded System Ucontrollr
15/64
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
FIG 2.5: BLOCK DIAGRAM OF 8051
15
-
8/9/2019 Embedded System Ucontrollr
16/64
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.
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
16
-
8/9/2019 Embedded System Ucontrollr
17/64
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
-
8/9/2019 Embedded System Ucontrollr
18/64
FIG 2.6:- PIN DIAGRAM OF 80512.10.1 PIN DESCRIPTION:
18
-
8/9/2019 Embedded System Ucontrollr
19/64
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
-
8/9/2019 Embedded System Ucontrollr
20/64
Input/output pins.
Contains internal pull-ups.
Alternate functions to provide signals such as interrupts.
PINS : DESCRIPTIONRXD (P3.0) : Serial input portTXD (P3.1) : Serial output portINT0 (P3.2) : External interruptINT1 (P3.3) : External interruptT0 (P3.4) : Timer 0 external inputT1 (P3.5) : Timer 1 external inputWR (P3.6) : External data memory writes strobeRD (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
-
8/9/2019 Embedded System Ucontrollr
21/64
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 hACC 0000 hB 0000 hPSW 0000 hSP 0007 hDPTR 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. Mostoften 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
-
8/9/2019 Embedded System Ucontrollr
22/64
-
8/9/2019 Embedded System Ucontrollr
23/64
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 iscurrently 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
-
8/9/2019 Embedded System Ucontrollr
24/64
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.
FIG 2.10:- INTERNAL ROM
24
SP=0A Address 0A SP=0A
SP=09
SP=08
SP=07
PUSH POP
Address 09
Address 08
Address 07
SP=09
SP=08
SP=07
Internal RAMStoring data on the Stack (Increment then store)
Getting data from the Stack (Get then decrement)
Store Data
Store Data
Store Data
Get Data
Get Data
Get Data
0000
0FFF
B te
INTERNALROM
-
8/9/2019 Embedded System Ucontrollr
25/64
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 instructionis given by:
T (instruction) = (C*12)/crystal frequency
FIG 2.11:-ONE COMPLETE MACHINE CYCLE
2.11.5 SPECIAL FUNCTION REGISTER:
The 8051 operations that dont use the 128-byte internal RAM addresses from 00h to 7Fh aredone 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
State 1 State 2 State 3 State 4 State 5 State 6
One Machine Cycle
P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
-
8/9/2019 Embedded System Ucontrollr
26/64
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
-
8/9/2019 Embedded System Ucontrollr
27/64
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
-
8/9/2019 Embedded System Ucontrollr
28/64
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 0CY AC F0 RS1 RS0 OV -------- P
BIT SYMBOL
FUNCTION
7 CY Carry flag; used in arithmetic, jump, rotate and Booleaninstruction
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 RS00 0 Select register bank 00 1 Select register bank 11 0 Select register bank 21 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 AND TIMERS
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
Bit addressable as PSW.0 to PSW.1
-
8/9/2019 Embedded System Ucontrollr
29/64
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). Theseregisters 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.
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.
29
TH0 TL0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
FIG 2.11: TIMER 0 REGISTER
TH1 TL1
FIG 2.12: TIMER 1 REGISTER
-
8/9/2019 Embedded System Ucontrollr
30/64
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 FUNCTION7 TF1 Timer 1 Overflow flag. Set when timer rolls from all 1s to 0.
Cleared when processor vectors to execute interrupt serviceroutine 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 resettimer.
5 TF0 Timer 0 Overflow flag. Set when timer rolls from all 1s to 0.Cleared when processor vectors to execute interrupt serviceroutine 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 resettimer
3 IE1 External interrupt 1 Edge flag. Set to 1 when a high-to-lowedge 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 afalling edge signal. Set to 0 by program to enable a low-levelsignal on external interrupt 1 to generate an interrupt.
1 IE0 External interrupt 0 Edge flag. Set to 1 when a high-to-lowedge 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
-
8/9/2019 Embedded System Ucontrollr
31/64
-
8/9/2019 Embedded System Ucontrollr
32/64
TABLE 2.7: TIMER MODES
M1 M0 MODE OPERATING MODE
0 0 0 13-bit timer mode8-bit timer/counter THx with TLxas 5-bit prescalar
0 1 1 16-bit timer mode16-bit timer/counter THx and TLxare cascaded; there is no prescalar
1 0 2 8-bit auto reload8-bit auto reload timer/counter;THx holds a value which is to bereloaded into TLx each time itoverflows.
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.
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 thetimers 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
TLX 5 Bits THX 8 Bits TFX InterruptFIG 2.13:- TIMER MODE 0 13-BIT TIMER/COUNTER
PULSEINPUT
-
8/9/2019 Embedded System Ucontrollr
33/64
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.
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 timers
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
THH TL
TFH
TF goes highWhen FFFF
OverflowFlag0
/12d
TR
XTALOscillator
C/T=0
-
8/9/2019 Embedded System Ucontrollr
34/64
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 dont 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 doesnt depend on an interrupt (or any other use of the TF1 flag) for
proper operation.
34
RELOAD
TFGOESHIGH
WHENFF 0
XTALOscillator
/12d
TR C/T=0
TL
TH
TF
-
8/9/2019 Embedded System Ucontrollr
35/64
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 8051s 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 timers 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
-
8/9/2019 Embedded System Ucontrollr
36/64
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
SENDER RECEIVER
SERIAL TRANSFER
PARALLEL TRANSFER
SENDER
RECEIVER
D7
D0
-
8/9/2019 Embedded System Ucontrollr
37/64
manufacturers for serial data communication. These chips are commonly referred to as UART
(Universal asynchronous receiver-transmitter). The 8051 has a built-in UART.
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 isreferred 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):
37
SIMPLEX TRANSMITTER RECEIVER
HALF DUPLEX TRANSMITTER RECEIVER
RECEIVER TRANSMITTER
FULL DUPLEX TRANSMITTER RECEIVER
RECEIVER TRANSMITTER
FIG 2.17:- SIMPLEX, HALF, AND FULL-DUPLEX
SM0 SM1 SM2 REN TB8 RB8 TI RI
-
8/9/2019 Embedded System Ucontrollr
38/64
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 programto select mode.
6 SM1 Serial port mode bit0. Set / cleared by programto select mode.
5 SM2 Multiprocessor communication bit. Set/ clearedby 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 todouble baurd rate using timer1.
6-4 ____ Not implemented
3 GF1 General purpose user flag bit1. Set/cleared byprogram.
2 GF0 General purpose user flag bit0. Set/cleared byprogram.
1 PD Power down bit.
38
-
8/9/2019 Embedded System Ucontrollr
39/64
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 asignal or request to microcontroller then it
performs the task accordingly.
The microcontroller continuously monitorsthe status of pin/device if the condition ismet, then it perform the task assigned.
If more than one interrupts generate requestto microcontroller then microcontroller executes them sequentially as per definedPRIORITY.
No priority level assignment since it checksall devices in round-robin fashion.
The program which is associated with theinterrupt is called interrupt service routine.
Not such condition.
FIG 2.18: TYPES OF INTERRUPTS
39
INTERRUPTS
MASKABLE NON-MASKABLE
External interruptsTimer interruptsSerial interrupts
RESET
-
8/9/2019 Embedded System Ucontrollr
40/64
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
EA IE.7 Disables all interrupts if EA=0. If EA=1, interrupt source is individually
40
-
8/9/2019 Embedded System Ucontrollr
41/64
-
8/9/2019 Embedded System Ucontrollr
42/64
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
ADDRLC
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
-
8/9/2019 Embedded System Ucontrollr
43/64
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
-
8/9/2019 Embedded System Ucontrollr
44/64
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, AMOV 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
-
8/9/2019 Embedded System Ucontrollr
45/64
FIG 2.20:- TYPES OF INSTRUCTION
ARITHMATIC INSTRUCTIONS:
TABLE 2.12: ARITHMATIC INSTRUCTION
MNEMONICS
OPERANDSBYTES/CYCLE
S
ADD A,Rn 1/1ADDC A,Direct 2/1SUBB A,@Ri
A,#data1/12/1
INC A 1/1DEC RN
DIRECT@ Ri
1/12/11/
INC DPTR 1/2MUL AB 1/4DIV AB 1/4DA A 1/1
45
-
8/9/2019 Embedded System Ucontrollr
46/64
LOGICAL INSTRUCTIONS:
TABLE 2.13 LOGICAL INSTRUCTIONS
MNEMONIC OPERANDS BYTES/CYCLE
ANL A,Rn 1/1
ORL A,direct 2/1
XRL A,@RiA,#dataDirect,A
Direct,#data
C,bit
1/12/12/13/2
2/2
CLR A 1/1
DATA TRANSFER INSTRUCTIONS:
TABLE 2.14: DATA TRANSFER INSTRUCTIONS3
MNEMONIC OPERANDS BYTES/CYCLE
MOV A, RnA, DirectA, RiA, #DataRn, A
Rn, DirectRn, #DataDirect, ADirect, RnDirect, DirectDirect, @RiDirect, #data@Ri, A
1/12/11/12/11/1
2/22/12/12/23/22/23/21/1
46
-
8/9/2019 Embedded System Ucontrollr
47/64
@Ri, Direct@Ri, #dataDPTR, #data 16C, bitBit, C
2/22/13/22/12/2
MOVX A, @DPTR @DPTR, AA, @Ri@Ri, A
1/21/21/21/2
MOVC A, @DPTR A, @A+PC
1/21/2
PUSH Direct 2/2
POP Direct 2/2
XCH A, RnA, directA, @Ri
1/12/11/1
XCHD A, @Ri 1/1
BRANCHING INSTRUCTIONS:
TABLE 2.15: BRANCHING INSTRUCTIONS
MNEMONIC OPEARNDS BYTES/CYCLESJC 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
-
8/9/2019 Embedded System Ucontrollr
48/64
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
A, #Data, relRn, #data,rel@Ri, #data, rel
3/2
3/23/23/2
DJNZ Rn, relDirect, rel
2/23/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:
o Assembler is software which convert assembly language program in to machine
language program called object code .
48
-
8/9/2019 Embedded System Ucontrollr
49/64
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
SIMULATOR:
49
-
8/9/2019 Embedded System Ucontrollr
50/64
-
8/9/2019 Embedded System Ucontrollr
51/64
-
8/9/2019 Embedded System Ucontrollr
52/64
Transmitter Receiver
CondenserMic Amplifier
Decoder(DTMF) Microcontroller
Outputdevices
I minINDIA
I minAUSTRALIA
Wireless or wired
Real timeglobal call receiver andcontroller
FIGURE 3.1: DTMF OPERATION
Transmitter Receiver
CondenserMic Amplifier
Decoder(DTMF) Microcontroller
I amconnected
msendingDTMF TonesBy pressingkeypad
I mreceivingDTMF tones andsendingtocondenser mic
I mreceivingDTMF tonesand amplifyingit.
I mdecodingcircuit forDTMF toBCD
O/PDevices
Wireless or wired
FIGURE 3.2: DTMF OPERATION
52
-
8/9/2019 Embedded System Ucontrollr
53/64
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
-
8/9/2019 Embedded System Ucontrollr
54/64
3.7.1 LED:
The symbol of a LED is shown in figure.
A=ANODEK=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 flaton the periphery of LEDs.
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
A
K
K A
-
8/9/2019 Embedded System Ucontrollr
55/64
-
8/9/2019 Embedded System Ucontrollr
56/64
3.7.4 POWER SUPPLY
The power supply supplies the required energy for both the microcontroller and the associatedcircuits. It is the most essential part of the circuit because to run its constituent ICs circuit has to
be provided with power. These ICs 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
FIG 3.5: POWER SUPPLY3.7.5 ULN 2004
It is a HIGH VOLTAGE HIGH CURRENT DARLINGTON ARRAYS. It is used to drive relayswhich 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 becontrolled 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 18-pin
56
D 2
C 1
1 0 0 0 u f
1 N 4 0 0 7 + 5
V
L M 7 8 0 5
1 2
3
V I N V O U T
G
N
D
J 1
12
3
D 3
g n d
D 4
D 1
-
8/9/2019 Embedded System Ucontrollr
57/64
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
-
8/9/2019 Embedded System Ucontrollr
58/64
3.8 CODING
ORG 0000HLCDPORT EQU P0RS BIT P3.0EN BIT P3.1relay1 bit p3.0relay2 bit p3.1relay3 bit p3.2relay4 bit p3.3
BUZZER BIT P1.0dtmf equ p2
FLAG1 BIT 20H.0FLAG2 BIT 20H.1FLAG3 BIT 20H.2FLAG4 BIT 20H.3SJMP POWER_ON
ORG 0003H ;EXT INT 0RETIORG 000BH ;TIMER 0RETIORG 0013H ;EXT INT 1RETIORG 001BH ; TIMER 1RETIORG 0023H ;SERIAL INTRETI
ORG 0030H
POWER_ON:MOV SP,#70HMOV IE,#00HMOV IP,#00HMOV P0,#0FFHMOV P1,#0FFHMOV P2,#0FFH
58
-
8/9/2019 Embedded System Ucontrollr
59/64
MOV P3,#0FFH
;***************************RAM CLR******************
setb p1.0
RAM_CLR:MOV R0,#7FHCLEAR:
MOV @R0,#00HDJNZ R0,CLEAR
;***************************MAIN*******************
MAIN1:
CLR RELAY2CLR RELAY3
CLR RELAY1CLR RELAY4jnb p2.3,$
MOV R0,#00mov r1,#0
mov r2,#0mov r3,#0
KEYSENSE:;setb p2.0
jnb p2.3,$MOV A,P2ANL A,#11110000BCJNE A,#00010000B,NEXT1SJMP ISHANT1
NEXT1:MOV A,P2ANL A,#11110000BCJNE A,#00100000B,NEXT2aJMP ISHANT2
NEXT2:MOV A,P2ANL A,#11110000BCJNE A,#00110000B,NEXT3aJMP ISHANT3
NEXT3:MOV A,P2
ANL A,#11110000BCJNE A,#01000000B,next4aJMP ISHANT4
NEXT4:
59
-
8/9/2019 Embedded System Ucontrollr
60/64
MOV A,P2ANL A,#11110000BCJNE A,#01010000B,next5clr p2.0
mov p0,#0d0h
acall delaysjmp keysense
next5:MOV A,P2
ANL A,#11110000BCJNE A,#01100000B,next6clr p2.0mov p0,#050h
acall delay
sjmp keysensenext6:MOV A,P2
ANL A,#11110000BCJNE A,#01110000B,next7clr p2.0
mov p0,#097h
acall delaysjmp keysense
next7:MOV A,P2
ANL A,#11110000BCJNE A,#10000000B,keysenseclr p2.0
mov p0,#10h
acall delaysjmp keysense
ISHANT1:clr p2.0mov p0,#0b7hacall delayinc r0cjne r0,#2,deviceclr buzzer
keys:MOV A,P2ANL A,#11110000B
60
-
8/9/2019 Embedded System Ucontrollr
61/64
-
8/9/2019 Embedded System Ucontrollr
62/64
-
8/9/2019 Embedded System Ucontrollr
63/64
device4:cpl relay4acall delay
cjne r3,#3,keysense1setb buzzer
mov r3,#0ajmp keysense
ISHANT5:DELAY:
mov r7,#2LP1:
MOV 37h,#255DLP2:
MOV R5,#255DLP3:
NOPDJNZ R5,LP3DJNZ 37h,LP2
djnz r7,LP1RET
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
-
8/9/2019 Embedded System Ucontrollr
64/64
3.11 BENEFITS The system is not a time consuming system. In todays world, people are very busy; they dont
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.
top related