单片机原理及应用(双语版·新形态版) 课件 第3章MCS51指令集_第1页
单片机原理及应用(双语版·新形态版) 课件 第3章MCS51指令集_第2页
单片机原理及应用(双语版·新形态版) 课件 第3章MCS51指令集_第3页
单片机原理及应用(双语版·新形态版) 课件 第3章MCS51指令集_第4页
单片机原理及应用(双语版·新形态版) 课件 第3章MCS51指令集_第5页
已阅读5页,还剩119页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

IntroductoryMicrocontrollerChapter3TheMCS-51InstructionSetandSpecialFunctionRegistersLANGUAGESFORTHE8051HighLevellanguages:- C51,SDCC,SmallC,PL/M-51Assemblylanguage:- ASM51高级语言编译语言Edit(Write)AssembleRun汇编SourceCodeObjectCode源码目标码Edit(Write)AssembleRunSourceCodeObjectCodeReadablebypeopleReadableby8051MOVA,25hPOPAINCAADDA,45h100101011001100111001011SourceCodeObjectCodeMOVA,25hE525MOV4Bh,26h854B26INCA04SETB20h.3D203AssemblyLanguageProgramFormatLABEL OPCODE

OPERANDCOMMENTBEGIN: MOV A,#34h;loadaccumulator

MOV 0C6h,A标号操作码操作数注释

SJMP BEGIN

Base SymbolDecimal noneBinary bHexadecimal hNumberFormats十进制二进制十六进制00000011b = 310 = 03h00100000b = 3210 = 20h1610 = 10h =00010000b30h = 4810 =00110000b11111111b = FFh = 2551043h=01000011bInaprogram,ahexnumbercannotbeginwithaletter F0h 0F0h E4h 0E4h C7h 0C7h

FFh 0FFhADDRESSINGMODES寻址方式

00010C0B0A0908070605040302ImmediateAddressingMOV07h,#3Fh3F3F

立即Numberneedsa#(hash井)00010C0B0A0908070605040302DirectAddressingMOV09h,02h直接

FFFFNo#meansanaddressR0R70F1017181FRegisterBank0RegisterAddressingMOVA,R6AccumulatorA寄存器5A5AHouseNo12DirectIndirect间接007HouseNo15HouseNo12R0R10C0B0A0908R7R6R5R4R3R2IndirectAddressingMOV@R1,#6Eh0A6E6EIndirectaddressingcanuseR0,R1orDPTRasindirectionregister.@=at16-bitAddressingModesImmediateDirectRegisterIndirect34hR5R0AAAAR0R10C0B0A0908R7R6R5R4R3R2InherentAddressingCLR AINC ADEC AInstructionswhichdonotmakeuseofmemoryornumbersAccumulatorAddressingRegisterARegisterAcanhavetwodifferentaddressingmodesAccumulatorAddressing8-bitbusesAccumulatoraddressingADirectaddressingACCPUSHACC {Directaddressing}POPACC {Directaddressing}INCA {Accumulatoraddressing}INCACC {Directaddressing}MOV23h,ACC {Directaddressing}MOV23h,A {Accumulatoraddress}AddressingAArethesethesame?MOV23h,ACCRAMAddressingADirectaddressingMOV23h,ACCAddressingARAMDirectaddressingRAMMOV23h,ACCAddressingADirectaddressingRAMMOV23h,ACCAddressingADirectaddressingRAMMOV23h,AAddressingAAccumulatoraddressingRAMMOV23h,AAddressingAAccumulatoraddressingMOV23h,ACC 24clockcycles

MOV23h,A 12clockcycles

时钟周期BitAddressingSomeinstructionsrefertobitsSETB28.5h {Set28.5h}SETB45h {Set28.5h}CLRP0.3 {ClearP0pin3}CPL5Eh {Complementbit5Eh}Whichlocationscanbebit-addressed?BitAddressingSomeinstructionsrefertobitsInternalRAM20h-2FhAccumulatorACCRegisterBI/OPortsMostSFRs

Whichlocationscanbebit-addressed? CLRACC.40AccumulatorABitAddressing CLR P0.30AccumulatorAClearPin3ofPort0 CLRACC.4BitAddressingBitAddressing20212C2B2A29282726252423222D2E2F CLR 24.6h00 CLR P0.3AccumulatorAClearPin3ofPort0 CLRACC.4THEMCS-51INSTRUCTIONSETFulldetailsinAppendixA(Page236)AppendixAInstruction DescriptionBytesClock cyclesADD A,direct A+(direct)->A 2 12ADD A,@Ri

