You are on page 1of 34

VIVEKANANDHA COLLEGE OF ENGINEERING FOR WOMEN

[AUTONOMOUS INSTITUTION AFFILIATED TO ANNA


UNIVERSITY, CHENNAI]
Elayampalayam – 637 205, Tiruchengode, Namakkal Dt., Tamil
Nadu.

B.E. / B.Tech. / M.E. / M.Tech. DEGREE END-SEMESTER EXAMINATIONS – APRIL 2019.


SIXTH SEMESTER
INFORMATION TECHNOLOGY
U15IT512-MICROCONTROLLER &EMBEDDED SYSTEMS
(Regulation 2015)
ANSWER KEY & SCHEME OF EVALUATION
Time: Three Hours Maximum: 100 Marks
Answer ALL the questions
PART – A
(10 x 2 = 20 Marks)
No. Questions Marks
1. Define bit, byte and word. 2
A bit is the smallest unit of data in a computer. A bit has a single binary value, either
0 or 1. A byte is a collection of 8 bits (0 or 1), whereas a Word is collection of 16 bits
( 2 Bytes).
2. Why address bus is unidirectional? 2
Address bus is Unidirectional because the microprocessor is addressing a specific
memory location. No outside devices cannot write into Microprocessor.
3. What is the function of ALE signal? 2
ALE ( Address Latch Enable)this is a signal which goes HIGH every time 8085
begins an operation. it indicates that the bits on AD0 to AD7 are address bits.
This signal is mainly used to latch the low order address from the multiplexed bus.
4. How the program memory is organized in 8051 based system? 2
The 8051 microcontroller's memory is divided into Program Memory and
Data Memory. Program Memory (ROM) is used for permanent saving program being
executed
5. List the addressing modes of 8051. 2
In 8051 There are six types of addressing modes.
1. Immediate Addressing Mode.
2. Register Addressing Mode.
3. Direct Addressing Mode.
4. Register Indirect Addressing Mode.
5. Indexed Addressing Mode.
6. Implied Addressing Mode
6. What is the function of SWAP? 2
SWAP instruction works only on the accumulator (SWAP A) . It swaps the lower
nibble and higher nibble .The lower 4 bits are put into the higher 4 bits and the higher
4 bits are put into the lower 4 bits.
7. Name the five interrupt sources of 8051. 2
 External interrupt-0 , External interrupt-1,Timer-0 interrupt, Timer-1 interrupt, and
serial port interrupt
8. Define the register IE format of 8051. 2
Interrupt Enable (IE) Register: This register is responsible for enabling and disabling
the interrupt. It is a bit addressable register in which EA must be set to one for
enabling interrupts. The corresponding bit in this register enables particular interrupt
like timer, external and serial inputs.
9. Define baud rate. 2
Baud rate is used to indicate the rate at which data is being transferred . Baud rate =
1/Time for a bit cell.
10. What is “W” register in PIC Microcontroller? 2
The W register is a special register in the PIC architecture, that is used as one of the 2
operands for ALU operations, and can also be the destination for any ALU operation.

PART - B

(5X13=65)

Q.N Scheme of
Answer
o Evaluation
11. (a) Different Types of Registers used in 8051 Microcontroller

Register is a main part in the microcontrollers and processors that provide a fast way
to collect and store data. If we want to manipulate data with a controller or processor
by performing addition, subtraction, and so on, we cannot do that directly in the
memory, but it needs registers to process and store the data. Microcontrollers contain
several types of registers that can be classified according to their content or
instructions that operate in them.
Different Types of Registers in the 8051 Microcontroller
Register
A register is a small place in a CPU that can store small amounts of the data used for
performing various operations such as addition and multiplication and loads the
resulting data on main memory. Registers contain the address of the memory location
Types-2M
where the data is to be stored. The size of the register is very important for modern
controllers. For instance, for a 64-bit register, a CPU tries to add two 32-bit numbers
and gives a 64-bit result.
Types of Registers
Explanation-
The 8051 microcontroller contains mainly two types of registers: 7M
 General purpose registers (Byte addressable registers)
 Special function registers (Bit addressable registers) Diagram-4M
8051 RAM Memory
The 8051 microcontroller consists of 256 bytes of RAM memory, which is divided
into two ways, such as 128 bytes for general purpose and 128 bytes for special
function registers (SFR) memory. The memory which is used for general purpose is
called as RAM memory, and the memory used for SFR contains all the peripheral
related registers like Accumulator, ‘B’ register, Timers or Counters, and interrupt
related registers.
General Purpose Registers

General Purpose Memory


The general purpose memory is called as the RAM memory of the 8051
microcontroller, which is divided into 3 areas such as banks, bit-addressable area, and
scratch-pad area. The banks contain different general purpose registers such as R0-
R7, and all such registers are byte-addressable registers that store or remove only 1-
byte of data.

Banks and Registers


The B0, B1, B2, and B3 stand for banks and each bank contains eight general purpose
registers ranging from ‘R0’ to ‘R7’. All these registers are byte-addressable registers.
Data transfer between general purpose registers to general purpose registers is not
possible. These banks are selected by the Program Status Word (PSW) register.
General Purpose Registers
PSW (Program Status Word) Register
The PSW register is a bit and byte-addressable register. This register reflects the
status of the operation that is carried out in the controller. The PSW register
determines bank selection by a RS1 and RS0, as shown below. The physical address
of the PSW starts from D0h and the individual bits are accessed with D0h to D7h.

PSW Registers

Bank selection Registers


