MC5
MC5
UNIT 5
Introduction
A microcontroller is a computer with most of the necessary support chips onboard. All computers have
several things in common, namely: . A central processing unit (CPU) that ‘executes’ programs. . Some
random-access memory (RAM) where it can store data that is variable. Some read only memory (ROM)
where programs to be executed can be stored. . Input and output (I/O) devices that enable
communication to be established with the outside world i.e. connection to devices such as keyboard,
mouse, monitors and other peripherals. There are a number of other common characteristics that define
microcontrollers. If a computer matches a majority of these characteristics, then it can be classified as a
‘microcontroller’. Microcontrollers may be: . ‘Embedded’ inside some other device (often a consumer
product) so that they can control the features or actions of the product. Another name for a
microcontroller is therefore an ‘embedded controller’. . Dedicated to one task and run one specific
program. The program is stored in ROM and generally does not change. A low-power device. A battery-
operated microcontroller might consume as little as 50 milliwatts. A microcontroller may take an input
from the device it is controlling and controls the device by sending signals to different components in the
device. A microcontroller is often small and low cost. The components may be chosen to minimise size and
to be as inexpensive as possible. The actual processor used to implement a microcontroller can vary
widely. In many products, such as microwave ovens, the demand on the CPU is fairly low and price is an
important consideration. In these cases, manufacturers turn to dedicated microcontroller chips – devices
that were originally designed to be low-cost, small, low-power, embedded CPUs. The Motorola 6811 and
Intel 8051 are both good examples of such chips. A typical low-end microcontroller chip might have 1000
bytes of ROM and 20 bytes of RAM on the chip, along with eight I/O pins. In large quantities, the cost of
these chips can sometimes be just a few pence.
MICROPROCESSOR MICROCONTROLLER
1.the functional blocks of a microprocessor are 1.the microcontroller includes the functional blocks
ALU,registers,timing and control unit. of microprocessor and in addition has timer,parallel
I/O port,serial I/O port,internalRAM and
EPROM/EEPROM memory.some controllers has
been ADC and/or DAC.
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
2.the microprocessor is concerned with the rapid 2.the microcontroller is concerned with the rapid
movement of code and data between external movement of code and data within microcontroller.
memory and microprocessor. Hence it has large Hence it has few instructions for data transfer
number of instructions for moving data between between external memory and microcontroller.
external memory and microprocessor.
3.the microprocessors mostly operate on byte/word 3.the microcontrollers often manipulate with bits
data and so has very few bit manipulating and has large number of bit manipulating
instructions. instructions.
4.the microprocessors usually require interfacing of 4.the microcontroller can be used to form a single
a large number of addition ICs to form an chip microcomputer based system without any
microcomputer based system. Hence the PCB of additional ICs. Hence the PCB of microcontroller
microprocessor based system will be large and so based system will be small and so system will be
the system will be costly. cheap.
5.the microprocessor are used for designing general 5.the microcontrollers are used for designing
purpose digital computing system(or computers). application specific dedicated systems.
The 8051 is a Harvard architecture, CISC instruction set, single chip microcontroller
(µC) series which was developed by Intel in 1980 for use in embedded systems.
Intel’s original MCS-51 family was developed using NMOS
technology, but later it is modified with CMOS technology and referred as 80C51which
consume less power than their NMOS predecessors and gives high switching speed than
NMOS technology. This made them more suitable for battery-powered devices.
Architecture of 8051
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
2. PC (Program Counter)
3. Registers
1. ALU
All arithmetic and logical functions are carried out by the ALU. Addition, subtraction with carry,
and multiplication come under arithmetic operations.Logical AND, OR and exclusive OR (XOR)
come under logical operations.
A program counter is a 16-bit register and it has no internal address. The basic function of program
counter is to fetch from memory the address of the next instruction to be executed. The PC
holds the address of the next instruction residing in memory and when a command is
encountered, it produces that instruction. This way the PC increments automatically, holding the
address of the next instruction.
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
3. Registers
Registers are usually known as data storage devices. 8051 microcontroller has 2 registers, namely
Register A and Register B. Register A serves as an accumulator while Register B functions as a
general purpose register. These registers are used to store the output of mathematical and logical
instructions. The operations of addition, subtraction, multiplication and division are carried out
by Register A. Register B is usually unused and comes into picture only when multiplication and
division functions are carried out by Register A. Register A also involved in data transfers
between the microcontroller and external memory.
8051 microcontroller also has 7 Special Function Registers (SFRs). They are:
Synchronization among internal operations can be achieved with the help of clock circuits which
are responsible for generating clock pulses. During each clock pulse a particular operation will
be carried out, thereby, assuring synchronization among operations. For the formation of an
oscillator, we are provided with two pins XTAL1 and XTAL2 which are used for connecting a
resonant network in 8051 microcontroller device. In addition to this, circuit also consists of four
more pins.
Internal operations can be synchronized using clock circuits which produce clock pulses. With each
clock pulse, a particular function will be accomplished and hence synchronization is achieved.
There are two pins XTAL1 and XTAL2 which form an oscillator circuit which connect to a
resonant network in the microcontroller. The circuit also has 4 additional pins -
4. RST: Reset
ROM
A code of 4K memory is incorporated as on-chip ROM in 8051. The 8051 ROM is a non-volatile
memory meaning that its contents cannot be altered and hence has a similar range of data and
program memory, i.e, they can address program memory as well as a 64K separate block of data
memory.
RAM
The 8051 microcontroller is composed of 128 bytes of internal RAM. This is a volatile memory
since its contents will be lost if power is switched off. These 128 bytes of internal RAM are
divided into 32 working registers which in turn constitute 4 register banks (Bank 0-Bank 3) with
each bank consisting of 8 registers (R0 - R7). There are 128 addressable bits in the internal
RAM.
PORT P0: When there is no external memory present, this port acts as a general purpose
input/output port. In the presence of external memory, it functions as a multiplexed address and
data bus. It performs a dual role.
PORT P1: This port is used for various interfacing activities. This 8-bit port is a normal I/O port
i.e. it does not perform dual functions.
PORT P2: Similar to PORT P0, this port can be used as a general purpose port when there is no
external memory but when external memory is present it works in conjunction with PORT PO as
an address bus. This is an 8-bit port and performs dual functions.
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
Data Transfer
Arithmetic
DIV AB Divides A by B
Logic Operations
Branch Instructions
Machine Control
CJNE Rn,#data rel Compare immed. to reg. and jump if not equal
DJNZ direct,rel Decrement direct byte and jump if not zero NOP
No operation
Addition of 8 bits
MOV A, #05H
MOV R, #09H
ADD A, R1
MOV @ DPTR, A
Subtraction of 8 bits
ORG 4100
CLR C
MOV A,#data1
SUBB A,#data2
MOV DPTR,#4500
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
MOVX @DPTR,A
Multiplication of 8 bits
ORG 4100
CLR C
MOV A,#data1
MOV B,#data2
MUL AB
MOV DPTR,#4500
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
Memory organization:
Register B
The major purpose of this register is in executing multiplication and division. The 8051 micro
controller has a single instruction for multiplication (MUL) and division (DIV). multiplication
is repeated addition, where as division is repeated subtraction. While programming 8085 a loop
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
Note: Register B can also be used for other general purpose operations.
Port Registers
4 Input/Output ports named P0, P1, P2 and P3 has got four corresponding port registers with
same name P0, P1, P2 and P3. Data must be written into port registers first to send it out to any
other external device through ports. Similarly any data received through ports must be read
from port registers for performing any operation. All 4 port registers are bit as well as byte
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
addressable.
mode when not used for a couple of seconds or minutes ? This is achieved by power
management feature of the controller used inside that phone.
As the name indicates, this register is used for efficient power management of 8051 micro
controller. Commonly referred to as PCON register, this is a dedicated SFR for power
management alone. From the figure below you can observe that there are 2 modes for this
register :- Idle mode and Power down mode.
Setting bit 0 will move the micro controller to Idle mode and Setting bit 1 will move the micro
controller to Power down mode.
Register
Bank LSB of the register bank select bit. Look for
3 RS0 D3 select bit 0 explanation below this table.
Register
Bank
4 RS1 D4 select bit 1 MSB of the register bank select bits.
Auxiliary This bit is set if data is coming out from bit 3 to bit 4
6 AC D6 carry of Acc during an Arithmetic operation.
At a time registers can take value from R0,R1…to R7. You may already know there are 32
such registers. There are 4 register banks named 0,1,2 and 3. Each bank has 8 registers named
from R0 to R7. At a time only one register bank can be selected. Selection of register bank is
made possible through PSW register bits PSW.3 and PSW.4, named as RS0 and RS1.These
two bits are known as register bank select bits as they are used to select register banks. The
picture will talk more about selecting register banks.
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
TCON 88 Timer control. Both bit addressing and byte addressing possible.
The opcode for MOV A, # data is 74H. The opcode is saved in program memory at 0202
address. The data 6AH is saved in program memory 0203. When the opcode 74H is read,
the next step taken would be to transfer whatever data at the next program memory
address (here at 0203) to accumulator A (E0H is the address of accumulator). This
instruction is of two bytes and is executed in one cycle. So after the execution of this
instruction, program counter will add 2 and move to o204 of program memory.
Note: The ‘#’ symbol before 6AH indicates that operand is a data (8 bit). If ‘#’ is not
present then the hexadecimal number would be taken as address.
MOV A, 04H
Here 04H is the address of register 4 of register bank#0. When this instruction is
executed, what ever data is stored in register 04H is moved to accumulator. In the picture
below we can see, register 04H holds the data 1FH. So the data 1FH is moved to
accumulator.
Note: We have not used ‘#’ in direct addressing mode, unlike immediate mode. If we had
used ‘#’, the data value 04H would have been transferred to accumulator instead 0f 1FH.
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
As shown in picture above this is a 2 byte instruction which requires 1 cycle to complete.
Program counter will increment by 2 and stand in 0204. The opcode for instruction MOV
A, address is E5H. When the instruction at 0202 is executed (E5H), accumulator is made
active and ready to receive data. Then program control goes to next address that is 0203
and look up the address of the location (04H) where the source data (to be transferred to
accumulator) is located. At 04H the control finds the data 1F and transfers it to
accumulator and hence the execution is completed.
MOV A, R4
At a time registers can take value from R0,R1…to R7. You may already know there are 32
such registers. . There are 4 register banks named 0,1,2 and 3. Each bank has 8 registers
named from R0 to R7. At a time only one register bank can be selected. Selection of
register bank is made possible through a Special Function Register (SFR) named
Processor Status Word (PSW). PSW is an 8 bit SFR where each bit can be programmed.
Bits are designated from PSW.0 to PSW.7 Register banks are selected using PSW.3 and
PSW.4 These two bits are known as register bank select bits as they are used to select
register banks. A picture below shows the PSW register and the Register Bank Select bits
with status.
So in register direct addressing mode, data is transferred to accumulator from the register
(based on which register bank is selected).
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
So we see that opcode for MOV A, R4 is EC. The opcode is stored in program memory
address 0202 and when it is executed the control goes directly to R4 of the respected
register bank (that is selected in PSW). If register bank #0 is selected then the data from
R4 of register bank #0 will be moved to accumulator. (Here it is 2F stored at 04 H). 04 H is
the address of R4 of register bank #0. Movement of data (2F) in this case is shown as
bold line. Now please take a look at the dotted line. Here 2F is getting transferred to
accumulator from data memory location 0C H. Now understand that 0C H is the address
location of Register 4 (R4) of register bank #1. Programmers usually get confused with
register bank selection. Also keep in mind that data at R4 of register bank #0 and register
bank #1 (or even other banks) will not be same. So wrong selection of register banks will
result in undesired output.
Also note that the instruction above is 1 byte and requires 1 cycle for complete execution.
This means using register direct addressing mode can save program memory.
MOV A, @R0
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5
Here the value inside R0 is considered as an address, which holds the data to be
transferred to accumulator.
Example: If R0 holds the value 20H, and we have a data 2F H stored at the address 20H,
then the value 2FH will get transferred to accumulator after executing this instruction.
So the opcode for MOV A, @R0 is E6H. Assuming that register bank #0 is selected. So
the R0 of register bank #0 holds the data 20H. Program control moves to 20H where it
locates the data 2FH and it transfers 2FH to accumulator.
This is a single byte instruction and the program counter increments 1 and moves to 0203
of program memory.
Note: Only R0 and R1 are allowed to form a register indirect addressing instruction. In
other words programmer can must make any instruction either using @R0 or @R1. All
register banks are allowed.
Relative addressing
The instruction specifies the address relative to program counter. The instruction will carry
an offset whose range is -128 to +127. The offset is added to PC to generate 16-bit physical
address
2. Control knobs in washing machine: • Load select knob • Water inlet select knob • Mode
select knob • Program select knob
3. Load select knob:- load Number of clothes low medium high Load select
6. Program select knob:- Heavy Clothes very dirty Normal Normal dirty clothes LIGHT For light
dirty clothes Delicate For silk clothes
7. Operations:- • Fill:- water will be filled by the pump as per the load knob selected. • Agitate:-
The wash basket will rotate in a clockwise direction for 10 revolutions, After that basket will
stop for 2 seconds, then rotate 10 revolutions in anticlockwise direction. The process will be
continued for specified minutes in cycle table.
8. LED ON After completion of washing cycle, buzzer sound will be generated.Drain:- After
agitation, the water and detergent are drained. Spin:- During spin, agitator will be stationary,
only the basket will rotate at high speed. Then the moisture of clothes are removed through
holes in the inner metallic basket. Indicator:- Machine ON
9. Washing cycle for Heavy, Normal, Light and Delicate setting Operation Heavy Normal Light
Delicate Fill water Set by load Select knob Set by load Select knob Set by load Select knob Set by
load Select knob Agitate 20 minutes 15 minutes 10 minutes 5 minutes Drain 5 minutes 5
minutes 5 minutes 5 minutes Fill water Set by load Select knob Set by load Select knob Set by
load Select knob Set by load Select knob Agitate 10 minutes 10 minutes 5 minutes 5 minutes
SEC1312 MICROPROCESSOR AND MICROCONTROLLERBASED SYSTEMS
UNIT 5