Et 3491 Unit-1 Part 1
Et 3491 Unit-1 Part 1
Et 3491 Unit-1 Part 1
Basics
Microprocessor &
Microcontroller
What is Microcontroller?
Micro Controller
ports...
Example: Motorola’s 6811, Intel’s 8051, Zilog’s
Z8 and PIC
Microprocessor Microcontroller
Not Expansive
Expansive
Single-purpose
General-purpose
Home
Appliances, intercom, telephones, security systems, garage door
openers, answering machines, fax machines, home computers,
TVs, cable TV tuner, VCR, camcorder, remote controls, video
games, cellular phones, musical instruments, sewing machines,
lighting control, paging, camera, pinball machines, toys, exercise
equipment etc.
Office
Telephones, computers, security systems, fax machines,
microwave, copier, laser printer, color printer, paging etc.
Auto
Trip computer, engine control, air bag, instrumentation, security
system, transmission control, entertainment, climate control,
cellular phone, keyless entry
497
UNIT 1 Syllabus
• Microcontrollers for embedded systems
• Architecture of 8051
• Addressing modes
• Instruction set
• Program and Data Memory
• Stacks, Interrupts, Timer/Counters
• Serial Ports
• Assembly language programming
499
Intel introduced 8051, developed in the year
1981.
8bit
CP
UOSC Bus
4 I/O Ports
Serial
Contro Port
l
TXD
P0 P1 P2 P3 RXD
8 bit CPU
On-chip clock oscillator
4K bytes of on-chip Program Memory-ROM
128 bytes of on-chip Data RAM
64KB Program Memory address space
64KB Data Memory address space
32 bidirectional I/0 lines (Port
0,1,2,3) Port 0 { P0.0-P0.7 } – 8
pins
Port 1 { P1.0-P1.7 } – 8 pins
Port 2 { P2.0-P2.7 } – 8
pins Port 3 { P3.0-P3.7 } –
Two 16-bit timer/counters(Timer 1,Timer 0)
One serial port
UART(Universal Asynchronous Receiver Transmitter)
6-source interrupt structure
1. External interrupt INT0
2. Timer interrupt T0
3. External interrupt INT1
4. Timer interrupt T1
5. Serial communication interrupt
6. Timer Interrupt T2
4 Register Banks (Bank 0, Bank 1, Bank 2,
Bank3) each bank has R0-R7 registers
Pin Description
of the 8051
or
IO Port structure
EA/VPP
• EA, “external access’’
17
I/O Port Pins
• The four 8-bit I/O ports
18
Port 3
• Port 3 can be used as input or output.
19
Pin Description Summary
PIN TYPE NAME AND FUNCTION
512
Architecture of
8051
microcontrolle
r
513
514
Program Counter(PC) : The program
counter always points to the address of the
next instruction to be executed.
Stack Pointer Register (SP) : It is an 8-bit
register which stores the address of the
stack top.
ALU: perform arithmetic & logical operations
Flags : Carry(C),Auxiliary Carry(AC),
Overflow(O) & Parity(P)
Timing & Control: Timing and control unit
synchronises all microcontroller operations
with clock & generates control signals.
DPTR: (Data Pointer) - 16 bit
DPH-Data Pointer High – 8 bit
DPL-Data Pointer Low – 8 bit
External
External
60K
64K 64K
SFR
Bank 3 R0 R1 R2 R3 R4 R5 R6 R7
Bank 2 R0 R1 R2 R3 R4 R5 R6 R7
Bank 1 R0 R1 R2 R3 R4 R5 R6 R7
Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
31
Program Status Word [PSW]
C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
1. Bank 0
2. Bank 1
10 Bank 2
11 Bank 3
32
Data Pointer Register (DPTR)
It consists of two separate registers:
DPH (Data Pointer High) &
DPL (Data Pointer Low).
524
Stack Pointer (SP) Register
8 bit
8 bit
8 bit
834bit
INSTRUCTION
SET OF
8051
35
8051 Instruction Set
• The instructions are grouped into 5 groups
– Arithmetic
– Logic
– Data Transfer
– Boolean
– Branching
36
1. Arithmetic Instructions
• ADD A, source
A A + <operand>.
• ADDC A, source
A A + <operand> + CY.
• SUBB A, source
A A - <operand> - CY{borrow}.
37
• INC
– Increment the operand by one. Ex: INC
DPTR
• DEC
– Decrement the operand by one. Ex: DEC B
• MUL Multiplication
AB
A*B
Result
8 byte * 8 byte A=low byte,
B=high byte
• DIV AB
Division Quotient Remainder
8 byte /8 byte A/B A B
38
Multiplication of Numbers
MUL AB ; A B, place 16-bit result in B and A
A=07 , B=02
MUL AB ;07 * 02 = 000E where B = 00 and A =
0E
Division
;A/B ,
of Numbers
8-bit Quotient result
DIV AB
in A & 8-bit Remainder
A=07 , B=02 result in B
DIV AB ;07 / 02 = Quotient 03(A) Remainder 01
(B)
39
2. Logical
instructions
40
• ANL D,S
-Performs logical AND of destination & source
- Eg: ANL A,#0FH ANL A,R5
• ORL D,S
-Performs logical OR of destination & source
- Eg: ORL A,#28H ORL A,@R0
•XRL D,S
-Performs logical XOR of destination & source
- Eg: XRL A,#28H XRL A,@R0
41
• CPL A
-Compliment accumulator
-gives 1’s compliment of accumulator data
• 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
42
3. Data Transfer
Instructions
43
MOV Instruction
• MOV destination, source ; copy source to
destination.
• MOV ;load value 55H into reg. A
A,#55H MOV ;copy contents of A into R0
R0,A ;(now A=R0=55H)
MOV R1,A ;copy contents of A into R1
;(now A=R0=R1=55H)
MOV R2,A ;copy contents of A into R2
;(now A=R0=R1=R2=55H)
MOV R3,#95H ;load value 95H into R3
;(now R3=95H)
MOV A,R3 ;copy contents of R3 into A
;now A=R3=95H
44
• MOVX
– Data transfer between the accumulator
and a byte from external data memory.
• MOVX A, @DPTR
• MOVX @DPTR,
A
45
• PUSH / POP
– Push and Pop a data byte onto the stack.
• PUSH DPL
• POP 40H
46
• XCH
– Exchange accumulator and a byte
• XCH
variable A, Rn
• XCH A, direct
• XCH A, @Ri
47
4.Boolean variable
instructions
48
CLR:
• The operation clears the specified bit indicated in
the instruction
• Ex: CLR C clear the carry
SETB:
• The operation sets the specified bit to 1.
CPL:
• The operation complements the specified bit
indicated in the instruction
540
• ANL C,<Source-bit>
• ORL C,<Source-bit>
• MOV
P2.3,C
• MOV
C,P3.3
51
5. Branching
instructions
52
Jump Instructions
• LJMP (long jump):
– Original 8051 has only 4KB on-chip ROM
53
Call Instructions
• LCALL (long call):
– Target address within 64K-byte range
54
• 2 forms for the return instruction:
– Return from subroutine – RET
– Return from ISR – RETI
55
56
8051
Addressin
g
8051 Addressing Modes
• The CPU can access data in various ways, which are
called addressing modes
1. Immediate
2. Register
3. Direct
4. Indirect
5. Relative
6. Absolute
7. Long
8. Indexed
549
1. Immediate Addressing Mode
• The immediate data sign, “#”
• Data is provided as a part of instruction.
559
2. Register Addressing Mode
• In the Register Addressing mode, the instruction involves
transfer of information between registers.
60
3. Direct Addressing Mode
• This mode allows you to specify the operand by giving its
actual memory address
61
4. Indirect Addressing Mode
• A register is used as a pointer to the data.
• Only register R0 and R1 are used for this purpose.
• R2 – R7 cannot be used to hold the address of
an operand located in RAM.
• When R0 and R1 hold the addresses of RAM locations,
they must be preceded by the “@” sign.
MOVX A,@DPTR
62
5. Relative Addressing
• This mode of addressing is used with some type of jump
instructions, like SJMP (short jump) and conditional
jumps like JNZ
63
6. Absolute Addressing
• In Absolute Addressing mode, the absolute
address, to which the control is transferred, is
specified by a label.
• Two instructions associated with this mode
of addressing are and
ACALL AJMP
instructions.
• These are 2-byte instructions
64
7. Long Addressing
• This mode of addressing is used with the
LCALL and LJMP instructions.
• It is a 3-byte instruction
• It allows use of the full 64K code space.
65
8. Indexed Addressing
• The Indexed addressing is useful when there is a
need to retrieve data from a look-up table
(LUT).
66
8051
Assembly
Language
Programming(ALP
) 67
ADDITION OF TWO 8 bit Numbers
ADDRESS LABEL MNEMONICS
9100: CLR C
MOV A,#05
MOV B,#03
SUBB A,B
MOV DPTR,#9200
MOVX @DPTR,A
HERE SJMP HERE
MUL AB DIV AB
55 quotient
Timer Modes
IE REGISTER
SERIAL PORT OF 8051