Special Function Registers (SFR)
Special function registers are upper RAM memory in the 8051 microcontroller. These
registers contain all peripheral related registers like P0, P1, P2, P3, timers or counters,
serial port and interrupts-related registers. The SFR memory address starts from 80h
to FFh. The SFR register is implemented by bit-address registers and byte-address
registers.
Special Function Registers (SFR)
The accumulator, B register, Po, P1, P2, P3, IE registers are bit-addressable register
remaining all are byte-addressable registers.

Accumulator
The accumulator which is also known as ACC or A is a bit as well as a byte-
addressable register by an address of the accumulator. If you want to use a bit-
addressable register, you can use a single bit (E0) of the register and you can use an
8-bit of the accumulator as a byte-addressable register. The accumulator holds the
results of most Arithmetic and logical operations.

Accumulator register
Port Registers
The 8051 microcontroller consists of 4-input and output ports (P0, P1, P2, and P3) or
32-I/O pins. Each pin is designed with a transistor and P registers. The pin
configuration is very important for a microcontroller that depends on the logic states
of the registers. The pin configuration as input given by 1 or output 0 depends on the
logic states. If logic 1 is applied to the bit of the P register, the output transistor
switches off the appropriate pin that acts as an input pin.

Port Registers of 8051


Counters and registers
Many microcontrollers consist of one or more timers and counters. The timers are
used to generate precious time delay and the source for the timers is crystal oscillator.
The counters are used to count the number of external events – for instance,
the objective counter , and the source for counters are external pulses applied across
the counter pin.
The 8051 microcontroller consists of two 16-bit timers and counters such as timer 0
and timer 1. Both the timers consist of a 16-bit register in which the lower byte is
stored in the TL and the higher byte is stored in the TH. The Timer can be used as a
counter as well as for timing operation that depends on the source of the clock pulses
to the counters.

The Counters and Timers in 8051 microcontrollers contain two special function
registers: TMOD (Timer Mode Register) and TCON (Timer Control Register), which
are used for activating and configuring timers and counters.
Types of Shift Register
Shift registers are a type of sequential logic circuits that are mainly used for storage
of digital data. The shift registers are bit-addressable registers that store only one bit
of data. The shift registers are constructed with flip-flops – a group of flip-flops
connected as a chain so that the output from one flip-flop becomes the input of the
next flip-flop.

All the flip-flops are driven by the clock signals that are implemented by the D-flip-
flap. The shift registers are mainly used for serial communication.
These are classified into 4- types:

 Serial in Serial out (SISO)


 Serial in Parallel out (SIPO)
 Parallel in Serial out (PISO)
 Parallel in Parallel out (PIPO)

D- flipflop register
These are all different types of registers in an 8051 microcontroller. We hope that we
have successfully given you relevant content with the appropriate program for each
register. Furthermore, for any sort of help to know the coding of several other
registers, you can contact us by commenting below.

11. (b) Embedded Systems Hardware Components


As we know embedded systems are the combination of hardware and software. There Diagram-5M
are different hardware components like power supply, processor, memory, timers and Explanation-
counters that make the embedded hardware. 8M
Power Supply
The power supply is an essential part of any embedded systems circuits. An
embedded system may need a supply of 5 volts or if it is low power then maybe 3.3
or 1.8v. The supply may be provided with the help of battery or we can use any wall
adapter. It will depend on the application need.
The power supply circuit can be designed with the help some little knowledge of
electronics. For that, we need a bridge rectifier circuit, capacitor as a filter and a
voltage regulator that provides constant output supply.
You may find a different circuit on the internet or you may try below circuit.
It is a very common circuit that produces 5 Volt at the output. You can change the
voltage regulator to 7808,7812 depending upon the output required.

Characteristics of Good Power Supply


 Stable & Smooth Output
 Proper Output Current to Drive the Load
 Perfect Power Efficiency
 Stable in Different Temperature Range
 Proper Noise Filtering
 Proper Decoupling
 Line Regulation – Fluctuation in output while input changes
 Load Regulation – Fluctuation in output voltage when load current changes
 Efficiency
 Input/Output Ripple Voltage
 Transient Response
 Allowable Dissipation

Processor
A processor is the main brain inside any embedded systems. This is a major factor
that affects the performance of the system. There are different processors available in
the market. An embedded system may use microprocessor or microcontroller.
The processor comes in different architecture like 8-bit, 16-bit and 32-bit. The 8-bit
processor is generally used in a small application where we need some basic
computation like input and output no heavy processing.
For higher-end application where performance matters and need some graphical user
interface, we use 16 or 32-bit processor.
What are the criteria for selecting the processor?
 Speed
 Unit Price
 Packaging
 Performance
 Peripheral Set
 Timer on the Chip
 Operating Voltage
 Number of I/O Pins
 Power Consumption
 Amount of RAM and ROM
 Specialized Processing Units
 Architecture 8-bit, 16-bit, or 32-bit
 Availability of Supplier for a given core
 Easy to upgrade to higher or lower power consumption mode
 Availability of Software tools like assembler, debugger, compiler, emulator
and technical support

Memory
If we are using a microcontroller like AT89s51, AT89s52 or ATmega. The memory is
available on-chip. We generally talk about two types of memory in the embedded
systems
 Read-Only memory(RAM)
 Random Access Memory(ROM)
 Electrically Erasable Programmable Read-Only Memory (EEPROM)