A+(Ri)->A 1 12INC A A+1->A 1 12INC DPTR DPTR+1->DPTR 1 24addr11 =11-bitaddressaddr16 =16-bitaddressdirect =8-bitaddressofinternalRAMorSFRRn =DataintheregistersR0toR7@Ri =IndirectaddressusingR0orR1[]: =IFconditionin[]isTRUEthenaction() =Dataattheaddressin()rel =OffsettobeaddedtocreatetheaddressTHEMCS-51INSTRUCTIONSETDataMovementInstructionsDataMovementInstructionsMOVA,#34hMOVA,47hMOVA,R3MOVA,@R034hFFhFFh34h5Fh5FhC6hC6h47hR0R3ACCA累加器Direct直接寻址@Ri间接寻址Rn寄存器#data立即数PossibleDataTransferInstructionsMOV,AACCA累加器Direct直接寻址@Ri间接寻址Rn寄存器#data立即数PossibleDataTransferInstructionsMOV,DPTR16-bit16-bitNowtrythefollowing..Question3.5.1Question3.5.5Question3.5.7Question3.5.8Question3.5.9Page47-!!!!Question3.5.1Number5toR5,8toR7MOV R5,#05hMOV R7,#08hQuestion3.5.5Write55htoPort1MOV P1,#55hQuestion3.5.7CopyfromA9hto36hAddressingmodes:36h=Direct,A9h=IndirectUseR0asindirectregisterPage20Table2.2DataMemoryDataMemCodeMemoryCodeMemorySFRs0080FFFFFFFFFF0000IndirectInternalRAMInternalROMExternalROMExternalRAMDirectMOV R0,#0A9hMOV 36h,@R0Question3.5.1Number5toR5,8toR7MOV R5,#05hMOV R7,#08hQuestion3.5.5Write55htoPort1MOV P1,#55hQuestion3.5.7CopyfromA9hto36hAddressingmodes:36h=Direct,A9h=IndirectUseR0asindirectregisterPage20Table2.2Question3.5.8

MovefromaddressinR0to48hMOV 48h,@R0MOV R6,@R1Question3.5.9

MovefromaddressinR1toR6ACCA累加器Direct直接寻址@Ri间接寻址Rn寄存器#data立即数PossibleDataTransferInstructionsQuestion3.5.8

MovefromaddressinR0to48hMOV 48h,@R0MOV R6,@R1Question3.5.9

MovefromaddressinR1toR6MOV A,@R1MOVR6,ADataMovementInstructionsMOVCA,@A+DPTRProgramCodememoryAC656h00hDPTR=C656h56h56hDataMovementInstructionsMOVXA,@DPTRDatamemoryAMOVX@DPTR,AC656h56h56hDPTR=C656hPOP37hStackPointer36h37h35hXXXXDataMovementInstructionsPUSH36hStackPointer36h37h35hXXXXDataMovementInstructionsDataMovementInstructionsXCHA,67h(Exchange)67h66h65h68h10011100A11110000MOVR7,AMOVA,67hMOV67h,R748cyclesDataMovementInstructionsXCHDA,@R0(Exchangenibbles)67h66h65h68h1001A1111R067h11000000

半位元组Pleasetrythefollowing..(Page48)Question3.5.2Question3.5.4Question3.5.12Question3.5.10SFRshavedirectaddressingQuestion3.5.2 ExchangeSPandPSW

MOV A,SPMOV SP,PSWMOV PSW,AQuestion3.5.4CopybyteinexternalRAMat007DhtoSPMOV DPTR,#007DhMOVX A,@DPTR ;(007D)toAMOV SP,A ;AtoSPQuestion3.5.10 CopyCodebyteat13F5htoIPMOV DPTR,#13F5hCLR AMOVC A,@A+DPTRMOV IP,A POP P1Question3.5.12 POPtopofstacktoPort1ArithmeticInstructionsAADDA,#30h30h80h+80hArithmeticInstructionsB0hAADDA,#C0hC0h80h+80hArithmeticInstructions40h80h+C0h=140h1000000011000000101000000C(Carryflag)1AADDCA,#30h-AddwithCarry

