收藏 分享(赏)

黄英_《单片机原理及应用》讲义.ppt

上传人:dreamzhangning 文档编号:3353087 上传时间:2018-10-17 格式:PPT 页数:57 大小:643.50KB
下载 相关 举报
黄英_《单片机原理及应用》讲义.ppt_第1页
第1页 / 共57页
黄英_《单片机原理及应用》讲义.ppt_第2页
第2页 / 共57页
黄英_《单片机原理及应用》讲义.ppt_第3页
第3页 / 共57页
黄英_《单片机原理及应用》讲义.ppt_第4页
第4页 / 共57页
黄英_《单片机原理及应用》讲义.ppt_第5页
第5页 / 共57页
点击查看更多>>
资源描述

1、1,Chapter 3 : Instruction system,Microcontroller Principle and Application,主讲教师:黄英,2,Contents:,3.1 Instruction format and Addressing Modes,3.2 Instruction Introduction,Chapter 3 Instruction system,3, Assemble Language: symbolic language Assembler: A computer program used to assemble Source Program A

2、ssembler Object program(Source codes) (Machine codes) Instruction Set: can not transplant directly,Chapter 3 Instruction system,3.1 Instruction format and Addressing Modes,4,3.1 Instruction format and Addressing Modes,3.1.1 Instruction format, Instruction = opcode operand= opcode destination operand

3、, source operand, Instruction types:1-byte Instruction: includes opcode and operand2-byte Instruction: 1th byte is opcode 2th byte is operand3-byte Instruction: 1th byte is opcode 2th, 3th byte are operands,5,3.1 Instruction format and Addressing Modes, Addressing: how to get the location of (source

4、) operand., Addressing Modes: 7 types 1. Register Addressing2. Direct Addressing3. Register Indirect Addressing4. Immediate Constants Addressing5. Indexed Addressing6. Boolean Addressing,3.1.2 Addressing Modes,7. Relative Addressing (get the jumping destination address of PC ),6,3.1.2 Addressing Mod

5、es,1. Register Addressing, Operand: denoted by register.For example: MOV A, R0, Addressing Range: General register: 4 banks 8( R0 R7 ) 32 registers Some SFRs: A, AB, DPTR, etc.,7,3.1.2 Addressing Modes, Operand: denoted directly by 8-bit address. For example: MOV A, 3AH, Addressing Range: Lower 128

6、bytes of internal RAM SFRs,2. Direct Addressing,8,3.1.2 Addressing Modes, Operand: specifies a register to contain operand address with the prefix “” ., Addressing Range: Lower 128 bytes of internal RAM (8-bit address ) 64KB of external RAM (16-bit address ),3. Register Indirect Addressing, address

7、register of 8-bit address: Ri(i = 0, 1) SP (PUSH, POP)address register of 16-bit address: DPTR,For example: MOV A, R0MOVX A, DPTR,9,3.1.2 Addressing Modes, Operand: specifies the value of a 8-bit or 16-bit constant with the prefix “#” .,For example: MOV A, #3AHMOV DPTR, # 0200H,4. Immediate Constant

8、s Addressing,10,3.1.2 Addressing Modes, Only three instruction: MOVC A, A+DPTRMOVC A, A+PCJMP A+DPTR Addressing Range: Program Memory (ROM),5. Indexed Addressing, Program Memory can only be accessed via this mode. Designed for reading look-up tables in Program Memory or executing unconditional jumps

9、. A 16-bit base register (DPTR or PC)points to the base address of table, and A is set up with the table entry number. The 16-bit address in ROM is formed by adding the A data to the base pointer.,11,3.1.2 Addressing Modes, Addressing Range:1. Bit addressable area in Internal RAMcell address: 20H2FH

10、, bit address: 00H7FH 2 ways to specifies the addressing bit: Cell address + bit: 20H.6 Bit address: 06H,6. Boolean Addressing,2. Addressable bit in SFRs 4 ways to specifies the addressing bit SFR symbol + bit: PSW.5 Bit address: 0D5H Cell address + bit: 0D0H.5 Bit name: F0,12,3.1.2 Addressing Modes

11、, offset Range: - 128(backward) + 127(forward),7. Relative Addressing, Used for getting the jumping destination address of PC in Jump Instruction.Destination address = PC + relPC = (address + byte number ) of Jump instructionrel = 8-bit relative offset byte,Return,13,Chapter 3 Instruction system,3.2

12、 Instruction Introduction (111 items),Data transfer instructions (29 items),Arithmetic instructions (24 items),Logical instructions (24 items),Jump instructions (17 items),Boolean instructions (17 items),Port Access instructions,The symbol meaning of Instruction format,Return,14,3.2 Instruction Intr