RAM memory is volatile memory and used for temporary storage of the data. And the
selection of it depends on the user need and the application.
The ROM memory or Code Memory. This is used for the storage of the program.
Once system powered, the system fetches the code from the ROM memory.
The EEPROM is a unique memory. The content can be erased and reprogrammed by
a high voltage pulse input. This is used to store the data by the program itself.
Suppose we have a temperature data logger. And it needs to store the data every one
hour. It means we need the data at runtime after the system is started.
The system will read temperature and store in the EEPROM memory. And it will be
permanent. And you can retrieve the data later.
So an embedded system developer decide which memory to use for its application.
Timers-Counters
If you are working in embedded systems you must have heard about
 What are timer and counter
 Why we use timer and counter
 What is difference between timers and counter

In some application, we need to generate some delay. Like for blinking an LED, we
need a delay. For making square pulse we need a delay.
But there is some issue when we generate the delay from the normal coding style by
making any loop running for a particular time. Definitely, this will give you some
delay but the code after this loop remains in waiting for state and delayed.
So it is not the best approach to generate the delay. For such kind of application
where we need a delay for a specific time interval without affecting the normal code
execution, we use timer and counter.
By setting some register for timer and counter using the programming we get the
desired delay. The amount of delay depends on the system frequency and crystal
oscillator.
Communication Ports
Embedded systems hardware has different types of communication ports to
communicate with the other embedded devices.
Different communication ports in embedded systems
 UART
 CAN
 SPI
 I2C
 USB
 Ethernet
 RS-232
 RS-423
 RS-485

But for a small level of embedded systems microcontroller has on-chip


communication ports.
For example, popular Arduino UNO board has ATmega328 IC and it has following
communication port:
 UART
 I2C
 SPI

For sending data from one board to other we can use these serial protocols. But for
that, we need to program it.
Input and Output
To interact with the embedded systems we need input. The input may be provided by
the user or by some sensor. Sometimes some systems need more input or output. So
the processor selection will be based on I/O.
These input and output are generally divided into ports like P0, P1, P2 and P3 in
8051microcontrollersr. And PA, PB, PC and PD in ATmega series of the
microcontroller.
The I/O need to be configured for input or output based on the provided register. And
for that, we need to refer the datasheet of the manufacturer.
Application Specific Circuits
Some hardware components are common while designing the embedded systems. But
some are different and depends on the application need. Like a temperature sensor
need a temperature sensor for sensing the temperature. While others hand an alcohol
detector has a sensor to detect the alcohol level.
But the remaining hardware components might be the same like
 Power Supply
 Processor
 Display Device
 Buzzer for Alert

Software Components
Once the hardware is completed we need to build the software for the embedded
devices. There are different software tools for programming and coding. These
software tools are referred to as software components.
How is software embedded into a system?
We need a program written in assembly or in embedded c language. And then we
compile it. This compiled code converted into HEX code. This hex code is
programmed or burned into the ROM of the system using some programmer.
These are the tools that are generally used in embedded system development
 Assembler
 Emulator
 Debugger
 Compiler

Assembler
When you program in assembly language. This assembly language program is
converted into the HEX code using this utility. Then using some hardware called as a
programmer we write the chip.
Emulator
An emulator is hardware or software tool that has a similar functionality to the target
system or guest system. It enables the host system to execute the functionality and
other components. It is a replica of the target system. And used for debugging the
code and issues.
Once program or code is fixed at the host system. It is transferred to the target
system.
Debugger
Sometimes we are not getting expected results or output due to errors or bug. There
are certain tools that are specifically used for the debugging process. Where we can
see the controls flow and register value to identify the issue.
Compiler
A compiler is a software tool that converts one programming language into target
code that a machine can understand. The compiler basically used for translating the
high-level language into the low-level language like machine code, assembly
language or object code.
12. (a) ARCHITECTURE OF 8051 INTRODUCTION
8051 microcontroller is designed by Intel in 1981. It is an 8-bit Diagram-6M
microcontroller. It is built with 40 pins DIP (dual inline package), 4kb of ROM
storage and 128 bytes of RAM storage, 2 16-bit timers. It consists of are four parallel Explanation-
8-bit ports, which are programmable as well as addressable as per the requirement. 7m
An on-chip crystal oscillator is integrated in the microcontroller having crystal
frequency of 12 MHz.
ARCHITECTURE
In the following diagram, the system bus connects all the support devices to the
CPU. The system bus consists of an 8-bit data bus, a 16-bit address bus and bus
control signals. All other devices like program memory, ports, data memory, serial
interface, interrupt control, timers, and the CPU are all interfaced together through the
system bus.

Central Processor Unit (CPU)


As we know that the 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 and executes them and do the expected task
of that application.

Interrupts

As its name suggests, 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 us a
mechanism to put on hold the ongoing operations, execute a subroutine and then
again resumes to another type of operations.

The Microcontroller 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
are shown in below.

 INTO
 TFO
 INT1
 TF1
 R1/T1

Out of these, (INT0) ̅ and (INT1) ̅ are external interrupts that could be negative edge
triggered or low level triggered. When All these interrupts are activated, set the
corresponding flogs except for serial interrupt,.The interrupt flags are cleared when
the processor branches to the interrupt service routine (ISR). The external interrupt
flags are cleared when the processor branches to the interrupt service routine,
provides the interrupt is a negative edge triggered whereas the timers and serial port
interrupts two of them are external interrupts, two of them are timer interrupts and
one serial port interrupt terminal in general.

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 of microcontroller also requires a memory to store data or
operands temporarily of the micro controller. The data memory of the 8051 is used to
store data temporarily for operation is known RAM memory. 8051 microcontroller
has 4K of code memory or program memory,that has 4KB ROM and also 128 bytes
of data memory of RAM.

BUS

