Professional Documents
Culture Documents
Murali, AP/CSE
UNIT IV MICROCONTROLLER
Memory
RAM (Random Access Memory) – temporary storage of
programs that computer is running
The data is lost when computer is off
Address bus
For a device (memory or I/O) to be recognized by the CPU,
it must be assigned an address
The CPU puts the address on the address bus, and the
decoding circuitry finds the device
Prepared by Mr. S. Murali, AP/CSE, VCET
Prepared by Mr. S. Murali, AP/CSE
Data bus
The CPU either gets data from the device or sends data to it
Control bus
Provides read or write signals to the device to indicate if the
CPU is asking for information or sending it information
Registers
The CPU uses registers to store information temporarily
Values to be processed
Address of value to be fetched from memory
In general, the more and bigger the registers, the better the
CPU
Registers can be 8-, 16-, 32-, or 64-bit
The disadvantage of more and bigger registers is the increased
cost of such a CPU
General-purpose microprocessors
Microcontroller
8-bit microcontrollers
Motorola’s 6811
Intel’s 8051
Zilog’s Z8
Microchip’s PIC
Architecture:
The 8051 had
-The User has no control over the work of the CPU directly .
Interrupts
•INTO
•TFO
•INT1
•TF1
•R1/T1
Memory
RAM memory - data memory of the 8051 stores data temporarily for
operation.
BUS
•Address Bus
•Data Bus
Address Bus:
Oscillator
Timers/Counters
Pin 29 − PSEN pin which stands for Program Store Enable and used
to read a signal from the external program memory.
Pin 30 − EA pin which stands for External Access input and used to
enable/disable the external memory interfacing.
Pin 31 − ALE pin which stands for Address Latch Enable and used
to demultiplex the address-data signal of port.
(2) Both code and data may be internal, however, both expand using external components
to a maximum of 64K code memory and 64K data memory.
(3) Internal memory consists of on-chip ROM and on-chip data RAM.
(4) On-chip RAM contains a rich arrangement of general purpose storage, bit addressable
storage, register banks, and special function registers.
(5) In the 8051, the registers and input/output ports are memory mapped and accessible
like any other memorylocation.
(6) In the 8051, the stack resides within the internal RAM, rather than in external RAM.
2
2
24
Accumulator
(1)A register is a general-purpose register used for storing
intermediate results obtained during operation.
26
B Register
(1)B register or accumulator B is used along with the accumulator
for multiply and divideoperations.
27
11
Stack Pointer
(1)Stack pointer (SP) is an 8-bit register at address 81H.
(2) It contains the address of the data item currently on top of the
stack.
(3)Stack operations include pushing data on the stackandpopping
data off the stack.
(4)Pushing increments SP before writing thedata
(5)Popping from the stack reads the data and decrements theSP
(6). 8051 stack is kept in the internalRAM
(7)Depending on the initial value of the SP,stack canhave
different sizes
12
I/O Ports
32
PORT 0
(1)Port 0 is 8-bitbidirectional I/O port.
PORT 1
(1)Port 1 is an 8-bit bidirectional I/0port.
PORT 2
(1) Port 2 is an 8-bit bidirectional I/O port.
(2) Port 2 emits the high-order address byte during fetches from external
program memory and during accesses to external data memory that use 16-bit
addresses (MOVX @DPTR).
35
PORT 3
(1). Port 3 is an 8-bit bi-directional I/0port.
(2). We r using pins no. from 10 to17.
Address: 87H
Used for power management of 8051 in two modes i.e. idle mode and
power down mode.
SMOD – Serial mode bit used to determine the baud rate with Timer 1.
37
39
40
Interrupts
• An interrupt is triggered whenever corresponding event
occurs. When the event occurs, the 8051 temporarily puts
"on hold" the normal execution of the program and executes
a special section of code referred to as an interrupt handler.
Interrupts Priorities
Interrupt Destinations
Interrupt Addres
s
(Hex)
1 IE0 0003H
2 TF0 000BH
3 IE1 0013H
4 TF1 001BH
5 SERIAL 0023H
26
43
44
INSTRUCTION
SET OF
8051
486
487
1. Arithmetic Instructions
• ADD
– 8-bit addition between the accumulator (A) and a
second operand.
• The result is always in the accumulator.
• The CY flag is set/reset appropriately.
• ADDC
– 8-bit addition between the accumulator, a second
operand and the previous value of the CY flag.
488
ADD Instruction
• ADD A, source ;ADD the source operand to
the accumulator
• MOV A, #03H ;load 03H into A
MOV B,#02H ;load 02H into B
ADD A,B ;add B register to accumulator
;(A = A + B)= 05
489
SUBB
–Subtract with Borrow.
–A A - <operand> - CY.
–The result is always saved in the
accumulator.
–The CY flag is set/reset appropriately.
490
SUBB Instruction
• SUBB A, source ;Subtract the source operand
with the accumulator
• MOV A, #03H ;load 03H into A
MOV B,#02H ;load 02H into B
SUBB A,B ;add B register to accumulator
;(A = A - B)= 01
491
• INC
– Increment the operand by one. Ex: INC DPTR
• The operand can be a register, a direct address, an
indirect address, the data pointer.
• DEC
– Decrement the operand by one. Ex: DEC B
• The operand can be a register, a direct address, an
indirect address.
• MUL AB / DIV AB
– Multiply A by B and place result in A:B.
– Divide A by B and place result in A:B.
492
Multiplication of Numbers
MUL AB ; A B, place 16-bit result in B and A
493
Division of Numbers
MOV A,#05 ;load 05H to reg. A
MOV B,#03 ;load 03H in reg. B
DIV AB ;05/03 =>Quotient = 01,Reminder = 02
where B = 02 and A = 01
494
•ADD A, Rn A = A+ Rn
2. Logical
instructions
496
• ANL D,S
-Performs logical AND of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: ANL A,#0FH ANL A,R5
• ORL D,S
-Performs logical OR of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: ORL A,#28H ORL A,@R0
497
•XRL D,S
-Performs logical XOR of destination & source
-Destination : A/memory;
-Source : data/register/memory
- Eg: XRL A,#28H XRL A,@R0
• CPL A
-Compliment accumulator
-gives 1’s compliment of accumulator data
• SWAP A
-Exchange the upper & lower nibbles of accumulator
498
• RL A
-Rotate data of accumulator towards left without
carry
• RLC A
- Rotate data of accumulator towards left with carry
• RR A
-Rotate data of accumulator towards right without
carry
• RRC A
- Rotate data of accumulator towards right with
carry
499
3. Data Transfer
Instructions
500
MOV Instruction
• MOV destination, source ; copy source to destination.
501
• MOVX
– Data transfer between the accumulator and
a byte from external data memory.
•MOVX A, @Ri
•MOVX A, @DPTR
•MOVX @Ri, A
•MOVX @DPTR, A
• PUSH / POP
– Push and Pop a data byte onto the stack.
– The data byte is identified by a direct
address from the internal RAM locations.
•PUSH DPL
•POP 40H
503
• XCH
– Exchange accumulator and a byte variable
•XCH A, Rn
•XCH A, direct
•XCH A, @Ri
504
4.Boolean variable
instructions
505
CLR:
• The operation clears the specified bit indicated in
the instruction
• Ex: CLR C clear the carry
SETB:
e.g. SETB 63H
• The operation sets the specified bit to 1.
CPL:
• The operation complements the specified bit
indicated in the instruction e.g. CPL A
506
• ANL C,<Source-bit>
• ORL C,<Source-bit>
507
• XORL C,<Source-bit>
•MOV P2.3,C
•MOV C,P3.3
•MOV P2.0,C
508
5. Branching
instructions
509
510
Jump Instructions
• All conditional jumps are short jumps
– Target address within -128 to +127 of PC
511
Call Instructions
• LCALL (long call): 3-byte instruction
– 2-byte address
– Target address of routine within 64K-byte range
512
513
514
8051
Addressing
Modes
515
1. Immediate
2. Register
3. Direct
4. Register indirect
5. External Direct
516
517
519
• PUSH A is invalid.
520
521
522
523
5. External Direct
• External Memory is accessed.
524