13、oduction,3.2.1 The symbol meaning of Instruction format,Return,See P45,15,3.2 Instruction Introduction, General format:MOV , Source operand: A, Rn, Direct address, Indirect address register, #data, #data16Destination operand: A, Rn, Direct address,Indirect address register,3.2.2 Data transfer instru

14、ctions (29 items),16, 8-bit data:MOV A, #data MOV A, 00HMOV direct, #data MOV 3CH, 0FFHMOV Rn, #data MOV R5, 0FHMOV Ri, #data MOV R1, 0CH 16-bit data:MOV DPTR, #data16 MOV DPTR, 0200H,3.2.2 Data transfer instructions,Data Transfer of internal RAM (1) Transfer immediate Constants,17,MOV direct2, dire

15、ct1 MOV 50H,30HMOV direct, Rn MOV 32H, R1MOV Rn, direct MOV R0, 33HMOV Ri, direct MOV R1, 0D0H MOV direct, Ri MOV 0D0H, R1,3.2.2 Data transfer instructions,(2) Transfer data among internal RAM cells,18,MOV A, Rn MOV A, R3MOV Rn, A MOV R2, AMOV A, direct MOV A, 0E0HMOV direct, A MOV 30H, AMOV A, Ri M

16、OV A, R0MOV Ri, A MOV R1, A,3.2.2 Data transfer instructions,(3) Transfer data by A,19,(1) Transfer data by DPTRMOVX A, DPTR MOVX DPTR, A (2) Transfer data by Ri MOVX A, Ri MOVX Ri, A They are Read/Write instructions of external RAM.,3.2.2 Data transfer instructions,2. Data Transfer of external RAM,

17、20,MOVC A, A+DPTR MOVC A, A+PC Read instructions of program memory. Indexed addressing mode Designed for reading look-up tables in Program Memory,3.2.2 Data transfer instructions,For example: PC A2000 HBA: INC A ; 2001 01H2001 MOVC A, A+PC ; 2002 30H2002 RET ; 2003 2003 DB 30H 2004 DB 31H2005 DB 32H

18、 ,3. Data Transfer of Program Memory,21,XCH A, Rn XCH A, directXCH A, RiXCHD A, Ri ;(A3A0) (Ri3Ri0)SWAP A ; (A3A0) (A7A4),3.2.2 Data transfer instructions,4. Data Exchange Instruction,For example: MOV R0, #20H ; R0 = 20HMOV A, #3FH ; A = 3FHMOV 20H, #75H ; (20H)= 75H XCHD A, R0 ; A = 35H, (20H)= 7FH

19、SWAP A ; A = 53H,22,PUSH direct ; SP SP+1, (SP)(direct)POP direct ; (direct)(SP), SP SP - 1,3.2.2 Data transfer instructions,5. Stack operation Instruction,Return,23,3.2 Instruction Introduction, For unsigned constants Including the following 7 types:,3.2.3 Arithmetic Instructions(24 items),1. Addit

20、ion Instructions2. Addition Instructions with carry bit3. Subtraction Instructions with carry bit4. Increment Instructions5. Decrement Instructions6. Multiplication/Division Instructions7. Decimal-Adjust Instructions,24,3.2.3 Arithmetic Instructions,ADD A, Rn ADD A, R6 ADD A, direct ADD A, 30H ADD A

21、, Ri ADD A, R1 ; A A +(R1) ADD A, #data ADD A, #0FH,1. Addition Instructions, Affect PSWIf bit 3 has carry bit, then AC=1, else AC=0.If bit 7 has carry bit, then CY=1, else CY=0.If bit 6 has carry bit but not bit 7, orIf bit 7 has carry bit but not bit 6, then OV=1, else OV=0.,25,3.2.3 Arithmetic In

22、structions,ADDC A, Rn ADDC A, R6 ; A A + R6 + CY ADDC A, direct ADDC A, 30H ADDC A, Ri ADDC A, R1 ; A A +(R1)+ CY ADDC A, #data ADDC A, #0FH,2. Addition Instructions with carry bit,26,3.2.3 Arithmetic Instructions,SUBB A, Rn SUBB A, R6 ; A A R6 CY SUBB A, direct SUBB A, 30H SUBB A, Ri SUBB A, R1 ; A

23、 A (R1) CY SUBB A, #data SUBB A, #0FH,3. Subtraction Instructions with carry bit, Affect PSWIf bit 3 has carry bit, then AC=1, else AC=0.If bit 7 has carry bit, then CY=1, else CY=0.If bit 6 has carry bit but not bit 7, orIf bit 7 has carry bit but not bit 6, then OV=1, else OV=0.,27,3.2.3 Arithmeti