Basically Bus is a collection of wires which work as a communication channel or


medium for transfer of Data. These buses consists of 8, 16 or more wires of the
microcontroller. Thus, these can carry 8 bits,16 bits simultaneously. Hire two types of
buses that are shown in below

 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 that are

 Immediate addressing modes.


 Bank address (or) Register addressing mode.
 Direct Addressing mode.
 Register indirect addressing mode.

Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to carry
data of particular applications.

Oscillator

Generally, we know that the microcontroller is a device, therefore it requires clock


pulses for its operation of microcontroller applications. For this purpose,
microcontroller 8051 has an on-chip oscillator which works as a clock source for
Central Processing Unit of the microcontroller. The output pulses of oscillator are
stable. Therefore, it enables synchronized work of all parts of the 8051
Microcontroller.

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 4 input, output ports to connect it to the other
peripherals

Timers/Counters
8051 microcontroller has two 16 bit timers and counters. These counters are again
divided into a 8 bit register. The timers are used for measurement of intervals to
determine the pulse width of pulses.

12. (b) INPUT OUTPUT PORT OF 8051


8051 microcontrollers have 4 I/O ports each of 8-bit, which can be Types-2m
configured as input or output. Hence, total 32 input/output pins allow the
microcontroller to be connected with the peripheral devices. Register-2m
Explanation-
 Pin configuration, i.e. the pin can be configured as 1 for input and 0 for 9m
output as per the logic state.
o Input/Output (I/O) pin − All the circuits within the
microcontroller must be connected to one of its pins except P0
port because it does not have pull-up resistors built-in.
o Input pin − Logic 1 is applied to a bit of the P register. The output
FE transistor is turned off and the other pin remains connected to
the power supply voltage over a pull-up resistor of high resistance.
 Port 0 − The P0 (zero) port is characterized by two functions −
o When the external memory is used then the lower address byte
(addresses A0A7) is applied on it, else all bits of this port are
configured as input/output.
o When P0 port is configured as an output then other ports consisting
of pins with built-in pull-up resistor connected by its end to 5V
power supply, the pins of this port have this resistor left out.
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 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.
Pins Current Limitations
 When pins are configured as an output (i.e. logic 0), then the single port
pins can receive a current of 10mA.
 When these pins are configured as inputs (i.e. logic 1), then built-in pull-up
resistors provide very weak current, but can activate up to 4 TTL inputs of
LS series.
 If all 8 bits of a port are active, then the total current must be limited to
15mA (port P0: 26mA).
 If all ports (32 bits) are active, then the total maximum current must be
limited to 71mA.
8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI. Each interrupt can
be enabled or disabled by setting bits of the IE register and the whole interrupt
system can be disabled by clearing the EA bit of the same register.
IE (Interrupt Enable) Register
This register is responsible for enabling and disabling the interrupt. EA register is
set to one for enabling interrupts and set to 0 for disabling the interrupts. Its bit
sequence and their meanings are shown in the following figure.

It disables all interrupts. When EA = 0 no interrupt will be acknowledged and EA = 1 enables


EA IE.7
interrupt individually.

- IE.6 Reserved for future use.

- IE.5 Reserved for future use.

ES IE.4 Enables/disables serial port interrupt.

ET1 IE.3 Enables/disables timer1 overflow interrupt.

EX1 IE.2 Enables/disables external interrupt1.

ET0 IE.1 Enables/disables timer0 overflow interrupt.

EX0 IE.0 Enables/disables external interrupt0.

IP (Interrupt Priority) Register


We can change the priority levels of the interrupts by changing the corresponding bit
in the Interrupt Priority (IP) register as shown in the following figure.
 A low priority interrupt can only be interrupted by the high priority
interrupt, but not interrupted by another low priority interrupt.
 If two interrupts of different priority levels are received simultaneously, the
request of higher priority level is served.
 If the requests of the same priority levels are received simultaneously, then
the internal polling sequence determines which request is to be serviced.

- IP.6 Reserved for future use.

- IP.5 Reserved for future use.

PS IP.4 It defines the serial port interrupt priority level.

PT1 IP.3 It defines the timer interrupt of 1 priority.

PX1 IP.2 It defines the external interrupt priority level.

PT0 IP.1 It defines the timer0 interrupt priority level.

PX0 IP.0 It defines the external interrupt of 0 priority level.


13. (a) JUMP INSTRUCTION
8051 Instruction Set: JMP Explanation
-7m
Operation Instruction-
JMP
: 4m
Example-
Jump to Data Pointer + 2m
Function:
Accumulator

Syntax: JMP @A+DPTR

OpCod Byte Flag


Instructions
e s s

JMP Non
0x73 1
@A+DPTR e

Description: JMP jumps unconditionally to the address represented by


the sum of the value of DPTR and the value of the Accumulator.

8051 Conditional Jump Instructions:

Instruction Action of the Instruction

JZ Jump if Accumulator A = 0

JNZ Jump if Accumulator A ≠ 0

DJNZ Decrement and jump if Accumulator A ≠ 0

CJNE A,byte Compare and Jump if Accumulator A ≠ byte

CJNE
Compare and Jump if Accumulator A ≠ #data
reg,#data

JC Jump if Carry Flag CY = 1

JNC Jump if Carry Flag CY = 0

JB Jump if bit is set i.e. bit = 1

JNB Jump if bit is not set i.e. bit = 0


Jump if bit is set and clear that bit i.e bit = 1 and
JBC
clear bi

Example # 1:

MOV A,R0 ;A = R0

JZ OVER ;Jump if accumulator A = 0

