8051 MC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 115

Chapter 2

Core of embedded systems: microprocessors and


microcontrollers, RISC and CISC controllers, Big endian and Little
endian processors, Application specific ICs, Programmable logic
devices, COTS, sensors and actuators, communication interface,
embedded firmware, other system components
Core of the Embedded Systems
The core of the embedded system falls into any one of the following categories.
General Purpose and Domain Specific Processors
o Microprocessors
o Microcontrollers
o Digital Signal Processors
Programmable Logic Devices (PLDs)
Application Specific Integrated Circuits (ASICs)
Commercial off the shelf Components (COTS)
General Purpose and
Domain Specific Processors
Almost 80% of the embedded systems are processor/ controller based.
The processor may be microprocessor or a microcontroller or digital signal processor, depending on the domain
and application
Digital Signal Processors (DSPs)
Powerful special purpose 8/16/32 bit microprocessors designed specifically to meet the computational demands
and power constraints of today's embedded audio, video, and communications applications
Digital Signal Processors are 2 to 3 times faster than the general purpose microprocessors in signal processing
applications
DSPs implement algorithms in hardware which speeds up the execution whereas general purpose processors
implement the algorithm in firmware and the speed of execution depends primarily on the clock for the processors
DSP can be viewed as a microchip designed for performing high speed computational operations for “addition”,
“subtraction”, “multiplication” and “division”.
Digital Signal Processors (DSPs)
A typical Digital Signal Processor incorporates the following key units:
Program Memory
Data Memory
Computational Engine
I/O Unit
Audio video signal processing, telecommunication and multimedia applications are typical examples where DSP
is employed
Endianness
Endianness specifies the order in which the data is stored in the memory by processor operations in a multi byte
system (Processors whose word size is greater than one byte). Suppose the word length is two byte then data can
be stored in memory in two different ways
 Higher order of data byte at the higher memory and lower order of data byte at location just below the higher
memory
 Lower order of data byte at the higher memory and higher order of data byte at location just below the higher
memory
Big-endian V/s Little-endian processors

Little-endian means the lower-order byte of the data is stored


in memory at the lowest address, and the higher-order byte at
the highest address. (The little end comes first)

Big-endian means the higher-order byte of the data is stored


in memory at the lowest address, and the lower-order byte at
the highest address. (The big end comes first.)
Check out the youtube link that explains the concept

https://youtu.be/T1C9Kj_78ek

Check the following page to know more on this