30h80h+80hArithmeticInstructionsB1hC(Carryflag)1Memory4C4F4E4D(Incrementing

增加)AddtovalueinthememoryINC4Dh650166ArithmeticInstructionsMemory1E2221201FDecrementing

减少SubtractfromvalueinthememoryDEC1Fh650164ArithmeticInstructionsArithmeticInstructionsMULABABXAB(Lowbyte)(Highbyte)(Multiply)ArithmeticInstructionsMULABABXAB(Lowbyte)(Highbyte)80h80h80h*80h=4000h00h40h(Multiply)ArithmeticInstructionsDIVABABAB(Quotient)(Modulus)(Divide)商ArithmeticInstructionsDIVABABAB(Quotient)(Modulus)07h03h02h01h(Divide)商ArithmeticInstructionsDA-DecimalAdjustDecimalBinaryBCDOpcode4800110000+3200100000=8001010000ADDBinary-CodedDecimal二进制编码的十进ArithmeticInstructionsDA-DecimalAdjustDecimalBinaryBCDOpcode480011000001001000+320010000000110010=800101000001111010ADDDA10000000ArithmeticInstructionsDA-DecimalAdjustDecimalBinaryBCD480011000001001000+320010000000110010=800101000001111010ADDDA10000000MOV A,#01001000b;BCDADD A,#00110010b;BCDDA AASUBBA,#30h30h80h-80hArithmeticInstructions4FhC(Carryflag)1-ASUBBA,#30h30h80h-50hArithmeticInstructionsC(Carryflag)0ASUBBA,#80h80h30h-50hArithmeticInstructionsC(Carryflag)1ASUBBA,#80h80h30h-50hArithmeticInstructionsC(Carryflag)1Iftheresultisnegative,thentheCarry=1aftertheinstructionLogicalInstructions1111000010010000ANLA,67h(logicalAND)67h66h65h68h10011100ALogicalInstructions11110000AND100111001111000011111100ORLA,67h(logicalOR)67h66h65h68h10011100ALogicalInstructions11110000OR100111001111000001101100XRLA,67h(ExclusiveOR)67h66h65h68h10011100ALogicalInstructions11110000Ex-OR10011100LogicalInstructionsCLRA1100110100000000CPLA(Complement)1100110100110010c.LogicalInstructionsRLA(RotateLeftaccumulatorA)1001101RLCA(RotateLeftAthroughCarry)(Carryflag)C1010011011c.LogicalInstructionsRRA(RotateRightaccumulatorA)1001101RRCA(RotateRightAthroughCarry)(Carryflag)C1010011011c.LogicalInstructionsSWAPA11001101LogicalInstructionsSETB24.6hCLR24.6hNOP-Nooperation10Sometimesuse24h.6Pleasetrythefollowing..(Page48)Question3.5.15Question3.5.16Question3.5.17Question3.5.15Multiply47and96.Resultin56hand57h

MOV A,#2Fh ;Number47MOV B,#60h ;Number96MUL ABMOV 56h,A ;LowbyteofresultMOV 57h,B ;Highbyteofresult

MOV A,#61h ;Number97MOV B,#05h ;Number5DIV ABMOV 66h,A ;QuotientMOV 67h,B ;ModulusQuestion3.5.16Divide97by5.Quotientin66h,modulus67h

MOV A,#14hADD A,#67hDA AMOV 36h,AQuestion3.5.1714h(BCD)+67h(BCD)Resultin36hJumpandSubroutineInstructions

SJMP X -Shortjump LJMP Y -Longjump

AJMP Z -AbsolutejumpNoHighJump!!JumpandSubroutineInstructionsShortJumpSJMP0EDh0001F0040302SJMPF2F10<=Offset<=255EDh

JumpandSubroutineInstructionsOffset00h<=Offset<=FFhLongJumpLJMP0FFF1h0001FFF0040302LJMPCanjumpanywhereinmemoryuptoFFFFhFFF1FFF2JumpandSubroutineInstructionsFFF1AbsoluteJumpAJMP7B2h00017B1040302AJMP7B37B2Canjumpuptoaddress2047(7FFh)withinsame2kbyteblockJumpandSubroutineInstructions07B2Usesan11-bitaddressConditionalJumps条件转移