MOV A,R1 ;A = R1

JZ OVER ;Jump if accumulator A = 0

.........

OVER:

Either R0 or R1 is zero, it jumps to the label OVER. The JZ instruction


can be used only for register accumulator A. It can used only check to
see whether the Accumulator is zero. It does not apply to any other
register.

Example # 2:

Lets write a program in which if R4 register contains the value 0. Then


put 55H in R4 register:

Answer:

MOV A,R4 ;Copy R4 to accumulator A

JNZ NEXT ;Jump if accumulator is not zero

MOV R4,#55H ;Put value 55H into register R4

NEXT: ..........

JNC [Jump if No Carry i.e. Jumps if Carry Flag = 0]:

In JNC instruction, the carry flag bit in the flag [PSW] register is used to
make the decision weather to jump. In executing "JNC label", the
processor looks ar the carry flag to see it if is raised carry flag CY = 1, if
it is not, the CPU starts to fetch and execute instructions from the address
of the label. If carry flag CY=1, it will not jump but will execute the next
instruction below JNC.

JC [Jump if Carry i.e. Jumps if Carry Flag = 1]:


In JC instruction, if carry flag CY=1, it jumps to the target address.

JB [Jump if bit is high]:

JNB [Jump if bit is low]:

These bit manipulation instructions will be discussed in the upcoming


chapters in details.

ALL Conditional Jumps are Short Jumps:

All conditional jumps are short jumps, as in that the address of the target
must be within -128 to -127 bytes of the contents of the program counter
[PC].

Unconditional Jump Instructions:

The unconditional jump is a jump in which control is transferred


unconditionally to the target location. There are 2 unconditional jumps in
the 8051: LJMP [Long Jump] and SJMP [Short Jump].

 Long Jump [LJMP]:

LJMP [Long Jump] is an


unconditional long jump. LJMP is a 3-byte instruction in which the first
byte is the opcode, and the second and third bytes represent the 16-bit
address of the target location. The 2-byte target address allows a jump to
any memory location from 0000 to FFFFH. The program counter [PC] is
a 16-bit in the 8051,giving a ROM address space of 64K bytes. Not all
family members of 8051 have this much on-chip program ROM. The
original 8051 had only 4K-bytes of on-chip ROM for program space. For
this reason, there is also a short jump SJMP instruction which is a 2-byte
instruction as opposed to the 3-byte instruction which is long
jump LJMP. Using short jump SJMP save some bytes of memory in
many applications where memory space in short supply.

 Short Jump [SJMP]:

Short Jump [SJMP] is a two byte instruction.


The first byte is the opcode and the second byte is the relative address of
the target location. The relative address range of 00 - FFH is divided into
forward and backward jumps. Memory relative to the address of the
current PC [Program counter} is within the -128 to +128 bytes. The
target address in within 127 bytes from the current PC [Program
counter], if the jump is forward. The target address is within -128 bytes
from the current PC [Program counter], if the jump is backward.

Short Jump Address Calculations:


All conditional jumps such as JNC, JZ and DJNZ are short jumps. They
are all 2-byte instructions. In these instructions, the first byte is the
opcode and the second byte is the relative address. The target address is
relative to the value of the program counter [PC]. To calculate the target
address, the second byte is added to the PC [program counter] of the
instruction immediately below the jump.

13. (b) 13.(b) RAM Location


25 = 04
26 = 20 Program-
27 = 15 13m
MOV DPTR, #26H ; Initialize memory Points.
MOVX A, @DPTR ; Get the count.
MOV R0, #10 ; Initialize the iteration counter.
; Initialize pointer to array of
MOV DPTR
numbers
MOV R1, #00 ; Result = 0

Back Movx. A, @ DPTR ; Get the numbers


ADD. A, R1 ; A  Result & A
MOV R1,A ; Increment the array pointer
INC DPTR ; Increment the array pointer
DJNZ R0, BACK ; Decrement the iteration count
MOV DPTR R0, #30H ; Initialize memory pointer
MOV A1 R1 ; Get the result
MOV X@ DPTR, A ; Store the result
MOV DPTR, #31 H ; Initialize memory
MOV A1 R1 ; Get the result pointer
MOVX @ DPTR, A ; Store the result
14. (a) SERIAL COMMUNICATION MODE OF 8051
Types-2m
In serial communication, data is in the form of binary pulses. In other Diagram-
words, we can say Binary One represents a logic HIGH or 5 Volts, and 4m
zero represents a logic LOW or 0 Volts. Serial communication can take Explanation
-7m
many forms depending on the type of transmission mode and data
transfer. The transmission modes are classified as Simplex, Half
Duplex, and Full Duplex. There will be a source (also known as
a sender) and destination (also called a receiver) for each transmission
mode.

Transmission Modes – Serial Communication


The Simplex method is a one-way communication technique. Only one
client (either the sender or receiver is active at a time). If a sender
transmits, the receiver can only accept. Radio and Television
transmission are the examples of simplex mode.
In Half Duplex mode, both sender and receiver are active but not at a
time, i.e. if a sender transmits, the receiver can accept but cannot send
and vice versa. A good example is an internet. If a client (laptop) sends a
request for a web page, the web server processes the application and
sends back the information.
The Full Duplex mode is widely used communication in the world. Here
both sender and receiver can transmit and receive at the same time. An
example is your smartphone.
erial communication is a technique used to send data bit by bit using a
two-wires i.e. transmitter (sender) and receiver.