https://www.freecodecamp.org/news/what-is-endianness-big-endian-vs-little-
endian/
Application Specific Integrated Circuit
(ASIC)
A microchip designed to perform a specific or unique application. It is used as
replacement to conventional general purpose logic chips.
ASIC integrates several functions into a single chip and thereby reduces the system
development cost
Most of the ASICs are proprietary products. As a single chip, ASIC consumes very
small area in the total system and thereby helps in the design of smaller systems with
high capabilities/functionalities.
ASICs can be pre-fabricated for a special application or it can be custom fabricated by
using the components from a re-usable “building block” library of components for a
particular customer application
Fabrication of ASICs requires a non-refundable initial investment (Non Recurring
Engineering (NRE) charges) for the process technology and configuration expenses
If the Non-Recurring Engineering Charges (NRE) is born by a third party and the
Application Specific Integrated Circuit (ASIC) is made openly available in the market,
the ASIC is referred as Application Specific Standard Product (ASSP)
The ASSP is marketed to multiple customers just as a general-purpose product , but to
a smaller number of customers since it is for a specific application.
Some ASICs are proprietary products , the developers are not interested in revealing
the internal details.
Programmable Logic Devices (PLDs)
Logic devices provide specific functions, including device-to-device interfacing, data
communication, signal processing, data display, timing and control operations, and
almost every other function a system must perform.
Logic devices can be classified into two broad categories - Fixed and Programmable.
The circuits in a fixed logic device are permanent, they perform one function or set of
functions - once manufactured, they cannot be changed
Programmable logic devices (PLDs) offer customers a wide range of logic capacity,
features, speed, and voltage characteristics - and these devices can be re-configured
to perform any number of functions at any time
Designers can use inexpensive software tools to
quickly develop, simulate, and test their logic
designs in PLD based design. The design can be
quickly programmed into a device, and immediately
tested in a live circuit
PLDs are based on re-writable memory technology
and the device is reprogrammed to change the
design
Two major types of programmable logic devices
Field Programmable Gate Arrays (FPGAs)
Complex Programmable Logic Devices (CPLDs)
Field Programmable Gate Arrays (FPGAs)
FPGA is an IC designed to be configured by a designer after manufacturing.
FPGAs offer the highest amount of logic density, the most features, and the highest
performance.
Logic gate is Medium to high density ranging from 1K to 500K system gates
These advanced FPGA devices also offer features such as built-in hardwired
processors (such as the IBM Power PC), substantial amounts of memory, clock
management systems, and support for many of the latest, very fast device-to-device
signaling technologies
FPGAs are used in a wide variety of applications ranging from data processing and
storage, to instrumentation, telecommunications, and digital signal processing
Complex Programmable Logic Devices
(CPLDs)
A complex programmable logic device (CPLD) is a programmable logic device with
complexity between that of PALs and FPGAs, and architectural features of both.
CPLDs, by contrast, offer much smaller amounts of logic - up to about 10,000 gates.
CPLDs offer very predictable timing characteristics and are therefore ideal for critical
control applications.
CPLDs such as the Xilinx CoolRunner series also require extremely low amounts of
power and are very inexpensive, making them ideal for cost-sensitive, battery-
operated, portable applications such as mobile phones and digital handheld assistants
ADVANTAGES OF PLDs
PLDs offer customer much more flexibility during design cycle
PLDSs do not require long lead times for prototype or production-the PLDs are
already on a distributor’s self and ready for shipment
PLDs do not require customers to pay for large NRE costs and purchase expensive
mask sets
PLDs allow customers to order just the number of parts required when they need
them. allowing them to control inventory.
PLDs are reprogrammable even after a piece of equipment is shipped to a customer.
The manufacturers able to add new features or upgrade the PLD based products that
are in the field by uploading new programming file
Commercial off the Shelf Component
(COTS):
A Commercial off-the-shelf (COTS) product is one which is used “as-is”
COTS products are designed in such a way to provide easy integration and interoperability with
existing system components
Commercial off the Shelf Component
(COTS):
Typical examples for the COTS hardware unit are Remote Controlled Toy Car control unit including the
RF Circuitry part, High performance, high frequency microwave electronics (2 to 200 GHz), High
bandwidth analog-to-digital converters, Devices and components for operation at very high temperatures,
Electro-optic IR imaging arrays, UV/IR Detectors etc
A COTS component in turn contains a General Purpose Processor (GPP) or Application
Specific Instruction Set Processor (ASIP) or Application Specific Integrated Chip
(ASIC)/Application Specific Standard Product (ASSP) or Programmable Logic Device
(PLD)
The major advantage of using COTS is The major problem faced by the end-
that they are readily available in the user is that there are no operational
market, cheap and a developer can cut and manufacturing standards
down his/her development time to a
great extend. The major drawback of using COTs
component in embedded design is that
There is no need to design the module the manufacturer may withdraw the
yourself and write the firmware product or discontinue the production
of the COTs at any time if rapid change
Everything will be readily supplied by in technology
the COTs manufacturer
This problem adversely affect a
commercial manufacturer of the
embedded system which makes use of
the specific COTs
Sensors & Actuators
Embedded system is in constant interaction with the real world
Controlling/monitoring functions executed by the embedded system is achieved in
accordance with the changes happening to the Real World.
The changes in the system environment or variables are detected by the sensors
connected to the input port of the embedded system.
If the embedded system is designed for any controlling purpose, the system will
produce some changes in controlling variable to bring the controlled variable to the
desired value.
It is achieved through an actuator connected to the out port of the embedded
system.
Sensor
A transducer device which converts energy from one form to another for any
measurement or control purpose. Sensors acts as input device
Eg. Hall Effect Sensor which measures the distance between the cushion and magnet
in the Smart Running shoes from adidas
Example: IR, Humidity, PIR(passive infrared),
Ultrasonic, Piezoelectric, Smoke sensors
Actuator
A form of transducer device
(mechanical or electrical) which
converts signals to corresponding
physical action (motion). Actuator
acts as an output device
Eg. Micro motor actuator which
adjusts the position of the
cushioning element in the Smart
Running shoes from adidas
Silicon
Techno
Labs
Digital
Analog
Arduino
Starter
Kit
8051 Microcontroller
Microcontrollers and Embedded
processors
Factors to be considered in selecting a
controller
• Feature set
• Speed of operation
• Code memory space
• Data memory Space
• Development support
• Availability
• Power consumption
• Cost
Why 8051
• Versatile
• Powerful Boolean processor
• Supports bit manipulation instructions for real time industrial control
applications
• Supports 6 interrupts
• 2 16-bit timers/counters
• 32 I/O lines
• Programmable full duplex serial interface
Overview of 8051 family
• Introduced by Intel Corp in 1981
• 8051 was the original member of the family
• Main features of 8051 is
Feature Quantity
ROM 4K bytes
RAM 128 bytes
Timer 2
I/O pins 32
Serial port 1
Interrupt sources 6
• Popular and code compatible
• 8051 become widely popular after intel allowed other manufactures to make
and market any version of 8051, with a condition that they should remain
code compatible with 8051
• Hence different version available
• All different versions are compatible with original 8051
• So the code written for one microcontroller, will run on any other version
regardless of the manufacturer.
• There are two other members in 8051 family
• 8052 ad 8031
Comparison of 8051 family members
Features 8051 8052 8031
ROM (on-chip program space in bytes) 4K 8K 0K
RAM (bytes) 128 256 128
Timers 2 3 2
I/O pins 32 32 32
Serial port 1 1 1
Interrupt sources 6 8 6
• 8051 is a subset of 8052, therefore, all programs written for 8051 will
run on 8052, but visa versa is not true.
• 8031 is often called ROM-less 8051 (0 bytes on-chip ROM)
• Hence it uses external ROM which contains the program that 8031
will fetch and execute
• This external ROM can be as large as 64 bytes
• The process of adding external ROM to 8031,looses two ports (16
pins). This leave the user with 2 ports for I/O operations, but one can
add external I/O.
8051 Microcontroller Hardware
Block Diagram of 8051 Microcontroller
Central Processor Unit (CPU) & Oscillator
• CPU is the brain of any processing device of the microcontroller. It
monitors and controls all operations that are performed on the
Microcontroller units. The user has no control over the work of the
CPU directly. It reads program written in ROM memory, executes
them, and do the expected task of that application.
• Microcontroller is a device; that requires clock pulses for its
operation. 8051 has an on-chip oscillator that works as a clock source
for Central Processing Unit. The output pulses of oscillator are stable.
Therefore, it enables synchronized work of all parts of the 8051
Microcontroller.
Interrupts
• Interrupt is a subroutine call that interrupts of the microcontrollers
main operations or work and causes it to execute any other program,
which is more important at the time of operation. The feature of
Interrupt is very useful as it helps in case of emergency operations. An
Interrupts gives a mechanism to put on hold the ongoing operations,
execute a subroutine and then again resumes to another type of
operations. 8051 can be configured in such a way that it temporarily
terminates or pause the main program at the occurrence of
interrupts. When a subroutine is completed, then the execution of
main program starts.
• Generally five interrupt sources are there in 8051 Microcontroller.
There are 5 vectored interrupts • INTO • TFO • INT1 • TF1 • R1/T1
Memory
• Microcontroller requires a program, which is a collection of instructions.
This program tells microcontroller to do specific tasks. These programs
require a memory on which these can be saved and read by
Microcontroller to perform specific operations of a particular task.
• The memory which is used to store the program of the microcontroller is
known as code memory or Program memory of applications. It is known, as
ROM memory
• Microcontroller also requires a memory to store data or operands
temporarily for the micro controller. The data memory of the 8051 is used
to store data temporarily for operation is known RAM memory.
• 8051 microcontrollers has 4K of code memory or program memory that
has 4KB ROM and 128 bytes of data memory of RAM.
Bus
• Bus is a collection of wires, which work as a communication channel or
medium for transfer of Data. These buses consist of 8, 16 or more wires of
the microcontroller. Thus, these can carry 8 bits, 16 bits simultaneously.
Two types of buses are as follows:
• Address Bus
• Data Bus
• Address Bus: Microcontroller 8051 has a 16-bit address bus for transferring
the data. It is used to address memory locations and to transfer the
address from CPU to Memory of the microcontroller. It has four addressing
modes
• Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to
carry data of particular applications.
Input / Output Port & Timers/Counters
• Input / Output Port - Normally microcontroller is used in embedded
systems to control the operation of machines in the microcontroller.
Therefore, to connect it to other machines, devices or peripherals we
require I/O interfacing ports in the microcontroller interface. For this
purpose microcontroller 8051 has four input, output ports to connect
it to the other peripherals.
• Timers/Counters - The 8051 microcontroller has two 16-bit timers
and counters. These counters are again divided into an 8-bit register.
The timers are used for measurement of intervals to determine the
pulse width of pulses.
Applications of 8051 Microcontroller
• Light sensing and controlling devices
• Temperature sensing and controlling devices
• Fire detections and safety devices
• Automobile applications
• Defense applications Some industrial applications of micro controller and its
applications
• Industrial instrumentation devices
• Process control devices Some of 8051 microcontroller devices are used in
measurement applications
• Voltmeter applications
• Measuring and revolving objects
• Current meter objects & Hand held metering system
8051 Microcontroller hardware
Input/output pins
Ports and Circuits
External Memory
Input/output pins
Ports
• 8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as
input or output.
• Hence, total 32 input/output pins allow the microcontroller to be connected with the
peripheral devices
• Each port of 8051 has bidirectional capability.
• Input Configuration: If any pin of this port is configured as an input, then it acts as
if it “floats”, i.e. the input has unlimited input resistance and in-determined
potential.
• Output Configuration: When the pin is configured as an output, then it acts as an
“open drain”. By applying logic 0 to a port bit, the appropriate pin will be
connected to ground (0V), and applying logic 1, the external output will keep on
“floating”.
• In order to apply logic 1 (5V) on this output pin, it is necessary to build an external pullup
resistor.
• Port 0 is called 'true bidirectional port' as it floats when configured as
input.
• Port-1, 2, 3 are called 'quasi bidirectional port’.
• Port 1: P1 is a true I/O port as it doesn’t have any alternative functions as
in P0, but this port can be configured as general I/O only. It has a built-in
pull-up resistor and is completely compatible with TTL circuits.
• Port 2: P2 is similar to P0 when the external memory is used. Pins of this
port occupy addresses intended for the external memory chip. This port
can be used for higher address byte with addresses A8-A15. When no
memory is added then this port can be used as a general input/output port
similar to Port 1.
• Port 3: In this port, functions are similar to other ports except that the logic
1 must be applied to appropriate bit of the P3 register.
Port-0 Pin Structure
• Port -0 has 8 pins (P0.0-P0.7).
Port-0 can be configured as a normal
bidirectional I/O port or it can be used
for address/data interfacing for
accessing external memory. When
control is '1', the port is used for
address/data interfacing. When the
control is '0', the port can be used as a
normal bidirectional I/O port
• Each pin of Port 0 possesses a bit latch which is part of the Special Function
Register (SFR) for Port 0, P0.
• Port-0 latch is written to with 1's when used for external memory access.
Port-1 Pin Structure

