MCA Sessional1 2023 24
MCA Sessional1 2023 24
MCA Sessional1 2023 24
(Part-II)
• CPU
- Determines operations that computer can perform
- Process data by performing digital operations on it.
- Controls flow of information among various components of
computer.
Memory
0
1
N-1
• 64KB of RAM
• Address lines? Data lines? Control lines?
• 4KB of ROM
• Address lines? Data lines? Control lines?
I/O Unit
• I/O device (Peripherals):
The device that gives information to computer - input device.
Keyboard, mouse, A/D converters are all input devices.
The device that receives information from computer called
output devices. LED, LCD, Printer..
• I/O port:
The hardware in a computer that allows information transfer
between external world and computer.
- i.e. 16-bit address bus can address 216 = 65536 (64KB) bytes of
memory.
Contd.
• Control bus
- Read (RD), write (WR) and CS’ (chip select) are most common
control signals.
- It is used to enable memory and I/O devices to perform read or
write operations.
- It regulates all activities on the bus and direction of the data transfer.
• Data bus
- It transfers data or instructions between CPU and memory or I/O
devices.
- It is bidirectional because data can be transferred in both directions
i.e. from CPU to memory (or output devices) or from memory or
input devices to CPU.
- i.e. 8-bit, 16-bit, 32-bit,, 64-bit….
- Wider data bus supports higher rate of data transfer.
Microprocessor vs. Microcontroller
• Microprocessor is a central processing unit (CPU) built into a
single semiconductor chip. The structure of microprocessor is
same as CPU.
• Each port pin except P1 can be used for two different functions.
CPU 7B
Data BUs
FB MOV A, R3
0x0001 10
MOV R7, #10H
0x0000 7F
Code Memory
Case Study
• Connected crystal of 12 MHz. Period of 1 M/C = 1 µs.
• MIPS
RESET Pin of 8051
• RST ( pin 9 ):
– input pin and active high ( normally low ) .
• High pulse is applied to this pin, microcontroller
terminates all activities and contents of all registers
will be lost.
• RESET signal must be high for 2 machine cycles.
PC 0000H
ACC 00H
B 00H
PSW 00H
SP 0007
DPTR 0000
P0- P3 FFH
R0-R7 00H
Content of on-chip RAMs are non deterministic.
ALE (Address Latch Enable)
Multiplexed Address
& Data bus
ALE 74LS373
G
AD0
P0.0 A0
D
P0.7 A7 Demultiplexed
AD7 Address & Data
bus
8051
D0
D7
P2.0 A8
P2.7 A15
8051
Contd.
• P0 provides lower 8-bit address A0-A7, and data D0- D7.
• P0 ->AD0-AD7 (Address/Data time Multiplexing)-A0 to A7,
D0-D7
• P2 provides upper 8-bit address A8-15.
P2.0 A8
P2.7 A15
8051
Code/Program Memory
A0-A15 A0-A13
Address Decoder using Logic Gates
‘1’ A12
‘1’ A13
‘0’ A14
‘0’ A15
Contd.
• A15 A14 A13 A12 A11----A0
0 0 1 1 0-------0 = 3000H
0 0 1 1 1-------1 = 3FFFH
‘1’
‘1’
‘1’
‘0’
74LS138
‘0’
‘0’
‘1’
‘0’
Contd.
(a) The address range for Y4 is calculated as follows.
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
The above shows that the range for Y4 is 4000H to 4FFFH.
0xBFFF
0x8000
Contd.
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8000H
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 BFFFH
Addressing range: 8000H to BFFFH
MOV DPTR,#9000H
MOVX @DPTR,A
Contd.
• The 16K Byte chip requires 14 address lines (A13–A0).
0000H
Contd.
• Addressing range: 0000H to 1FFFH
• Only RD’ Signal used
• To bring data into the CPU from address 1000H
(memory read operation).
MOV A, #00H
MOV DPTR, #1000H (0001 0000 0000 0000)
MOVC A, @A+DPTR
Interface 4Kbyte of ROM (2732-EPROM) as data
memory starting at the memory location 0000H.
Interface two 4K bytes of Data ROM with 8051. The starting
address for the first chip will be from 0000H and the second chip
will be from 1000H..
0000H 1000H
Contd.
• Since each chip capacity is 4K bytes, the address range for the
first will be from 0000H to 0FFFH and for the second chip, it
will be 1000H to 1FFFH.
Program/Code Memory Interfacing (EA’
Pin)
Prog.
Data
Code
Y1,Y2,Y4,Y6
• Input/Output Ports
Ports
• 32 I/O pins configured as four 8-bit parallel ports
• P0,P1,P2,P3.
:Write to Clk Q M1
latch”
TB1
“Read pin”
Circuit is only for one pin. There will be 8 such circuits, one for each pin of the port.
Hardware Structure of I/O Pin
• Each pin of I/O ports -Internally connected to CPU bus
– 2 Tri-state buffer :
• TB1: controlled by “Read pin”
– Read pin = 1 : read the data present at the pin
• TB2: controlled by “Read latch”
– Read latch = 1 : read value from internal latch
– A transistor M1 – Output Driver
Writing “1” to Output Pin P1.X
Clk Q 0 M1
Output “1”
Write to latch
TB1
Read pin
Clk Q 1 M1
Output 0
Write to latch
TB1
Read pin
P1.X
0 M1
Write to latch Clk Q
TB1
Read pin
3. Read pin=1
MOV P1, #0FFH
MOV A, P1
Reading “Low” at Input Pin
TB1
Read pin
3. Read pin=1 MOV P1, #0FFH
MOV A, P1
Port Protection
• All the port pins are configured as an input after reset because the
8051 writes 1s to all port latches after reset.
• Never write “0” to the port that was configured as input port
because it may damage the port.
• Writing ‘0’ grounds the input pin. This will short VCC connected
to a pin, and a high current will flow through M1 and may damage
it.
• To avoid it, use current limiting resistor between input signal and
port pin.
Port-0 Structure
ORG 0000H
MOV A, #01H // only 1 LED is on at a time
BACK: MOV P0, A // send to Port 1
Delay routine// delay between each glowing LED
RLA // rotate to glow next LED
SJMP BACK // repeat the pattern forever
END
Read-Modify-Write Feature
:Write to Clk Q M1
latch”
TB1
“Read pin”
• If the microcontroller reads the port pin, it will read the base
voltage of the transistor and interpret it as logic 0 (0.7 is
treated as logic level ‘0’) even though port latch contains ‘1’.
• Therefore, reading the latch rather than the pin will read
correct value of ‘1’. The same problem will occur whenever
the port pin is heavily loaded.
Contd.
• Read-modify-write instructions read a port will read the
latch and rather than pin.