For example, I want to send an 8-bit binary data 11001110 from the
transmitter to the receiver. But, which bit goes out first? Most Significant
Bit – MSB (7th bit) or Least Significant Bit- LSB (0th Bit). We cannot
say. Here I am considering LSB is moving first (for little Endian).
Serial Communication
From the above diagram, for every clock pulse; the transmitter sends a
single bit of data to the receiver.

14. (b) Interrupt structure and priority


Types-2m
Interrupts are basically the events that temporarily suspend the main program,
pass the control to the external sources and execute their task. It then passes the
control to the main program where it had left off. Priority
Table-4m
8051 has five interrupts. These interrupts are INT0, INT1,TO ,T1 , TI/RI. All of
the interrupts can be enabled or disabled by using the IE (interrupt enable) Explanati
register. on-7m
The interrupt addresses of these interrupts are like below:

Interrupt Address

INT0 0003H

INT1 000BH

T0 0013H

T1 001BH
TI/RI 0023H

Interrupt Enable (IE)Register

This register can be used to enable or disable interrupts programmatically. This


register is an SFR. The address is A8H. This byte is bit addressable. So it can be
programmed by the user. The bits in this register has a different meaning. The
register structure is looking like this:

BitAdd AF AE AD AC AB AA A9 A8
ress

Bit EA X X ES ET1 EX1 ET0 EX0


Details

Now, let us see the bit details and different operations when the value is low (0)
and high(1).

Bit High Value(1) Low Value(0)


Detail
s

EA Least significant 5 Disable all five interrupts.


bits can decide It just ignores the rest five bits.
enable or disable
of these five
interrupts.

ES Enable Serial Port Disable Serial Port Interrupt


Interrupt

ET1 Enable Timer1 Disable Timer1 interrupt


interrupt

EX1 Enable external Disable external interrupt 1 (INT1)


interrupt 1 (INT1)

ET0 Enable Timer0 Disable Timer0 interrupt


interrupt

EX0 Enable external Disable external interrupt 0 (INT0)


interrupt 0 (INT0)

Interrupt Priority (IP) Register

All of these five interrupts can be in one or two interrupt level. The priority
levels are level 1 and level 0. Priority level 1 indicates the higher priority, and
level 0 indicates lower priority. This IP register can be used to store the priority
levels for each interrupt. This is also a bit addressable SFR. Its address is B8H.

Now, let us see the bit details and different operations when the value is low (0)
and high(1).

Bit High Value(1) Low Value(0)


Detail
s

PS Set 1 level priority of Set 0 level priority of Serial port


Serial port interrupt interrupt

PT1 Set 1 level priority of Set 0 level priority of Timer1


Timer1 interrupt interrupt

PX1 Set 1 level priority of Set 0 level priority of external


external interrupt 1 interrupt 1 (INT1)
(INT1)

PT0 Set 1 level priority of Set 0 level priority of Timer0


Timer0 interrupt interrupt
PX0 Set 1 level priority of Set 0 level priority of external
external interrupt 0 interrupt 0 (INT0)
(INT0)

When all of the five interrupts are in same priority level, and if all of the
interrupts are enabled, then the sequence of interrupts will be INT0, T0, INT1,
T1, TI/R I.
Some specific priority register value can be used to maintain the priorities of the
interrupts. Let the value of Priority register is xxx00101 indicates the
sequence INT0, INT1, TI/RI, T1, T0. But all of the sequences are not feasible.
Like INT0, INT1, TI/RI, T1, T0 is not valid.

External Interrupt

The external interrupts of 8051 are INT0and. INT1 These interrupts can be
programmed to either edge-triggered or level triggered. The TCON register can
be used top rogram external interrupts to edge or level triggered. The TCON
isTimer Control. TCON is another bit addressable SFR. Here the address is
88H.

BitAddress 8F 8E 8D 8C 8B 8A 89 88

Bit Details TF TR TF TR0 IE1 IT1 IE0 IT0


1 1 0

Now, let us see the bit details and different operations when the value is low (0)
and high(1).

Bit High Low Value(0)


Details Value(1)

IT0 Set ( INT0) Set ( INT0) as active low level triggered input.
as negative
edge
triggeredin
put.
IT1 Set ( INT1) Set ( INT1) as active low level triggered input.
as negative
edge
triggeredin
put.

IE0 This will be This will be 0, when INT0is activated as edge


1, triggered.
when INT0
is activated
as level
triggered.

IE1 This will be This will be 0, when INT1 is activated as edge


1, triggered.
when INT1
is activated
as level
triggered.

TR0 Set Timer0 Set Timer0 as stop mode.


as run
mode

TR1 Set Timer1 Set Timer1 as stop mode.


as run
mode

TF0 High when After resetting the timer T0 thiswill also be


Timer T0 changed to 0 state
overflow
occurs.

TF1 High when After resetting the timer T1 this will also be
Timer T1 changed to 0 state.
overflow
occurs.
The IT0 and IT1 are stands for Interrupt Type. These bits are used to decide
whether the INT0 and INT1 will be level trigged or edge triggered.
IE0 and IE1 bits are used to indicate the status of external interrupts. These bit
can be set or reset by the microcontroller itself.
The first four bits are the status information about timers. When TR0 and TR1
are 1, it indicates the running mode of the timers. These bits provide software
control over the running of timers. Timers can also be controlled by the
hardware. The priority of hardware mode is higher than the software mode.
The TF0 and TF1 are used to indicate the overflow of timer T0 and T1
respectively. When over flow occurs these flags are set to 1. When the interrupt
is handled by some interrupt service subroutine (ISS), these will be 0.

Serial Port Interrupt