• Port-1 does not have any alternate function i.e. it is dedicated solely for
I/O interfacing.
• When used as output port, the pin is pulled up or down through
internal pull-up.
• To use port-1 as input port, '1' has to be written to the latch.
Port-2 Pin Structure

• Port-2 is used for higher external address byte or a normal


input/output port.
• The I/O operation is similar to Port-1.
• Port-2 latch remains stable when Port-2 pin are used for external
memory access.
• Each pin of Port-3 can be individually programmed for I/O operation
or for alternate function.
• The alternate function can be activated only if the corresponding
latch has been written to '1'.
• To use the port as input port, '1' should be written to the latch.
External Memory

• The 8051 Microcontroller based on Harvard Architecture &


Instructions / program to be executed are stored in Internal Memory
(4 KB ROM).
• Here Address space available is 0000H to 0FFFH.
• To connect External memory, address range available from 1000H to
FFFFH.
Interfacing External
Memory
• External program memory is fetched,
if either of the following two conditions
are satisfied.
• 1. (Enable Address) is low. The
microcontroller by default starts searching
for program from external program
memory.
• 2. PC is higher than FFFH for 8051. PSEN
tells the outside world whether the
external memory fetched is program
memory or data memory.
8051 Programming in C
Data Types
Time delay in 8051 C
I/O Programming
Logic operations
Data conversion Programs
Factors for Selecting the Programming
Language
• The following are few factors that are to be considered while selecting the
Programming Language for the development of Embedded Systems.
• Size: The memory that the program occupies is very important as
Embedded Processors like Microcontrollers have a very limited amount of
ROM (Program Memory).
• Speed: The programs must be very fast i.e., they must run as fast as
possible. The hardware should not be slowed down due to a slow running
software.
• Portability: The same program can be compiled for different processors.
• Ease of Implementation
• Ease of Maintenance
• Readability
Difference between C and Embedded C
• C used for desktop based • It is used for micro controller
applications based applications
• C code generate the compatible • Embedded programs generate
.exe files the .hex files
• It has limitless resources like • It has limited resources like
memory memory (RAM, ROM)
• C language uses the desktop OS • Embedded programming uses
memory the micro controller inbuilt
• C don’t have registers to store memory
data temporarily • It has registers
Data types
• Data Types in C Programming Language (or any programming
language for that matter) help us declaring variables in the program.
• The following are the extra data types in Embedded C associated with
the Keil’s Cx51 Compiler. • bit • sbit • sfr • sfr16
• The following table shows some of the data types in Cx51 Compiler
along with their ranges.
Time delay in 8051
• The delay length in 8051
microcontroller depends on
three factors:
• The crystal frequency
• The number of clock per
machine
• The C compiler.
I/O Programming
I/O Ports and Their Functions
• The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit
ports.
• Upon RESET, all the ports are configured as inputs, ready to be used
as input ports.
• When the first 0 is written to a port, it becomes an output.
• To reconfigure it as an input, a 1 must be sent to a port.
Port 0
• It has 8 pins (32 to 39).
• It can be used for input or output.
• It is also designated as AD0-AD7, allowing it to be
used as both address and data.
• In case of 8031 (i.e. ROM less Chip), when we need
to access the external ROM, then P0 will be used
for both Address and Data Bus.
• ALE (Pin no 31) indicates if P0 has address or data.
When ALE = 0, it provides data D0-D7, but when
ALE = 1, it has address A0-A7.
Port 1
• It is an 8-bit port (pin 1 through 8)
• It can be used as either input or output.
• It does not require pull-up resistors because they
are already connected internally.
• Upon reset, Port 1 is configured as an input port.
Port 2
• Port 2 occupies 8 pins (pins 21 through 28)
• It can be used for both input and output operations.
• Just as P1 (Port 1), P2 also does not require external
Pull-up resistors.
• It must be used along with P0 to provide the 16-bit
address for the external memory. So it is also
designated as (A8–A15), as shown in the pin diagram.
• When the 8051 is connected to an external memory, it
provides path for upper 8-bits of 16-bits address, and it
cannot be used as I/O.
• Upon reset, Port 2 is configured as an input port.
Port 2
• It is also of 8 bits and can be used as Input/Output.
• This port provides some extremely important signals.
• P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter)
respectively and are collectively used for Serial
Communication.
• P3.2 and P3.3 pins are used for external interrupts.
• P3.4 and P3.5 are used for timers T0 and T1
respectively.
• P3.6 and P3.7 are Write (WR) and Read (RD) pins.
• These are active low pins, means they will be active
when 0 is given to them and these are used to provide
Read and Write operations to External ROM in 8031-
based systems.
Logic operations
Basics of Bitwise Operations
• Bitwise operations allows us for Setting, Inverting, Toggling, Clearing,
Extracting and Inserting bits in embedded programming.
• Here is a table which summarizes operations with 2-operands.
Designing Embedded System with
8051 Microcontroller
Factors to be considered in selecting a controller
why 8051 Microcontroller
Designing with 8051
Architecture diagram of 8051: Functional Description
• Accumulator: (Acc) Acc is an 8 bit special function register. It acts an
operand register. Result is temporarily stored in this register. It is used in
parallel I/O transfer.
• B Register : B register is 8 bit SFR. It is used during multiply and divide
operations. For other operations , it can be used as a scratchpad register.
• Program Status Word (PSW) : PSW register is 8 bit SFR. It contains
program status information. It is also used to select any one of the
required register bank.
• Stack Pointer (SP): It is 8 bit register. It is used to point the stack memory.
The stack may reside in anywhere in on-chip memory. It is incremented
before data is stored during PUSH & CALL instructions. After reset SP is
initialized to 07h. This causes the stack begin at location 08h.
• Data Pointer (DPTR) : It is 16 bit register. It may be manipulated as a 16 bit
register or as two independent 8 bit registers. Its function is to hold a 16
bit address. This register is used for external reference.
• Port 0 to Port 3 : Each port contains separate address. Using this address,
User can communicate with these ports. Each port contains latch, output
driver & input buffer.
• Serial Data Buffer : Serial data buffer contains two independent registers
of a transmit buffer register and a receiver buffer register.
• Transmit buffer is a parallel in and Serial out register.
• Receiver buffer is a Serial in and parallel out register.
• When data is moved to SBUF, it goes to transmit buffer .
• When data is moved from SBUF, it comes from the receive buffer.
• Timer Registers : Register pairs (TH0,TL0) & (TH1,TL1) are the two 16
bit counting registers for Timer/Counter 0 and 1 respectively.
• Control Registers : The special function registers IP, IE, TMOD, TCON,
SCON and PCON contain control and status information for
interrupts, timer/counters and serial port.
• Timing & Control Unit : This unit derives an necessary timing and
control signals required for the internal operations of the circuit. It
derives control signals required for controlling the external system
bus. The interrupt, serial port and timer circuits are controlled by the
control signals generated by timing & control unit.
• Oscillator : This circuit generates the basic timing clock signal for the
operation of the circuit using crystal oscillator.
• Instruction Register : This register decodes the opcode of an instruction to
be executed and gives information to the timing & control unit, and to
generate necessary signals for the execution of the instruction.
• EPROM & Program Address Register : These blocks provide an onChip
EEPROM and a Mechanism to internally address it.
• RAM & RAM address register : These blocks provide an onChip RAM and a
mechanism to internally address it.
• ALU : The Arithmetic And Logic Unit performs 8 bit arithmetic and logical
operations over the operands held by the temporary registers TMP 1 and
TMP 2. User cannot access these temporary registers.
• SFR Register Banks : It is a set of registers, which can be addressed using
their respective addresses which lie in the range 80H to FFH.
The 8051 oscillator and Clock
• 8051 chips are designed to run at specific minimum and maximum frequencies.
(Typically 1 MHz to 16 MHz).
• Minimum frequency implies that some internal memories are dynamic and must
always operate above a minimum frequency or data will be lost.
• Clock frequency is the smallest interval of time within the microcontroller called
the pulse, P, time.
• State is the basic time for discrete operations of a microcontroller such as opcode
fetching, opcode decoding, opcode execution, or writing a data byte. Two
oscillator pulses form each state.
• Machine cycle is the smallest interval of time required to execute a simple
instruction, or part of a complex instruction. The machine cycle is made up of 6
states or 12 clock pulses. Program instructions may require one, two or four
machine cycles.
• Therefore the formula to calculate time taken for each instruction is
given by:
Why is 11.0592 MHz crystal considered over
12 MHz ?
• For serial communication in 8051, it is required that the internal
counters must divide the basic clock rate to achieve standard
communication bits per second (baud) rates.
• The standard baud rates are 19200, 9600, 4800, 2400, 1200, and 300
Hz.
• If the basic clock frequency is not divisible without a remainder, then
the resulting communication frequency is not standard. e.g. if crystal
frequency is 11.0592 MHz then;
Memory Organisation
8051 architecture provide lowest 4K bytes of program memory as On-Chip
memory.
• Switching between internal program memory and external program memory is
accomplished by changing the logic level of the pin External Access (EA\----read
as EA bar). EA\ pin is an active low pin.
• Connect EA\ pin to logic 1(Vcc) connects the chip to execute instruction from
program memory upto 4K (program memory location upto 0FFFFH) from
internal memory and 4K(program memory location 1000H)onwards from
external memory, while connecting EA\ pin o logic 0(GND) configures chip to
external program execution mode, where then entire code memory is executed
from the external memory.
• The control signal for external program memory execution is PSEN\(Program
Strobe Enable----PSEN\ is read as PSEN bar)
• For internal program memory fetches PSEN\ is not activated.
External Program Memory Chip(ROM)
interfacing

