Microcontroller Unit 1
Microcontroller Unit 1
Microcontroller Unit 1
Nov/Dec 2018
Microprocessor Microcontroller
1. Microprocessor is used to perform many 1. It is used to perform single task (specific
task (general purpose) purpose).
2. It does not contain on chip RAM/ROM ,I/O 2. It has fixed amount of RAM/ROM , I/O
ports timers etc. ports ,timers / counters on chip
3. It requires more external hard ware 3. It requires less external hardware
4. The systems designed using 4. The systems designed using
microprocessor are bulky and consumes microcontroller are compact and
more power. consumes less power.
5. Versatile and general purpose. 5. Not very versatile
6. Large number of instructions with flexible 6. Limited number of instructions with few
addressing modes. addressing modes .
7. Very few instructions with bit-handling 7. Limited number of instructions with bit-
capability handling capability
8. It is used in general purpose like network 8. It is used for embedded systems like TV
server, internet terminal bank teller remote control, keyboard, mouse,
machine. Examples for microprocessors microwave oven etc. Examples for
are:80286,80386 Pentium microcontrollers are 8031, 8051, 8052,
etc.
RISC CISC
1. Few instructions. 1. Many instructions.
2. Few addressing modes. 2. Larger addressing modes.
3. Fixed length instruction formats. 3. Variable length instruction formats.
4. Reduced complexity in hardware 4. Complex hardware
5. Instructions are executed in small clock 5. Execution time for an instruction may
periods. Hence they are faster than CISC take several clock cycles.
6. Examples for RISC are ARM processors. 6. Example for CISC are Intel
80286,80386,Pentium processors.
Q.3) Write a note on selection criteria of microntrollers.(5m)
1) Whether the microntroller is efficient & economical to perform the task at hand.
To check this condition the following parameters are considered,
i) Maximum operating speed
ii) Type of package i.e., DIP(Dual in Line) or QEP(Quad Flat Pack).
iii) Power consumption.
iv) The amount of on chip RAM and ROM.
v) The number of timers and I/O ports available.
Microcontroller: It is an embedded system used for specific task. Microcontroller has CPU in addition to
the fixed amount of RAM ROM I/O PORTS,Timers Serial port embedded(integrated) on a single chip. It is
also known as system on chip.
Some specific applications of microntrollers are:
OR
Specific features of 8051 are:
1) 8-bit CPU with two registers (A) Accumulator & Register B. Accumulator is used in most of ALU
operations. Register B used for integer multiplication and division.
2) A 16-bit register called Program Counter (PC).It holds the address of the location of the next
instruction to be executed.
3) A16-bit Data Pointer (DPTR) register. It is used to access external memory.
4) An 8-bit Program Status Word(PSW) register . it indicates certain conditions like status of carry,
parity ,sign etc. after execution of some instruction.
5) Internal RAM of 128 bytes divided as:-
Four register banks of 8 registers each.
16 bytes, which are bit addressable.
80 bytes of general RAM.
6) Internal ROM used to store program code.
7) Four 8-bit ports ,P0 to P3. A port pin is a pin ,where data can be transmitted to or read from an
external device.
8) Two 16-bit timers, T0 and T1 can be used as timer or counter.
9) Full duplex serial port is used for serial communication.
10) Two external and 3 internal interrupts are used to stop normal execution of instructins.
11) Oscillator and clck circuits
(1) ALE (2) PSEN (3)T0 (4) INT1 (5) TxD NOV/DEC 2017
ALE pin is used to indicate whether P0 pins carries address or data.when it is high P0 pins
carries lower order address(A0 –A7) and when it is low P0 pins carries data(D0-D7) .
It is use as read strobe to external program memory( ROM). In 8031 this pin is
connected to OE pin of external ROM chip. To acess the program code EA pin is grounded and PSEN will
go low to enable external ROM chip.
5) Txd - (serial transmit output pin) transmits data during serial communication via serial port.
FUNCTIONS OF 8051 PINS
VCC- Pin 40 provides voltage to the chip. The supply voltage is +5V.
XTAL1 & XTAL2 –(Pin 18 & 19) 8051 has an on chip oscillator but requires an external clock source
to run it. Most commonly quartz crystal is connected to crystal inputs.
It is used for dual purpose i.e., when no external memory is present, it is used as general
purpose I/O port. PORT0 has eight I/O pins P0.0 to P0.7. To use P0 as input/output port each pin must
be connected externally to 10K ohm pull-up resistor. Upon reset the P0 is configured as output port. To
make P0 as input, the P0 must be programmed by writing 1 to all its bits.
But if external memory is connected to 8051 then PORT0 provides both address and data
lines(AD0 – AD7). 8051 multiplexes address and data through P0 to save pins.
PORT1 is used as general purpose I/O port with internal pull ups. PORT1 has
eight I/O pins P1.0 to P1.7. Upon reset the P1 is configured as output port. To make P1 as input, the P1
must be programmed by writing 1 to all its bits.
PORT2 is used as general purpose I/O port with internal pull ups. PORT2 has
eight I/O pins P2.0 to P2.7. Upon reset the P2 is configured as output port. To make P2 as input, the P2
must be programmed by writing 1 to all its bits.
PORT 3 (P3) acts as a I/O port and has 8 pins P3.0 to P3.7.
Rxd- (serial receive input pin) Receives data during serial communication via serial port.
Txd - (serial transmit output pin) transmits data during serial communication via serial port
INT0 – External interrupt 0 pin
Pin 9 is the reset input. Upon applying high pulse on this pin microcontroller will
reset and terminates all activities.
ALE pin is used to indicate whether P0 pins carries address or data.when it is high P0 pins
carries lower order address(A0 –A7) and when it is low P0 pins carries data(D0-D7) .
It is use as read strobe to external program memory( ROM). In 8031 this pin is
connected to OE pin of external ROM chip. To acess the program code EA pin is grounded and PSEN will
go low to enable external ROM chip.
EA pin must be connected to GND to enable the device to fetch code from
external program memory locations starting at 0000h to FFFFh.
This pin must be connected to +VCC for internal program executions.This pin
also receives 12 V Programming Enable Voltage (VPP) during flash programming.
Q.8) Sketch the structure of PSW and write the functions of various flags.(5M) NOV/DEC 2017
It is set when there is carry from D3 to D4 bit position i.e, from lower nibble to
higher nibble . It is not accessable to user by any instruction.
It is used during signed arithmetic. It is set when there is carry from D6 to D7 and
not out of D7 or there is a carry from D7 out but no carry from D6 to D7 bit. It indicates the results of the
operation on signed numbers are too large for the register.
This flag indicates whether Reg A contains odd number of 1’s or even number of 1’s
It is set for odd parity number(odd number of 1’s in accumulator) and reset for even parity number(even
number of 1’s in accumulator).
These two bits PSW are used to select register bank.By default on power u bank 0 is
selected. To change register bank RS0 &RS1 are used as follows:
Reg A: It is an 8 bit register, all arithmetic and logical operations are done using this. It is a bit
addressable register.
Reg B: It is an 8 bit register used in multiply and division operations and as generalpurpose reg to
store data temporarily. It is also a bit addressable register.
Program Counter (PC): Program Counter is a 16 bit register that holds address of the next instruction
to be executed. PC does not have internal address. It is reset to 0000h upon power up. The contents of
PC is altered by certain interrupt related instructions or branching instructions.
Stack Pointer(SP): Stack is a part of RAM used by CPU to store information temporarily. To use stack
memory a register called Stack Pointer (SP) is used. By default Reg SP points to memory location 07h.
The Stack Pointer is incremented or decremented automatically with PUSH and POP instructions.
DPTR (Data Pointer Reg): Data Pointer is a 16 bit register used to access external memory. It can also
be used as two 8 bit registers as DPH and DPL. The address of DPL is 82h and DPH is 83h.
8051 Microcontroller has 128 bytes ofinternal RAM reffered by an address from 00h
to 7Fh. This RAM is divided into three different groups as :
1) Register Banks
2) Bit addressable RAM
3) Scratch pad RAM
0 0 Bank 0 00h-07h
0 1 Bank 1 08h-0Fh
1 0 Bank 2 10h-17h
1 1 Bank 3 18h-1Fh
After selecting a Reg bank , particular Reg can be accessed by its name (R0 – R7) or by its
address(00h – 07h).
2) Bit Addressable RAM(16 bytes or 128 bits, 20h – 2Fh)
The RAM locations 20h to 2Fh of RAM are used for bit
addressable . This means each of their bits can be addressed individually . Each bit has a unique
address from 00h – 7Fh (total 128 bits)
Example: 17h is the bit address of the bit7 in byte address 22h
30h is the bit address of the bit0 in byte address 26h
69h is the bit address of the bit1 in byte address 2Ch
Addressable bits are very useful in control of binary events(like switching ON/OFF a switch)
The instrucions specify whether to access the byte or bit address.