Mpmca Unit-4 Final
Mpmca Unit-4 Final
1.1 Introduction
Microprocessors vs. Microcontrollers
Microprocessor
The word microprocessor, in a broader sense a Central Processing Unit (CPU) only.
The functional blocks like memory and other peripherals are to be connected externally
to a microprocessor chip to form a complete microprocessor board. The system, which is
built this way, is called a “Single-Board Microcomputer”.
example 8085, 8086 and 80486 microprocessors.
Microcontroller
For the applications like design automation, designer needs a device which has all the
functional blocks inside a single IC.
Therefore, the concept of “Single chip” microcomputers came into reality.
Single-chip microcomputers are ‘Microcontrollers’.
The examples are Intel MCS-51, PIC family by Microchip, Atmel 89CXX, 89CXX51.
These microcontrollers used for general-purpose applications in the sense that they are
user programmable and have functional blocks suitable to meet a more general design
requirement.
The general structure of microprocessor and microcontroller is shown in figure 4.1.
Fig 4.4 Four register banks and their locations in the On-Chip RAM
Stack pointer and Program counter
Stack pointer:
8-bit register.
It is incremented during push or call operations.
Decremented during POP or return operation.
Initialized anywhere in the available on-chip data.
After the RESET operation, the stack pointer is initialized to 07 H.
Program counter (PC):
16 bit register, and it can address 64 K code bytes.
The 16 bit program counter specifies the address of the next instruction to be
executed.
After reset, PC will be set to 0000H and the CPU will start executing the first
execution stored at program memory location 0000H.
Table 4.2 shows the stack pointer and program counter and their addresses.
Table 4.2 Stack pointer and Program counter
Register symbol Register name Address
SP (8) Stack pointer 81 H
PC (16) Program Counter NO ADDR
Special Function Registers (SFR)
These registers have some special functions like
Controlling the timer/counter.
Enabling interrupts.
Controlling the serial port operations.
The 128 bytes of on-chip additional RAM locations from 80H to 0FFH are reserved for
the special function registers (SFRs).
There are 21 special function registers in the 8051.
Table 4.3 Special Function Registers.
SFR symbol Register name Address
ACC* Accumulator 0E0H
B* B-register 0F0H
P0* Port 0 80H
P1* Port 1 90H
P2* Port 2 0A0H
P3* Port 3 0B0H
IP* Interrupt priority control 0B8H
IE* Interrupt Enable Control 0A8H
TMOD Timer/Counter Mode Control 89H
T2CON (Only in 8052) Timer/Counter 2 control 0C8H
TCON* Timer/Counter control 88H
TH0 Timer/Counter 0 (high byte) 8CH
TL0 Timer/Counter 0 (low byte) 8AH
TH1 Timer/Counter 1 (high byte) 8DH
TL1 Timer/Counter 1 (low byte) 8BH
TH2 (only in 8052) Timer/Counter 2 (high byte) 0CDH
TL2 ( only in 8052) Timer/Counter 2 (low byte) 0CCH
RCAP2H (only in 8052) Timer/Counter 2 Capture register (high byte) 0CBH
RCAP2L (only in 8052) Timer/Counter 2 Capture register (low byte) 0CAH
SCON* Serial control 98H
SBUF Serial data buffer 99H
PCON Power control 97H
PSW* Program status word 0D0H
DPTR Data pointer
DPH Data pointer (high byte) 83H
DPL Data pointer (low byte) 82H
Program Status Word:
Program status word or simply PSW, is an 8-bit register
It consists of carry, auxiliary carry, overflow, and parity flags,
Also RS1 and RS0 for register bank selection.
The PSW is a bit addressable register.
MSB LSB
C AC F0 RS1 RS0 OV ---- P
Fig. 4.5 Program status word
Bit 7 (Carry/ Borrow flag) PSW.7:
When two 8-bit operands are added, the result may exceed 8-bit and the
9th bit is copied in the carry bit.
During subtraction, if the borrow occurs, the carry bits is set and otherwise
it is cleared.
Similarly, SETB C and CLR C instructions can also change carry bit.
Bit 6 (Auxiliary carry) PSW.6:
Used for BCD operations
Set when a carry generated from lower nibble to upper nibble
Bit 5 (F0):
F0 is available to user as a general purpose flag.
This flag can be set/cleared by software.
Bit 4 & 3: Register Bank select bits RS1 and RS0:
These bits for selecting one of the four register banks.
Each of these register banks consists of registers R0 through R7.
When power up reset, bank 0 is selected.
Table 1.4 shows the address ranges of four register banks along with RS1 and
RS0 bits.
Table 4.4 Register Bank Select Bits
Register bank Address range in
RS1 RS0
selected the on-chip RAM
0 0 Bank 0 00-07 H
0 1 Bank 1 08-0F H
1 0 Bank 2 10-17 H
1 1 Bank 3 18-1F H
Bit 2 (Over flow flag):
When two signed numbers are added, if the result exceeds the destination,
overflow flag is set, else it is reset.
Timer Registers:
Two 16-bit Registers T0 and T1 (TH0, TL0), (TH1, TL1) to hold the count
value.
TCON- to control the timer operations.
TMOD-timer mode selection.
Serial data Buffer (SBUF):
This register holds the data that has to be transmitted through the serial port
and holds the data that is received.
1.5 I/O PORTS
8051 has four 8-bit I/O ports, named as P0, P1, P2 and P3.
Denoted as P0.0-P0.7, P1.0-P1.7, P2.0-P2.7, P3.0-P3.7
Each port can be used as a single 8-bit port or single bit of each port can be
programmable
Each port consists of a latch, an output driver and an input buffer.
Port 0
A true bidirectional port as shown in figure 4.6.
Can be configured as input or output port
External pull up resistors are required if configured as an input port.
Alternate function of this port as a time multiplexed address and data bus AD0-AD7.
Priority is also programmable and it should be done with Interrupt Priority (IP) register
Bit addressable register
If bit=1, then highest priority
Fig. 4.14 Format of IP register
Write an ALP to Interface 8- LEDs to PORT 2 of 8051 with the delay of 45mS using the interrupt
Timer0 mode1. The data has to display the value “0AAH”.
ORG 0000H
MOV TMOD,#01H
MOV P2,#00H
UP: MOV TL0,#38H
MOV TH0,#50H
CPL A
MOV P2,A
ACALL DELAY
SJMP UP
DELAY: SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TR0
CLR TF0
RET
END
Write an ALP to toggle the LED, which is connected with the P2.7 and without using
timers. the delay need to be generated as 5 Sec.
ORG 0000H
UP: CPL P2.7
ACALL DELAY
SJMP UP
DELAY: SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TR0
CLR TF0
RET
END
ORG 0000H
MOV P2, #00H
RETURN: ACALL DELAY
CPL P2.7
SJMP RETURN
DELAY: MOV R5, #50H //load register R5 with 50//
DELAY1: MOV R6, #200 //load register R6 with 200//
DELAY2: MOV R7, #229 //load register R7 with 200//
DJNZ R7, $ //decrement R7 till it is zero//
DJNZ R6, DELAY2 //decrement R6 till it is zero//
DJNZ R5, DELAY1 //decrement R5 till it is zero//
RET //go back to the main program //
END
Write an ALP to Transmit the information “***INDIA***” with baud rate of 9600 and 8
data bits, 1 stop bit
MOV TMOD,#20H ; Timer 1, mode 2
MOV TH1,#-3 ; 9600 baud rate
MOV SCON,#50H ; 8-bit, 1-stop bit
SETB TR1 ; start timer 1
AGAIN: MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"I" ;transfer "I"
ACALL TRANS
MOV A,#"N" ;transfer "N"
ACALL TRANS
MOV A,#"D" ;transfer "D"
ACALL TRANS
MOV A,#"I" ;transfer "I"
ACALL TRANS
MOV A,#"A" ;transfer "A"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
SJMP AGAIN ;keep doing it
TRANS: MOV SBUF,A ; load SBUF
HERE: JNB TI,HERE ; wait for last bit to transfer
CLR TI ;get ready for next bute
RET
Write an ALP to transmit the information “***TELANGANA***” with 4800 baud rate, data bit 8, and 1
stop bit
MOV TMOD,#20H ; Timer 1, mode 2
MOV TH1,#-2 ; 4800 baud rate
MOV SCON,#50H ; 8-bit, 1-stop bit
SETB TR1 ; start timer 1
AGAIN: MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"T" ;transfer "T"
ACALL TRANS
MOV A,#"E" ;transfer "E"
ACALL TRANS
MOV A,#"L" ;transfer "L"
ACALL TRANS
MOV A,#"A" ;transfer "A"
ACALL TRANS
MOV A,#"N" ;transfer "N"
ACALL TRANS
MOV A,#"G" ;transfer "G"
ACALL TRANS
MOV A,#"A" ;transfer "A"
ACALL TRANS
MOV A,#"N" ;transfer "N"
ACALL TRANS
MOV A,#"A" ;transfer "A"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
MOV A,#"*" ;transfer "*"
ACALL TRANS
SJMP AGAIN ;keep doing it
TRANS: MOV SBUF,A ; load SBUF
HERE: JNB TI,HERE ; wait for last bit to transfer
CLR TI ;get ready for next byte
RET