Академический Документы
Профессиональный Документы
Культура Документы
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
PSW 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.
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:
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.
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
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.
Interrupts
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
BUS
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
Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to carry
data of particular applications.
Oscillator
Input/Output Port
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.
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.
JMP Non
0x73 1
@A+DPTR e
JZ Jump if Accumulator A = 0
CJNE
Compare and Jump if Accumulator A ≠ #data
reg,#data
Example # 1:
MOV A,R0 ;A = R0
MOV A,R1 ;A = R1
.........
OVER:
Example # 2:
Answer:
NEXT: ..........
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.
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].
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.
Interrupt Address
INT0 0003H
INT1 000BH
T0 0013H
T1 001BH
TI/RI 0023H
BitAdd AF AE AD AC AB AA A9 A8
ress
Now, let us see the bit details and different operations when the value is low (0)
and high(1).
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).
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
Now, let us see the bit details and different operations when the value is low (0)
and high(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.
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.
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 Description
Details
TB8 It indicates the 9th bit that will be transmitted in mode 2 or 3. It can be set or reset
by the software
RI The receiver interrupt flag. It can be set by hardware but must be reset by software.
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.
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.
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.
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