MPMC Unit 5 Notes
MPMC Unit 5 Notes
Unit-5
by
M.Ramanjaneyulu
Associte professor
Department of ECE
The 8051 microcontroller has FIVE interrupts in addition to Reset. They are
Each interrupt has a specific place in code memory where program execution (interrupt service
routine) begins.
Upon reset all Interrupts are disabled & do not respond to the Microcontroller. These
interrupts must be enabled by software in order for the Microcontroller to respond to them. This
is done by an 8-bit register called Interrupt Enable 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.
EA : Global enable/disable. To enable the interrupts this bit must be set High.
Upon reset the interrupts have the following priority.(Top to down). The interrupt with the
highest PRIORITY gets serviced first.
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.7: reserved
IP.6: reserved
It is not possible to for seen when an interrupt request will arrive. If several interrupts are
enabled, it may happen that while one of them is in progress, another one is requested. In order
that the microcontroller knows whether to continue operation or meet a new interrupt request,
there is a priority list instructing it what to do.
1. Reset. When a reset request arrives, everything is stopped and the Microcontroller restarts.
2. Interrupt priority 1 can be disabled by Reset only.
3. Interrupt priority 0 can be disabled by both Reset and interrupt priority 1.
The IP Register (Interrupt Priority Register) specifies which one of existing interrupt sources
have higher and which one has lower priority. Interrupt priority is usually specified at the
beginning of the program. According to that, there are several possibilities:
4. These addresses store appropriate subroutines processing interrupts. Instead of them, there
are usually jump instructions specifying locations on which these subroutines reside.
5. When an interrupt routine is executed, the address of the next instruction to execute is
poped from the stack to the program counter and interrupted program resumes operation from
where it left off.
Program1.Write ALP 8051 to (a) Enable the serial interrupt, Timer 0 interrupt, and external
hardware interrupt1 (b) Disable the Timer 0 interrupt (c) disable all interrupts
(a)
B7 B6 B5 B4 B3 B2 B1 B0
1 0 0 1 0 1 1 0
=96
1) MOV IE,#10010110B
2) MOV IE,#96H
3) SETB IE.7
SETB IE.4
M Ramanjaneyulu, ECE, MRCET Page 5
MPMC Unit-5 Notes
SETB IE.2
SETB IE.1
b) CLR IE.1
c) CLR IE.7
TIMERS in 8051 Microcontrollers: The 8051 microcontroller has two 16-bit timers
Timer 0 (T0) and Timer 1(T1) which can be used either to generate accurate time delays or as
event counters. These timers are accessed as two 8-bit registers TLO, THO & TL1,TH1
because the 8051 microcontroller has 8-bit architecture.
TIMER 0 : The Timer 0 is a 16-bit register and can be treated as two 8-bit registers (TL0 &
TH0) and these registers can be accessed similar to any other registers like A,B or R1,R2,R3
etc…
TIMER 1 : The Timer 1 is also a 16-bit register and can be treated as two 8-bit registers (TL1
& TH1) and these registers can be accessed similar to any other registers like A,B or R1,R2,R3
etc…
TMOD Register: The various operating modes of both the timers T0 and T1 are set by an 8-bit
register called TMOD register. In this TMOD register the lower 4-bits are meant for Timer 0 and
the higher 4-bits are meant for Timer1.
GATE: This bit is used to start or stop the timers by hardware .When GATE= 1 ,the timers can
be started / stopped by the external sources. When GATE= 0, the timers can be started or stopped
by software instructions like SETB TR0 or SETB TR1
C/T (clock/Timer): This bit decides whether the timer is used as delay generator or event
counter. When C/T = 0 , the Timer is used as delay generator and if C/T=1 the timer is used as
an event counter. The clock source for the time delay is the crystal frequency of 8051.
M1, M0 (Mode) : These two bits are the timer mode bits. The timers of the 8051 can be
configured in three modes.Mode0, Mode1 and Mode2. The selection and operation of the modes
is shown below.
Modes of 8051 Timer/Counter: The 8051 microcontroller provides four different modes of
operation, and a programmer can decide which mode to use according to their needs.
Mode 1:- It is a 16-bit timer; therefore it allows values from 0000 to FFFFH to be loaded into
the timer’s registers TL and TH. After TH and TL are loaded with a 16-bit initial value, the timer
must be started.
We can do it by “SETB TR0” for timer 0 and “SETB TR1” for timer 1. After the timer is started.
It starts count up until it reaches its limit of FFFFH. When it rolls over from FFFF to 0000H, it
sets high a flag bit called TF (timer flag). This timer flag can be monitored. When this timer flag
is raised, one option would be stop the timer with the instructions “CLR TR0“ or CLR TR1 for
timer 0 and timer 1 respectively. Again, it must be noted that each timer flag TF0 for timer 0 and
TF1 for timer1. After the timer reaches its limit and rolls over, in order to repeat the process the
registers TH and TL must be reloaded with the original value and TF must be reset to 0.
Mode0:- Mode 0 is exactly same like mode 1 except that it is a 13-bit timer instead of 16-bit.
The 13-bit counter can hold values between 0000 to 1FFFH in TH-TL. Therefore, when the
timer reaches its maximum of 1FFH, it rolls over to 0000, and TF is raised.
Mode 2:- It is an 8 bit timer that allows only values of 00 to FFH to be loaded into the timer’s
register TH. After TH is loaded with 8 bit value,the 8051 gives a copy of it to TL. Then the timer
must be started. It is done by the instruction “SETB TR0” for timer 0 and “SETB TR1” for
timer1. This is like mode 1. After timer is started, it starts to count up by incrementing the TL
register. It counts up until it reaches its limit of FFH. When it rolls over from FFH to 00. It sets
high the TF (timer flag). If we are using timer 0, TF0 goes high; if using TF1 then TF1 is
raised. When Tl register rolls from FFH to 00 and TF is set to 1, TL is reloaded automatically
with the original value kept by the TH register. To repeat the process, we must simply clear TF
and let it go without any need by the programmer to reload the original value. This makes mode
2 auto reload, in contrast in mode 1 in which programmer has to reload TH and TL.
Mode3:- Mode 3 is also known as a split timer mode. Timer 0 and 1 may be programmed to be
in mode 0, 1 and 2 independently of similar mode for other timer. This is not true for mode 3;
timers do not operate independently if mode 3 is chosen for timer 0. Placing timer 1 in mode 3
causes it to stop counting; the control bit TR1 and the timer 1 flag TF1 are then used by timer0.
TCON register:- Bits and symbol and functions of every bits of TCON are as follows:
7 TF1 Timer1 over flow flag. Set when timer rolls from all 1s to 0. Cleared
When the processor vectors to execute interrupt service routine
Located at program address 001Bh.
Program2. Write 8051 program to initialize timer0 in mode2 and timer1 in mode1 and start
both timers. Reset timer0 on overflow
TMOD: =12H
Timer1 Timer 0
0 0 0 1 0 0 1 0
Program :
ORG 0000H
SELF:JNB TF0 SELF ;Self loop to check the timer0 over flow flag
END
Program3.Write 8051 ALP to generate a 5KHz square wave on P1.5 using timer0
Assumptions :
TMOD: =01H
Timer1 Timer 0
0 0 0 0 0 0 0 1
Algorithm :
TL0=38H,TH0=FF
Program:
ORG 0000H
SJMP BACK
Assumptions :
• Initilize TL0 and TH0 such that delay of 50msec=50000 usec is achieved by running
timer0
Algorithm:
1. Timer0 is used as Timer in mode 1 as Timer and Timer1 used as counter in mode
0,so load TMOD accordingly.
2. Timer1 Timer 0
0 1 0 0 0 0 0 1
=41H
12. Decrement delay repitation count ,if it is not zero go back to Step7
DJNZ R2,GOBACK
END
SBUF: Serial Buffer Register: This is the serial communication data register used to transmit or
receive data through it.
The serial port buffer (SBUF) at address 99H is really two buffers.
Writing to SBUF loads data to be transmitted, and reading SBUF accesses received data.
These are two separate and distinct registers, the transmit write-only register, and the
receive read-only register
There are two separate data lines, one for transmission (TXD) and one for reception
(RXD).
The Serial Control or SCON is used to control the 8051 Microcontroller’s Serial Port.
It is located as an address of 98H.
Using SCON, you can control the Operation Modes of the Serial Port, Baud Rate of the
Serial Port and Send or Receive Data using Serial Port.
SCON Register also consists of bits that are automatically SET when a byte of data is
transmitted or received.
Mode 0:
• In this mode, the serial port works like a shift register and the data transmission works
synchronously with a clock frequency of fosc /12.
• Serial data is received and transmitted through RXD.
• 8 bits are transmitted/ received at a time.
• Pin TXD outputs the shift clock pulses of frequency fosc /12, which is connected to the
external circuitry for synchronization.
• The shift frequency or baud rate is always 1/12 of the oscillator frequency.
Mode 1
• The 10 bits consist of one start bit (which is usually '0'), 8 data bits (LSB is sent
first/received first), and a stop bit (which is usually '1').
• Once received, the stop bit goes into RB8 in the special function register SCON.
• The baud rate is variable.
Mode 2
• In this mode 11 bits are transmitted through TXD or received through RXD.
• The various bits are as follows: a start bit (usually '0'), 8 data bits (LSB first), a
programmable 9th (TB8 or RB8)bit and a stop bit (usually '1').
• While transmitting, the 9th data bit (TB8 in SCON) can be assigned the value '0' or '1'.
• The baud rate is programmable to either 1/32 or 1/64 of the oscillator frequency.
• f baud = (2SMOD /64) fosc.
Mode 3
• In this mode 11 bits are transmitted through TXD or received through RXD.
• The various bits are: a start bit (usually '0'), 8 data bits (LSB first), a programmable 9th
bit and a stop bit (usually '1').
• Mode-3 is same as mode-2, except the fact that the baud rate in mode-3 is variable (i.e.,
just as in mode-1).
• f baud = (2 SMOD /32) * ( fosc / 12 (256-TH1)) .
• This baud rate holds when Timer-1 is programmed in Mode-2.
The PCON or Power Control register is used to control the 8051 Microcontroller’s Power
Modes and is located at 87H of the SFR Memory Space.
Using two bits in the PCON Register, the microcontroller can be set to Idle Mode and
Power Down Mode.
During Idle Mode, the Microcontroller will stop the Clock Signal to the ALU (CPU) but
it is given to other peripherals like Timer, Serial, Interrupts, etc.
In order to terminate the Idle Mode, you have to use an Interrupt or Hardware Reset.
In the Power Down Mode, the oscillator will be stopped and the power will be reduced to
2V.
To terminate the Power Down Mode, you have to use the Hardware Reset.
The SMOD Bit in the PCON Register is used to control the Baud Rate of the Serial Port.
There are two general purpose Flag Bits in the PCON Register, which can be used by the
programmer during execution.
TI (transfer interrupt) is raised when the last bit of the framed data, the stop bit, is
transferred, indicating that the SBUF register is ready to transfer the next byte.
RI (received interrupt), is raised when the entire frame of data, including the stop bit, is
received.
In the interrupt method, we are notified when the 8051 has received a byte, or is ready to
send the next byte
In the 8051 only one interrupt is set aside for serial communication.
If the interrupt bit in the IE register (IE.4) is enabled, when RI or TI is raised the 8051
gets interrupted and jumps to memory address location 0023H to execute the ISR.
M Ramanjaneyulu, ECE, MRCET Page 18
MPMC Unit-5 Notes
In that ISR we must examine the TI and RI flags to see which one caused the interrupt
and respond accordingly.
Program1: Write 8051 ALP to program to operate serial port at 2400 bauds using timer1
• 8051 uses Timer1 T1 for Generating the Baud rate for Serial Transmission.
• The Timer1 is operated in mode2 (Auto Reload Mode)
As we know that 8051 microcontrollers takes 12 clock cycles to complete one machine
cycle.
=> 921.6KHz.
8051 UART or serial communication block further divide this frequency (921.6 KHz) by 32
to generate its baud rate.
The Effective frequency available to generate Baud rates is 921.6 KHz/32 = 28800 Hz.
TMOD: 20H
Timer1 Timer 0
GATE C/T M1 M0 GATE C/T M1 M0
0 0 1 0 0 0 0 0
Program :
ORG 0000H
MOV TMOD,#20H
MOV TH1,0F4H
SETB TR1
END
Program2.Write 8051 ALP to transmit 8-bit character serially at 9600 bauds continuously
0 1 0 0 0 0 0 0
• 8051 uses Timer1 T1 for Generating the Baud rate for Serial Transmission.
Program:
SJMP CONTINUE
ARM architecture
Introduction:
The ARM microcontroller stands for Advance RISC Machine; it is one of the extensive and
most licensed processor cores in the world. The first ARM processor was developed in the year
1978 by Cambridge University, and the first ARM RISC processor was produced by the Acorn
Group of Computers in the year 1985. These processors are specifically used in portable devices
like digital cameras, mobile phones, home networking modules and wireless communication
technologies and other embedded systems due to the benefits, such as low power consumption,
reasonable performance, etc.
The ARM architecture processor is an advanced reduced instruction set computing [RISC]
machine and it’s a 32-bit reduced instruction set computer (RISC) microcontroller. This ARM is
a family of microcontroller developed by makers like ST Microelectronics, Motorola, and so on.
The ARM architecture comes with totally different versions like ARMv1, ARMv2, etc., and,
ARM Architecture:
Data enters the processor core through the Data bus. The data may be an instruction to
execute or a data item. Figure shows a Von Neumann implementation of the ARM—data items
and instructions share the same bus. In contrast, Harvard implementations of the ARM use two
different buses.
The instruction decoder translates instructions before they are executed. Each instruction
executed belongs to a particular instruction set. The ARM processor, like all RISC processors,
uses a load-store architecture. This means it has two instruction types for transferring data in and
out of the processor: load instructions copy data from memory to registers in the core, and
conversely the store instructions copy data from registers to memory. There are no data
processing instructions that directly manipulate data in memory. Thus, data processing is carried
out solely in registers.
Data items are placed in the register file—a storage bank made up of 32-bit registers. Since
the ARM core is a 32-bit processor, most instructions treat the registers as holding signed or
unsigned 32-bit values. The sign extend hardware converts signed 8-bit and 16-bit numbers to 32-bit
values as they are read from memory and placed in a register.
ARM instructions typically have two source registers, Rn and Rm, and a single result or
destination register, Rd. Source operands are read from the register file using the internal buses A
and B, respectively.
The ALU (arithmetic logic unit) or MAC (multiply-accumulate unit) takes the register values
Rn and Rm from the A and B buses and computes a result. Data processing instructions write the
result in Rd directly to the register file. Load and store instructions use the ALU to generate an
address to be held in the address register and broadcast on the Address bus.
One important feature of the ARM is that register Rm alternatively can be preprocessed in
the barrel shifter before it enters the ALU. Together the barrel shifter and ALU can calculate a wide
range of expressions and addresses.
After passing through the functional units, the result in Rd is written back to the register file
using the Result bus. For load and store instructions the incrementer updates the address register
before the core reads or writes the next register value from or to the next sequential memory location.
The processor continues executing instructions until an exception or interrupt changes the normal
execution flow.
The ALU has two 32-bits inputs. The primary comes from the register file, whereas the other
comes from the shifter. Status registers flags modified by the ALU outputs. The V-bit output
goes to the V flag as well as the Count goes to the C flag. Whereas the foremost significant bit
really represents the S flag, the ALU output operation is done by NORed to get the Z
flag. The ALU has a 4-bit function bus that permits up to 16 opcode to be implemented.
Barrel Shifter:
The barrel shifter features a 32-bit input to be shifted. This input is coming back from the
register file or it might be immediate data. The shifter has different control inputs coming back
from the instruction register. The Shift field within the instruction controls the operation of the
barrel shifter. This field indicates the kind of shift to be performed (logical left or right,
arithmetic right or rotate right). The quantity by which the register ought to be shifted is
contained in an immediate field within the instruction or it might be the lower 6 bits of a register
within the register file.
The shift_val input bus is 6-bits, permitting up to 32 bit shift. The shift type indicates the needed
shift sort of 00, 01, 10, 11 are corresponding to shift left, shift right, an arithmetic shift right and
rotate right, respectively. The barrel shifter is especially created with multiplexers.
Control Unit:
For any microprocessor, control unit is the heart of the whole process and it is responsible for the
system operation, so the control unit design is the most important part within the whole design.
The control unit is sometimes a pure combinational circuit design. Here, the control unit is
implemented by easy state machine. The processor timing is additionally included within the
control unit. Signals from the control unit are connected to each component within the processor
to supervise its operation.
An ARM Microcontroller is a load store reducing instruction set computer architecture means
the core cannot directly operate with the memory. The data operations must be done by the
registers and the information is stored in the memory by an address. The ARM consists of 37
register sets wherein 31 are general purpose registers and 6 are status registers. The ARM uses
seven processing modes to run the user task.
USER Mode
FIQ Mode
IRQ Mode
SVC Mode
UNDEFINED Mode
ABORT Mode
Monitor Mode
USER Mode: The user mode is a normal mode, which has the least number of registers. It
doesn’t have SPSR and has limited access to the CPSR.
FIQ and IRQ: The FIQ and IRQ are the two interrupt caused modes of the CPU. The FIQ is
processing interrupt and IRQ is standard interrupt. The FIQ mode has additional five banked
registers to provide more flexibility and high performance when critical interrupts are handled.
SVC Mode: The Supervisor mode is the software interrupt mode of the processor to start up or
reset.
Undefined Mode: The Undefined mode traps when illegal instructions are executed. The ARM
core consists of 32-bit data bus and faster data flow.
Some of the registers are reserved in each mode for the specific use of the core. The reserved
registers are
The reserved registers are used for specific functions. The SPSR and CPSR contain the status
control bits which are used to store the temporary data. The SPSR and CPSR register have some
properties that are defined operating modes, Interrupt enable or disable flags and ALU status
flag. The ARM core operates in two states 32-bit state or THUMBS state.
Pipeline: The Process of fetching the next instruction while the current instruction is being
executed is called as “pipelining”. Pipelining is supported by the processor to increase the speed
of program execution. Increases throughput. Several operations take place simultaneously,
rather than serially in pipelining.
A pipeline is the mechanism of a RISC processor uses to execute instructions. Using a pipeline
speeds up execution by fetching the next instruction while other instructions are being decoded
and executed. One way to view the pipeline is to think of it as an automobile assembly line, with
each stage carrying out a particular task to manufacture the vehicle.
As the pipeline length increases, the amount of work done at each stage is reduced, which
allows the processor to attain a higher operating frequency. This in turn increases the
performance. The system latency also increases because it takes more cycles to fill the pipeline
before the core can execute an instruction. The increased pipeline length also means there can be
data dependency between certain stages. You can write code to reduce this dependency by using
instruction scheduling
The pipeline design for each ARM family differs. For example, The ARM9 core
increases the pipeline length to five stages, as shown in Figure 2.9. The ARM9 adds a memory
and write back stage, which allows the ARM9 to process on average 1.1 Dhrystone MIPS per
MHz—an increase in instruction throughput by around 13% compared with an ARM7.The
maximum core frequency attainable using an ARM9 is also higher.
The ARM10 increases the pipeline length still further by adding a sixth stage, as shown
in Figure 2.10. The ARM10 can process on average 1.3 Dhrystone MIPS per MHz, about 34%
more throughput than an ARM7 processor core, but again at a higher latency cost. Even though
the ARM9 and ARM10 pipelines are different, they still use the same pipeline executing
characteristics as an ARM7. Code written for the ARM7 will execute on an ARM9 or ARM10.