If the program memory is external , 16 I/O lines are used for accessing the external
memory.
Port 0 and Port 2 are used for external memory accessing, where initially Port 0 send
lower order address when ALE signal of 8051 is high and then it function as input port for
data transfer from the corresponding memory location while Port 2 sends higher order
address.
Internal Memory
Register Organisation
Special Function Register(SFR)
• The SFR registers are located within the Internal Memory in the address
range 80h to FFh. Not all locations within this range are defined.
• Each SFR has a very specific function. Each SFR has an address (within the
range 80h to FFh) and a name which reflects the purpose of the SFR.
• Although 128 byes of the SFR address space is defined only 21 SFR
registers are defined in the standard 8051.
• Undefined SFR addresses should not be accessed as this might lead to
some unpredictable results. Note some of the SFR registers are bit
addressable. SFRs are accessed just like normal Internal RAM locations.
PSW Program Status Word ( flag register)

Carry Flag(CY): conventional carry, or borrow Overflow(OV): to check arithmetic operation


is out of range

Auxiliary conventional auxiliary carry Even Parity accumulator parity flag (even
Flag(AC): (half carry) flag(P): parity)

Flag 0.(F0): general-purpose flag RS0 and RS1 active register bank
SFR Registers for the Internal Timer
TCON :
• The Timer Control register is an SFR at address 88h, which is bitaddressable.
TCON is used to configure and monitor the 8051 timers. • The TCON SFR also
contains some interrupt control bits, described later.
TMOD:
The Timer Mode register is an SFR at address 89h and is used to define the
operational modes for the timers.
TL0 (Timer 0 Low) and TH0 (Timer 0 High) are two SFR registers addressed at 8Ah
and 8Bh respectively. The two registers are associated with Timer 0.
TL1 (Timer 1 Low) and TH1 (Timer 1 High) are two SFR registers addressed at 8Ch
and 8Dh respectively. These two registers are associated with Timer 1.
Power Control Register
PCON (Power Control) register is an SFR at address 87h. It contains various control
bits including a control bit, which allows the 8051 to go to ‘sleep’ so as to save
power when not in immediate use.
Serial Port Registers
SCON (Serial Control) is an SFR register located at addresses 98h, and it is bit
addressable. SCON configures the behaviour of the onchip serial port, setting up
parameters such as the baud rate of the serial port, activating send and/or receive
data, and setting up some specific control flags.
SBUF (Serial Buffer) is an SFR register located at address 99h. SBUF is just a single
byte deep buffer used for sending and receiving data via the on-chip serial port.
Interrupt Registers
• IE (Interrupt Enable) is an SFR register at addresses A8h and is used
to enable and disable specific interrupts. The MSB bit (bit 7) is used
to disable all interrupts.
• IP (Interrupt Priority) is an SFR register at addresses B8h and it is bit
addressable. The IP register specifies the relative priority (high or
low priority) of each interrupt. On the 8051, an interrupt may either
be of low (0) priority or high (1) priority.
Programming embedded
systems
Structure of embedded program
Infinite loop
Compiling
Linking and debugging
Structure of embedded program
The embedded C program has a structure similar to C programming.
The five layers are:
• Comments
• Pre-processor directives
• Global declaration
• Local declaration
• Main function()
Preprocessor Directives Section:
• The Pre-Processor directives tell the compiler which files to look in to
find the symbols that are not present in the program.