24、c Instructions,INC A ; A A + 1 INC Rn INC R6 INC direct INC 50H ; (50H) (50H)+ 1 INC Ri INC R0 ; (R0) (R0)+ 1 INC DPTR ; DPTR DPTR + 1,4. Increment Instructions, NOT Affect PSW, except “P” flag bit.,28,3.2.3 Arithmetic Instructions,DEC A ; A A 1 DEC Rn DEC R6 DEC direct DEC 50H ; (50H) (50H) 1 DEC R

25、i DEC R1 ; (R1) (R1) 1, NOT Affect PSW, except “P” flag bit.,5. Decrement Instructions,29,3.2.3 Arithmetic Instructions,(1)MUL AB ; A low byte of product ; B high byte of product,Affect PSW : P, OV, CY=0If the product is greater than 255(0FFH), then OV=1, else OV=0.,6. Multiplication/Division Instru

26、ctions,30,3.2.3 Arithmetic Instructions,DA A, Affect PSW:P, AC, CY ONLY apply to decimal addition, not decimal subtraction.,7. Decimal-Adjust Instructions,Return,31,3.2 Instruction Introduction, Including the following 5 types:,1. ANL operation Instructions2. ORL operation Instructions3. XRL operati

27、on Instructions4. CLR/CPL operation Instructions5. Rotation bits Instructions,3.2.4 Logical instructions(24 items),32,3.2.4 Logical instructions,1. ANL operation Instructions,ANL A, Rn ; A A Rn ANL A, direct ; A A (direct) ANL A, Ri ; A A (Ri) ANL A, #data ; A A data ANL direct, A ; direct direct A

28、ANL direct, #data ; direct direct data,33,3.2.4 Logical instructions,ORL A, Rn ; A A Rn ORL A, direct ; A A (direct) ORL A, Ri ; A A (Ri) ORL A, #data ; A A data ORL direct, A ; direct direct A ORL direct, #data ; direct direct data,2. ORL operation Instructions,34,3.2.4 Logical instructions,XRL A,

29、Rn ; A A Rn XRL A, direct ; A A (direct) XRL A, Ri ; A A (Ri) XRL A, #data ; A A data XRL direct, A ; direct direct A XRL direct, #data ; direct direct data,3. XRL operation Instructions, 0101 1100 = 1001 (rule:different = 1,same = 0),35,3.2.4 Logical instructions,CLR A ; A 0 CPL A ; A A,4. CLR/CPL

30、operation Instructions,Return,36,3.2 Instruction Introduction, Including the following 4 types:,1. Unconditional Jump Instructions(4 items),3.2.5 Jump instructions(17 items),2. Conditional Jump Instructions (8 items),3. Call/Return Instructions (4 items),4. No operation Instructions (1 item),Return,

31、37,3.2.5 Jump instructions,1. Unconditional Jump Instructions, Including the following 4 types:,1-1 Long Jump Instructions1-2 Absolute Jump Instructions1-3 Short Jump Instructions1-4 Indexed Addressing Jump Instructions, Jump location: in the program memory.,38,3.2.5 Jump instructions, Jump Address

32、Range: 64KB (216 ),1-1 Long Jump Instructions,LJMP address16 ; PC address16,39,3.2.5 Jump instructions, Jump Address Range: 2KB (211 ),AJMP address11 ; PC PC + 2; PC10-0 address11,1-2 Absolute Jump Instructions,For example:,2070H AJMP 16AH ; PC = 2070H + 2 = 2072H; PC: 2072 0010 0000 0111 0010; addr

33、ess11: 16A 0000 0001 0110 1010; new PC = 0010 0001 0110 1010 = 216AH,40,3.2.5 Jump instructions, rel = 8-bit signed relative offset byte Jump Address Range: -128B+127B(256Byte, 28 ),SJMP rel ; PC PC + 2; PC PC + rel,1-3 Short Jump Instructions,For example:,835AH SJMP 35H ; PC = 835AH + 2 + 35H = 839

34、1H,835AH SJMP 0E7H ; PC = 835AH + 2 - 19H = 8343H,STOP: SJMP STOP,STOP: SJMP $,41,3.2.5 Jump instructions,JMP A+DPTR ; PC = A + DPTR,1-4 Indexed Addressing Jump Instructions,Return,42,3.2.5 Jump instructions, Including the following 3 types:,2-1 Judgement A Jump Instructions2-2 Comparison Jump Instr

35、uctions2-3 Decrement Jump Instructions,2. Conditional Jump Instructions, NOT affect PSW,43,3.2.5 Jump instructions,JZ rel ; if A 0, then PC PC + 2 + rel; if A 0, then PC PC + 2,2-1 Judgement A Jump Instructions,JNZ rel ; if A 0, then PC PC + 2 + rel; if A 0, then PC PC + 2,44,3.2.5 Jump instructions