CJNEA,#01,44hCompareandJumpifnotequal4044434241?AConditionalJumps条件转移

CJNEA,#01,44hCompareandJumpifnotequal404443424155?CJNE01XXA01NOTEQUALConditionalJumps条件转移

CJNEA,#01,44hCompareandJumpifnotequal404443424101?CJNE01XXA01EQUALConditionalJumps条件转移

404443424103?DJNZ6FXXRAMaddress6Fh00NOTZERODJNZ6Fh,45hDecrementandJumpifnotzero3F3E3D4502ConditionalJumps条件转移

404443424103?DJNZ6FRAMaddress6Fh00NOTZEROAGAIN:DJNZ6Fh,AGAIN3F3E3D45020100ZERO3CXXConditionalJumpsareShortJumps

MOV A,27hLOOP: DEC A CJNE A,#00h,LOOP MOV 27h,ATypicalloopprogramsLOOP: DJNZ27h,LOOP

DJNZ27h,$JB 21.3h,LOOP-Jumpifbitset(=1)JNB21.3h,LOOP-JumpifbitNOTsetConditionalJumpwithbits

765432101001011121hJC LOOP-JumpifCarrysetJNC LOOP-JumpifCarryclearConditionalJumpwithCarry

CarryFlag0JZ LOOP-JumpifA=0JNZ LOOP-JumpifA<>0ConditionalJumponZero

MOVA,#26h ACALLDELAY ------ ------DELAY: MOV0D6,#45hAGAIN: DJNZ0D6,AGAIN RETSubroutineCallInstructions子程序ACALL 0056h-AbsolutecallLCALL 90A3h-LongcallRET-ReturnfromsubroutineMOVA…ACALLMOV…RET----------DJNZ…DELAYSubroutineCallInstructions子程序ACALL 0056h-AbsolutecallLCALL 90A3h-LongcallRET-ReturnfromsubroutineMOVA…ACALLMOV…RET----------DJNZ…

MOVA,#26h ACALLDELAY ------ ------DELAY: MOV0D6,#45hAGAIN: DJNZ0D6,AGAIN RETDELAYSpecialFunctionRegistersWherearetheSFRs?WherearetheSFRsinthecircuit?WhataretheaddressesofSFRsinmemory?SpecialFunctionRegistersSpecialFunctionRegistersWherearetheSFRs?WherearetheSFRsinthecircuit?WhataretheaddressesofSFRsinmemory?00hFFh80h7FhFFFF0000DatamemorySpecialFunctionRegistersSpecialFunctionRegistersNameAddressNameAddressAE0PSWD0BF0SCON98DPH83SBUF99DPL82SP81IEA8TMOD89IPB8TCON88P080TL08AP190TH08CP2A0TL18BP3B0TH18DPCON87FFh80h00hFFh80h7FhFFFF0000DatamemorySpecialFunctionRegistersSpecialFunctionRegistersNameAddressNameAddressAE0PSWD0BF0SCON98DPH83SBUF99DPL82SP81IEA8TMOD89IPB8TCON88P080TL08AP190TH08CP2A0TL18BP3B0TH18DPCON87FFh80hMOV A,#35hMOV B,#47hMOV 0E0h,#35hMOV 0F0h,#47hADDA,directADDA,B00hFFh80h7FhFFFF0000DatamemorySpecialFunctionRegistersSpecialFunctionRegistersNameAddressNameAddressAE0PSWD0BF0SCON98DPH83SBUF99DPL82SP81IEA8TMOD89IPB8TCON88P080TL08AP190TH08CP2A0TL18BP3B0TH18DPCON87FFh80hAccumulatormodeADirectaddressmodeACCMOVX A,@DPTRMOVX B,@DPTRSpecialFunctionRegistersAccumulatorA(AorACC)B(B)DataPointer(DPTR)ProgramCounter(PC)StackPointer(SP)888161688DPLDPHCYACF0RS1RS0OV-PProgramStatusWord-PSWCarry

进位EvenParity偶校验

forAoverflowAuxiliaryCarry

辅助进位Example:0101101001101011CYACF0RS1RS0OV-P

MOVA,#5Ah ADDA,#6BhPSW10100011011010Example:0101101001101011CYACF0RS1RS0OV-P

MOVA,#5Ah ADD

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论