For Example, in 8051 Keil compiler we use,


#include<reg51.h>

At runtime, the compiler looks for preprocessor directives within the


code and resolves them completely before resolving any of the
functions within the code itself.
Global Declaration Section:
• This part of the code is the part where the global variables are
declared. Also, the user-defined functions are declared in this part of
the code. They can be accessed from anywhere.
Eg: void delay (int);

Local Declaration Section:


• These variables are declared in the respective functions and cannot
be used outside the main function.
Main Program
• The main part of the program begins with main().
• If the main function is expected to return an integer value, we would
write int main().
• If no return is expected, convention dictates that we should write void
main(void).
Infinite loop
• One of the most fundamental differences between programs
developed for embedded systems and those written for other
computer platforms is that the embedded programs almost always
have an infinite loop.
• It is intended to be run until either the world comes to an end or the
board is reset, whichever happens first.
• If the software stops running, the hardware is rendered useless. So
the functional parts of an embedded program are almost always
surrounded by an infinite loop that ensures that they will run forever.
• Infinite loop using while: While(1) { }
• Infinite loop using do while: do { } while(1);
• Infinite loop using for : for ( ; ; ; ) { }
• Infinite loop using goto (‘goto' when combined with a 'label' can
create infinite loops)
label : // Task to be repeated
//………..
//………...
Goto label ;
Embedded Software Development
Process
Compiling

