
b273269e90941feb4aa4c441d4fe2e2a.ppt
- Количество слайдов: 29
The 8051 Microcontroller and Embedded Systems CHAPTER 2 8051 ASSEMBLY LANGUAGE PROGRAMMING 1
OBJECTIVES l l l 2 List the registers of the 8051 microcontroller Manipulate data using the registers and MOV instructions Code simple 8051 Assembly language instructions Assemble and run an 8051 program Describe the sequence of events that occur upon 8051 power-up Examine programs in ROM code of the 8051 Explain the ROM memory map of the 8051 Detail the execution of 8051 Assembly language instructions Describe 8051 data types Explain the purpose of the PSW (program status word) register Discuss RAM memory space allocation in the 8051 Diagram the use of the stack in the 8051
SECTION 2. 1: INSIDE THE 8051 l 3 Registers Figure 2– 1 a Some 8 -bit Registers of the 8051
SECTION 2. 1: INSIDE THE 8051 l Registers Figure 2– 1 b 4 Some 8051 16 -bit Registers
SECTION 2. 1: INSIDE THE 8051 l l 5 most widely used registers are A, B, R 0, R 1, R 2, R 3, R 4, R 5, R 6, R 7, DPTR and PC all registers are 8 -bits, except DPTR and the program counter which are 16 bit register A is used for all arithmetic and logic instructions simple instructions MOV and ADD
SECTION 2. 1: INSIDE THE 8051 l MOV instruction – MOV destination, source MOV A, #55 H MOV R 0, A MOV R 1, A MOV R 2, A MOV R 3, #95 H MOV A, R 3 6 ; copy source to destination ; load value 55 H into reg A ; copy contents of A into R 0 (A=R 0=55 H) ; copy contents of A into R 1 (A=R 0=R 1=55 H) ; copy contents of A into R 2 (A=R 0=R 1=R 2=55 H) ; load value 95 H into R 3 (R 3=95 H) ; copy contents of R 3 into A (A=R 3=95 H)
SECTION 2. 1: INSIDE THE 8051 l ADD instruction – ADD A, source MOV A, #25 H MOV R 2, #34 H ADD A, R 2 ; ADD the source operand ; to the accumulator ; load 25 H into A ; load 34 H into R 2 ; add R 2 to accumulator Executing the program above results in A = 59 H 7
SECTION 2. 2: INTRODUCTION TO 8051 ASSEMBLY PROGRAMMING l Structure of Assembly language ORG 0 H MOV R 5, #25 H MOV R 7, #34 H MOV A, #0 ADD A, R 5 ADD A, R 7 ADD A, #12 H HERE: SJMP HERE END ; start (origin) at 0 ; load 25 H into R 5 ; load 34 H into R 7 ; load 0 into A ; add contents of R 5 to A ; now A = A + R 5 ; add contents of R 7 to A ; now A = A + R 7 ; add to A value 12 H ; now A = A + 12 H ; stay in this loop ; end of asm source file Program 2 -1: Sample of an Assembly Language Program 8
SECTION 2. 3: ASSEMBLING AND RUNNING AN 8051 PROGRAM l An Assembly language instruction consists of four fields: [label : ] 9 mnemonic [operands] [; comment]
SECTION 2. 3: ASSEMBLING AND RUNNING AN 8051 PROGRAM 10 Figure 2– 2 Steps to Create a Program
SECTION 2. 3: ASSEMBLING AND RUNNING AN 8051 PROGRAM l More about "a 51" and "obj" files – – 11 "asm" file is source file and for this reason some assemblers require that this file have the “a 51" extension this file is created with an editor such as Windows Notepad or u. Vision editor u. Vision assembler converts the a 51 assembly language instructions into machine language and provides the obj file assembler also produces the Ist file
SECTION 2. 3: ASSEMBLING AND RUNNING AN 8051 PROGRAM l Ist file – – – 12 lst file is useful to the programmer because it lists all the opcodes and addresses as well as errors that the assembler detected u. Vision assumes that the list file is not wanted unless you indicate that you want to produce it file can be accessed by an editor such as Note Pad and displayed on the monitor or sent to the printer to produce a hard copy programmer uses the list file to find syntax errors only after fixing all the errors indicated in the lst file that the obj file is ready to be input to the linker program
SECTION 2. 4: THE PROGRAM COUNTER AND ROM SPACE IN THE 8051 l Program counter in the 8051 – – – 13 16 bits wide can access program addresses 0000 to FFFFH total of 64 K bytes of code
SECTION 2. 4: THE PROGRAM COUNTER AND ROM SPACE IN THE 8051 l Where the 8051 wakes up when it is powered up: – – 14 wakes up at memory address 0000 when it is powered up first opcode must be stored at ROM address 0000 H
SECTION 2. 4: THE PROGRAM COUNTER AND ROM SPACE IN THE 8051 l Placing code in program ROM – 15 the opcode and operand are placed in ROM locations starting at memory 0000
SECTION 2. 4: THE PROGRAM COUNTER AND ROM SPACE IN THE 8051 l 16 ROM memory map in the 8051 family Figure 2– 3 8051 On-Chip ROM Address Range
SECTION 2. 5: 8051 DATA TYPES AND DIRECTIVES l 8051 data type and directives – – 17 DB (define byte) ORG (origin) EQU (equate) END directive
SECTION 2. 5: 8051 DATA TYPES AND DIRECTIVES l Rules for labels in Assembly language – – – 18 each label name must be unique first character must be alphabetic reserved words must not be used as labels
SECTION 2. 6: 8051 FLAG BITS AND THE PSW REGISTER l 19 PSW (program status word) register Figure 2– 4 Bits of the PSW Register
SECTION 2. 6: 8051 FLAG BITS AND THE PSW REGISTER 20 Table 2– 1 Instructions That Affect Flag Bits
SECTION 2. 7: 8051 REGISTER BANKS AND STACK l 21 RAM memory space allocation in the 8051 Figure 2– 5 RAM Allocation in the 8051
SECTION 2. 7: 8051 REGISTER BANKS AND STACK l 22 Register banks in the 8051 Figure 2– 6 8051 Register Banks and their RAM Addresses
SECTION 2. 7: 8051 REGISTER BANKS AND STACK l How to switch register banks Table 2– 2 23 PSW Bits Bank Selection
SECTION 2. 7: 8051 REGISTER BANKS AND STACK l Stack in the 8051 – – – 24 section of RAM used to store information temporarily could be data or an address CPU needs this storage area since there are only a limited number of registers
SECTION 2. 7: 8051 REGISTER BANKS AND STACK l Viewing registers and memory with a simulator Figure 2– 7 Register’s Screen from Pro. View 32 Simulator 25
SECTION 2. 7: 8051 REGISTER BANKS AND STACK 26 Figure 2– 8 128 -Byte Memory Space from Pro. View 32 Simulator
SECTION 2. 7: 8051 REGISTER BANKS AND STACK 27 Figure 2– 9 Register’s Screen from Keil Simulator
SECTION 2. 7: 8051 REGISTER BANKS AND STACK 28 Figure 2– 10 128 -Byte Memory Space from Keil Simulator
Next … l Lecture Problems Textbook Chapter 2 – l Proteus Exercise Textbook Chapter 2 – 29 Answer as many questions as you can and submit via Me. L before the end of the lecture. Do as much of the Proteus exercise as you can and submit via Me. L before the end of the lecture.
b273269e90941feb4aa4c441d4fe2e2a.ppt