36、,CJNE A, #data, rel ; if A data, then PC PC + 3 + relif A data, then CY 1if A data, then CY 0,2-2 Comparison Jump Instructions,CJNE A, direct, rel ; if A (direct), then PC PC + 3 + relif A (direct), then CY 1if A (direct), then CY 0 CJNE Rn, #data, rel ; if Rn data, then PC PC + 3 + relif Rn data, t

37、hen CY 1if Rn data, then CY 0 CJNE Ri, #data, rel ; if (Ri) data, then PC PC + 3 + relif (Ri) data, then CY 1if (Ri) data, then CY 0,45,3.2.5 Jump instructions,DJNZ Rn, rel ; Rn Rn - 1if Rn 0, then PC PC + 2 + relif Rn 0, then PC PC + 2,2-3 Decrement Jump Instructions,DJNZ direct, rel ; (direct) (di

38、rect)- 1if (direct) 0, then PC PC + 3 + relif (direct) 0, then PC PC + 3,Return,46,3.2.5 Jump instructions, Including the following 3 types:,3-1 Absolute Call Instructions3-2 Long Call Instructions3-3 Return Instructions,3. Call/Return Instructions,47,3.2.5 Jump instructions,ACALL ; PC PC + 2SP SP +

39、 1SP PC7-0 (low 8-bit breakpoint address)SP SP + 1SP PC15-8 (high 8-bit breakpoint address)PC10-0 address11,3-1 Absolute Call Instructions, Subroutine Call Range: 2KB (211),For example: ACALL SUBRTN_NAME1,48,3.2.5 Jump instructions,LCALL ; PC PC + 3SP SP + 1SP PC7-0 (low 8-bit breakpoint address)SP

40、SP + 1SP PC15-8 (high 8-bit breakpoint address)PC address16, Subroutine Call Range: 64KB (216),3-2 Long Call Instructions,For example: LCALL SUBRTN_NAME2,49,3.2.5 Jump instructions,RET ; PC15-8 SP (Fetch high 8-bit breakpoint address)SP SP - 1PC7-0 SP (Fetch low 8-bit breakpoint address)SP SP - 1, R

41、eturn from Subroutine,3-3 Return Instructions,RETI ; PC15-8 SP (Fetch high 8-bit breakpoint address)SP SP - 1PC7-0 SP (Fetch low 8-bit breakpoint address)SP SP - 1, Return from Interrupt,Return,50,4. No operation Instructions,NOP ; PC PC + 1, one machine cycle instruction,3.2.5 Jump instructions,Ret

42、urn,51,3.2 Instruction Introduction, Including the following 4 types instructions:,1. Bit Transfer Instructions2. Bit SETB/CLR Instructions3. Bit logical operation Instructions4. Bit Jump Instructions, Hardware resources of bit processor: 4 items.,3.2.6 Boolean instructions,52,3.2.6 Boolean instruct

43、ions,1. Bit Transfer Instructions,MOV C, bit ; CY (bit) MOV bit, C ; (bit) CY,For example: MOV C, 20H ; CY (20H) MOV 5AH, C ; (5AH) CY,53,3.2.6 Boolean instructions,SETB C ; CY 1 SETB bit ; (bit) 1 CLR C ; CY 0 CLR bit ; (bit) 0,2. Bit SETB/CLR Instructions,54,3.2.6 Boolean instructions,ANL C, bit ;

44、 CY CY (bit) ANL C, /bit ; CY CY (bit) ORL C, bit ; CY CY (bit) ORL C, /bit ; CY CY (bit) CPL C ; CY CY CPL bit ; (bit)(bit),3. Bit logical operation Instructions,55,3.2.6 Boolean instructions,4. Bit Jump Instructions,JC rel ; if CY 1, then PC PC + 2 + relif CY 1, then PC PC + 2JNC rel ; if CY 0, th

45、en PC PC + 2 + relif CY 0, then PC PC + 2,JB bit, rel ; if (bit) 1, then PC PC + 3 + relif (bit) 1, then PC PC + 3JNB bit, rel ; if (bit) 0, then PC PC + 3 + relif (bit) 0, then PC PC + 3 JBC bit, rel ; if (bit) 1, then (bit) 0, PC PC +3 + relif (bit) 1, then PC PC + 3,Return,56,3.2 Instruction Intr

46、oduction,3.2.7 Port Access instructions,Output Instructions: MOV Pm, A MOV Pm, #data MOV Pm, direct MOV Pm.n, CInput Instructions: MOV A, Pm MOV direct, Pm MOV C, Pm.n,Other Instructions: SETB Pm.n CLR Pm.n ANL C, Pm.n ORL C, Pm.n JB Pm.n, rel JBC Pm.n, rel,Read-Modify-Write Instructions: Logical Instructions: ANL, ORL, XRL, etc Boolean Instructions: JBC, CPL, SETB, CLR, etc,Return,57,Home Work of Chapter 3,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报