• Compiler mainly to translate programs written in some human-


readable language into an equivalent set of opcodes for a particular
processor.
• Each processor has its own unique machine language, so you need to
choose a compiler that is capable of producing programs for your
specific target processor
• The use of a cross-compiler is one of the defining features of
embedded software development
• Regardless of the input language (C/C++, assembly, or any other), the
output of the cross-compiler will be an object file
• The contents of an object file can be thought of as a very large,
flexible data structure. The structure of the file is often defined by a
standard format such as the Common Object File Format (COFF) or
Executable and Linkable Format (ELF).
• Most object files begin with a header that describes the sections that
follow. Each of these sections contains one or more blocks of code or
data that originated within the source file you created
Linking
• All of the object files resulting from the compilation in step one must be
combined.
• Linker combines these object files and, in the process, to resolve all of the
unresolved symbols
• The output of the linker is a new object file that contains all of the code
and data from the input object files and is in the same object file format. It
does this by merging the text, data, and bss sections of the input files.
• When the linker is finished executing, all of the machine language code
from all of the input, object files will be in the text section of the new file,
and all of the initialized and uninitialized variables will reside in the new
data and bss sections, respectively.
• After merging all of the code and data sections and resolving all of the
symbol references, the linker produces an object file that is a special
relocatable copy of the program.
• In other words, the program is complete except for one thing: no
memory addresses have yet been assigned to the code and data
sections within
Debugging

You might also like