The serial ports can be used either Transmitting mode or reception mode. The
interrupt status for the Transmission is provided by TI, and status for Reception
is provided by RI. These are two bits of SCON(Serial Control). This is also a bit
addressable SFR. The address is98H

BitAddress 9F 9E 9D 9C 9B 9A 99 9
8

Bit Details SM0 SM1 SM2 REN TB8 RB8 TI R


I

The significance of these bits are as follows

Bit Description
Details

SM0 This is Serial Port Mode 0 shift register

SM1 This is Serial Port Mode 1 (8-bit UAR + variable)

SM2 Enable multiprocessor communication in the mode 2 or 3


REN Set or reset by the software to enable or disable the Reception

TB8 It indicates the 9th bit that will be transmitted in mode 2 or 3. It can be set or reset
by the software

RB8 In mode 2 or 3, the 9th bit was received in mode 1.

TI The transmission interrupt flag. It can be set by hardware.

RI The receiver interrupt flag. It can be set by hardware but must be reset by software.

The interrupt control system of 8051 is like below:

Interrupt Priorities

The 8051 offers two levels of interrupt priority: high and low. By using interrupt
priorities you may assign higher priority to certain interrupt conditions.

For example, you may have enabled Timer 1 Interrupt which is automatically
called every time Timer 1 overflows. Additionally, you may have enabled the
Serial Interrupt which is called every time a character is received via the serial
port. However, you may consider that receiving a character is much more
important than the timer interrupt. In this case, if Timer 1 Interrupt is already
executing you may wish that the serial interrupt itself interrupts the Timer 1
Interrupt. When the serial interrupt is complete, control passes back to Timer 1
Interrupt and finally back to the main program. You may accomplish this by
assigning a high priority to the Serial Interrupt and a low priority to the Timer 1
Interrupt
15. (a) KEYPAD INTERFACE

Keypads are widely used input devices being used in various electronics and
embedded projects. They are used to take inputs in the form of numbers and
albhabets, and feed the same into system for further processing. In this tutorial
we are going to interface a 4x4 matrix keypad with 8051 microcontroller.
Diagram-4m
4X4 Matrix Keypad
Explanation
Before we interface the keypad with microcontroller, first we need to understand -5m
how it works. Matrix keypad consists of set of Push buttons, which are
interconnected. Like in our case we are using 4X4 matrix keypad, in which there Program-4m
are 4 push buttons in each of four rows. And the terminals of the push buttons
are connected according to diagram. In first row, one terminal of all the 4 push
buttons are connected together and another terminal of 4 push buttons are
representing each of 4 columns, same goes for each row. So we are getting 8
terminals to connect with a microcontroller.

Interfacing keypad with 8051 microcontroller (AT89S52)


First we need to interface a LCD module to display the data which will be feed
through KEYPAD, so please go through “LCD Interfacing with 8051
Microcontroller” article before interfacing KEYPAD.

As shown in above circuit diagram, to interface Keypad, we need to connect 8


terminals of the keypad to any port (8 pins) of the microcontroller. Like we have
connected keypad terminals to Port 1 of 8051. Whenever any button is pressed
we need to get the location of the button, means the corresponding ROW an
COLUMN no. Once we get the location of the button, we can print the character
accordingly.

Now the question is how to get the location of the pressed button? I am going to
explain this in below steps and also want you to look at the code:
1. First we have made all the Rows to Logic level 0 and all the columns to Logic
level 1.
2. Whenever we press a button, column and row corresponding to that button
gets shorted and makes the corresponding column to logic level 0. Because that
column becomes connected (shorted) to the row, which is at Logic level 0. So
we get the column no. See main() function.

3. Now we need to find the Row no., so we have created four functions
corresponding to each column. Like if any button of column one is pressed, we
call function row_finder1(), to find the row no.
4. In row_finder1() function, we reversed the logic levels, means now all the
Rows are 1 and columns are 0. Now Row of the pressed button should be 0
because it has become connected (shorted) to the column whose button is
pressed, and all the columns are at 0 logic. So we have scanned all rows for 0.

5. So whenever we find the Row at logic 0, means that is the row of pressed
button. So now we have column no (got in step 2) and row no., and we can print
no. of that button using lcd_data function.

15. (b) PIC16C6X


PIC16CXX microcontrollers typically achieve a 2:1 code compression and a 4:1
speed improvement over other 8-bit microcontrollers in their class. Diagram-6m
Explanation
ARCHITECTURAL OVERVIEW The high performance of the PIC16CXX -7m
family can be attributed to a number of architectural features commonly found
in RISC microprocessors. To begin with, the PIC16CXX uses a Harvard
architecture, in which, program and data are accessed from separate memories
using separate buses. This improves bandwidth over traditional von Neumann
architecture where program and data may be fetched from the same memory
using the same bus. Separating program and data busses further allows
instructions to be sized differently than 8-bit wide data words. Instruction
opcodes are 14-bits wide making it possible to have all single word instructions.
A 14-bit wide program memory access bus fetches a 14-bit instruction in a
single cycle. A twostage pipeline overlaps fetch and execution of instructions
(Example 3-1). Consequently, all instructions execute in a single cycle (200 ns
@ 20 MHz) except for program branches. The PIC16C61 addresses 1K x 14 of
program memory. The PIC16C62/62A/R62/64/64A/R64 address 2K x 14 of
program memory, and the PIC16C63/R63/65/65A/R65 devices address 4K x 14
of program memory. The PIC16C66/67 address 8K x 14 program memory. All
program memory is internal. The PIC16CXX can directly or indirectly address
its register files or data memory. All special function registers including the
program counter are mapped in the data memory. The PIC16CXX has an
orthogonal (symmetrical) instruction set that makes it possible to carry out any
operation on any register using any addressing mode. This symmetrical nature
and lack of “special optimal situations” makes programming with the
PIC16CXX simple yet efficient, thus significantly reducing the learning curve.
The PIC16CXX device contains an 8-bit ALU and working register (W). The
ALU is a general purpose arithmetic unit. It performs arithmetic and Boolean
functions between data in the working register and any register file. The ALU is
8-bits wide and capable of addition, subtraction, shift, and logical operations.
Unless otherwise mentioned, arithmetic operations are two's complement in
nature. In two-operand instructions, typically one operand is the working
register (W register), the other operand is a file register or an immediate
constant. In single operand instructions, the operand is either the W register or a
file register. The W register is an 8-bit working register used for ALU
operations. It is not an addressable register. Depending upon the instruction
executed, the ALU may affect the values of the Carry (C), Digit Carry (DC),
and Zero (Z) bits in the STATUS register. Bits C and DC operate as a borrow
and digit borrow out bit, respectively, in subtraction. See the SUBLW and
SUBWF instructions for examples.

