Académique Documents
Professionnel Documents
Culture Documents
From the text by Mazidi & Mazidi (2000) Presentation developed by Martin Hebel
Data can be addressed in various ways, such as register, RAM or code space. The 8051 provides 5 addressing modes:
Immediate Register Direct Register Indirect Indexed
Immediate Addressing
Operand is a constant, or value written in code. Signified by a leading # MOV A, #25 MOV R4, #85H MOV DPTR, #2550H ACCEL EQU 32 MOV A, #ACCEL
4
Register Addressing
R0-R7 are the registers being addressed. The actual RAM location depends on which bank is selected. MOV A, R0 MOV R1, A MOV R4, R7 Register instructions typically use fewer bytes and may be faster than direct addressing.
5
Direct Addressing
Used to access RAM addresses 00 FFh, though typically above register banks. MOV A, 45H MOV R1, 50 MOV 35H, A These perform the same if Register Bank 0 is selected: MOV 4, A MOV R4, A
6
Write code to read PORT 0, and put on PORT 1 using their (a) names (b) addresses.
Often, when using the accumulator, it is part of the OpCode: MOV A, #55 OpCode means to Move into A Operand (2nd byte) is value 55. Some instructions, such as PUSH and POP, cannot use A (not part of opCode) and must use direct addressing: PUSH 0E0H PUSH Acc
10
Register Indirect
R0 and R1 are used to POINT to a RAM address. The @ is used to indicate Register Indirect addressing. Allows loops and other means to access a range of RAM.
11
MOV R0, #35H MOV R1, #60H MOV R3, #10 Back: MOV A, @R0 MOV @R1, A INC R0 INC R1 DJNZ R3, Back
12
Indexed Addressing
Data pointer is used to access data in ROM. Accumulator is used as a pointer offset MOVC A, @A+DPTR ORG 0000H MOV DPTR, #200H MOV A, #00H loop: MOVC A, @A+DPTR MOV SBUF A
Can be used to index a lookup table MOV DPTR, #Squares MOV A, P1 MOVC A, @A+DPTR ORG 300H Squares: DB 0, 1, 4, 9, 16, 25, (etc)
14
Write a program that will copy the value of the DIP switches into memory using register indirect addressing when SW1 is toggled. Copy 10 bytes of data.
15
From the text by Mazidi & Mazidi (2000) Presentation developed by Martin Hebel
16
17
Some instructions manipulate or operate based on a single bit. SETB bit CLR bit CPL bit JB bit, target JNB bit, target JBC bit, target Sets the bit (1) Clears the bit (0) Compliment Bit Jump bit set Jump bit not set Jump if bit set then clear
18
All bits of all 4 ports may be independently addressed: SETB P2.4 CLR P1.3 MOV C, P2.1 Wait: JNB P2.2, Wait
19
Many SFRs in the 8051 are bit addressable, but some are not.
Just as RAM has byte addresses, addressable bits also have bit addresses.
20
User RAM also has a section that is bit addressable MOV 25H, A SETB 25
21
Operations with CY
CY is the work-horse of the bit operations just as the Accumulator is for bytes.
22
23