PIC16C7X
The PIC16C710/71 devices have 36 bytes of RAM, and the PIC16C711 has 68
bytes of RAM. The PIC16C710/71/711 devices have 13 I/O pins. In addition a
timer/counter is available. Also a 4-channel highspeed 8-bit A/D is provided.
The 8-bit resolution is ideally suited for applications requiring low-cost analog
interface, e.g. thermostat control, pressure sensing, etc. The PIC16C72 device
has 128 bytes of RAM and 22 I/O pins. In addition several peripheral features
are available including: three timer/counters, one Capture/Compare/PWM
module and one serial port. The Synchronous Serial Port can be configured as
either a 3-wire Serial Peripheral Interface (SPI) or the two-wire Inter-Integrated
Circuit (I2C) bus. Also a 5-channel high-speed 8-bit A/D is provided. The 8-bit
resolution is ideally suited for applications requiring low-cost analog interface,
e.g. thermostat control, pressure sensing, etc.

ARCHITECTURAL OVERVIEW The high performance of the PIC16CXX


family can be attributed to a number of architectural features commonly found
in RISC microprocessors. To begin with, the PIC16CXX uses a Harvard
architecture, in which, program and data are accessed from separate memories
using separate buses. This improves bandwidth over traditional von Neumann
architecture in which program and data are fetched from the same memory using
the same bus. Separating program and data buses further allows instructions to
be sized differently than the 8-bit wide data word. Instruction opcodes are 14-
bits wide making it possible to have all single word instructions. A 14-bit wide
program memory access bus fetches a 14-bit instruction in a single cycle. A
twostage pipeline overlaps fetch and execution of instructions (Example 3-1).
Consequently, all instructions (35) execute in a single cycle (200 ns @ 20 MHz)
except for program branches. The table below lists program memory (EPROM)
and data memory (RAM) for each PIC16C7X device. The PIC16CXX can
directly or indirectly address its register files or data memory. All special
function registers, including the program counter, are mapped in the data
memory. The PIC16CXX has an orthogonal (symmetrical) instruction set that
makes it possible to carry out any operation on any register using any addressing
mode. This symmetrical nature and lack of ‘special optimal situations’ make
programming with the PIC16CXX simple yet efficient. In addition, the learning
curve is reduced significantly.
16. (a)

ORG 000H
Program-
Avoid using memory space 13m
LJMP MAIN
allocated

ORG 0023H
JNB T1,SKIP If T1 is low, goto SKIP
MOV SBUF,A Transfer data seriously
CLR T1 Clear T1
RET T1 Return to main program
SKIP CLR R1 Clear R1
RET T Return to main program
ORG 1001H
MAIN MOV P2,
Configure P2 as an input port
OFF H
MOV TMOD,
Initialize time in mode 2
#20H
Load count to get 96000 bud
MOV TH1, #FDH
rate
MOV SCON,
Select Serial Mode
#40H
MOV 1E,
Enable Serial Interrupt
#10010000B
SET B, TR1 Start Timer1
MOV A,P1 Read data from Port1
MOV SBUF, A Sent the first byte serial
BACK MOV
Read data from port1
A,P1
MOV P2, A Send it to Port 2
SJMP BACK Repeat
END

16. (b)
MOV TMOD #20H timer1 mode2
MOV TH 1, # -3 9600 buad ra
MOV SCON, #50H Program-
SETB TR1, H 13m
AGAIN MOV A, # “H” transfer H
A CALL TRANS
MOV A, # “E” transfer E
A CALL TRANS
MOV A, # “L” transfer L
A CALL TRANS
MOV A, # “L” transfer L
A CALL TRANS
MOV A, # “O” transfer O
A CALL TRANS
BitAddress BF BE BD BC BB BA B9 B8

Bit Details X X X PS PT1 PX1 PT0 PX0

MOV A, # “W” transfer W


A CALL TRANS
MOV A, # “O” transfer O
A CALL TRANS
A CALL TRANS transfer R
MOV A, # “R”
A CALL TRANS transfer L
MOV A, # “L”
A CALL TRANS transfer D
MOV A, # “D”
SJMP AGAIN Keep doing it

Serial Data Transfer Subroutine


TRANS: MOV SBUF,
Load SBUF
A
HERE: JNB T1, HERE Wait for last bit to transfer
CLR T1 Clear T1
RET Get ready for next byte

You might also like