单片机原理及应用(双语版·新形态版) 课件 第4章MCS51汇编语言程序设计_第1页
单片机原理及应用(双语版·新形态版) 课件 第4章MCS51汇编语言程序设计_第2页
单片机原理及应用(双语版·新形态版) 课件 第4章MCS51汇编语言程序设计_第3页
单片机原理及应用(双语版·新形态版) 课件 第4章MCS51汇编语言程序设计_第4页
单片机原理及应用(双语版·新形态版) 课件 第4章MCS51汇编语言程序设计_第5页
已阅读5页,还剩139页未读, 继续免费阅读

下载本文档

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

文档简介

IntroductoryMicrocontrollerChapter4AssemblyLanguageProgrammingfortheMCS-51ProgrammingLanguageTypesint

x,y;floatv,i;Main() { x=1; while(x<55){ProgrammingLanguageTypesLinear: Assemblylanguage 直线式流程 汇编语言

int

x,y;floatv,i;Main() { x=1; while(x<55){Function-driven: C,Pascal,Modula-2 功能模块Object-oriented: C++,Java,Ada

面向对象

Event-driven: VisualBASIC(VB) 事件驱动

ProgrammingLanguageTypesLinear: AssemblylanguageUseflowchart流程图YNActionDecisionBeginorEndDefine定义Flowchart流程图EditSourceProgram编辑源程序Assemble汇编

Download下载

Run运行Errors?错误

Runtimeerrors?FinishedYNYNPROGRAMDESIGNPROCEDUREDefine定义Flowchart流程图EditSourceProgram编辑源程序Assemble汇编

Download下载

Run运行Errors?错误

Runtimeerrors?FinishedYNYNPROGRAMDESIGNPROCEDUREAssemblyLanguageProgramFormatLABEL OPCODE

OPERANDCOMMENTBEGIN: MOVA,#34h;loadaccumulator

MOV0C6h,A标号操作吗操作数注释AssemblyLanguageProgramFormatLABEL OPCODE

OPERANDCOMMENTBEGIN: MOVA,#34h;loadaccumulator

mov0c6h,aNotcasesensitiveAssemblyLanguageProgramFormatLABEL OPCODE

OPERANDCOMMENTbegin: mova,#34h;loadaccumulator

MOV0C6h,ANotcasesensitiveAssemblyLanguageProgramFormatLABEL OPCODE

OPERANDCOMMENTBEGIN: MOVA,#34h;loadaccumulator

MOV0C6h,AFirstdigitmustbeanumberAssemblyLanguageProgramFormatLABEL OPCODE

OPERANDCOMMENTBEGIN: MOVA,#34h;loadaccumulator

MOV0C6h,AUseacolontoshowitisalabel MOV A,#34hEND: SJMP ENDAssemblyLanguageProgramFormatUseof$asashorthandlabel MOV A,#34h SJMP $Howcanwestopthemicrocontroller? SJMP $UseanendlessloopFINISH: SJMP FINISHWhatarePseudo-Instructions?伪指令

Yeudos

=

NotrealEditAssembleRunSourceProgramObjectProgramReadablebyhumansReadablebyprocessorsMOVA,06hMOV27h,AINCA100101011001100111001011EditAssembleRunSourceProgramPseudo-instructions伪指令

ORG2000hBEGIN: MOVA,#26h RR A RRA ANLA,67h MOV0D6,#45h DJNZ0D6,DEL INCAPSEUDO-INSTRUCTIONSINASM51伪指令

ORG2000h-Downloadprogramat2000h1FFF1FFE1FFD2007200620052004200320022001200020082009ORG=origin

ORG1FFDhBEGIN: MOVA,#26h RRA RRA

ORG2006hCHCK: MOV0D6,#45h DJNZ0D6,DEL INCAPSEUDO-INSTRUCTIONSINASM51伪指令

1FFF1FFE1FFD2007200620052004200320022001200020082009ORG2000h-Downloadprogramat2000hPSEUDO-INSTRUCTIONSINASM51伪指令

REDEQU40h-Equatenametovalue;TrafficlightsMOV40h,#21hMOV41h,#20hGO EQU20hSTOP EQU21hROAD1EQU40hROAD2 EQU41hMOVROAD1,#STOPMOVROAD2,#GOPSEUDO-INSTRUCTIONSINASM51伪指令

REDBITP1.5-Equatenametobit RED BITP1.5 MOV R6,#0A4h DJNZ R6,$ SETB RED MOV R6,#55h DJNZ R6,$ CLR RED

ORG1FFDh DB00h,55h DB27h ORG2005h DB‘Hello’PSEUDO-INSTRUCTIONSINASM51伪指令

DB=databyte-Putbytesinmemory1FFF1FFE1FFD2007200620052004200320022001200020082009006F6C6C65485527PROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制4.4.1CopyingdataininternalmemoryCopytheblockofdataininternalRAM25h-45htoaddresses55h-75h25h56h55h45h75h26h1.UseregistersR0andR12.MOVinindirectmode3.IncrementR0andR1MMNNPPQQRRStart55hintoR1YNCopydata@R0toaddress@R1R0=46h?FinishStart25hintoR0IncrementR0IncrementR1LOOP:Example4.4.1MOV@R1,@R0ACCA累加器Direct直接寻址@Ri间接寻址Rn寄存器#data立即数PossibleDataTransferInstructionsMOV,Start55hintoR1YNCopydata@R0toaddress@R1R0=46h?FinishStart25hintoR0IncrementR0IncrementR1LOOP:Example4.4.1START: MOV R0,#25h MOV R1,#55hLOOP: MOV A,@R0 MOV @R1,A INC R0 INC R1 CJNE R0,#46h,LOOP SJMP $Example4.4.1ShandongUniversityofScienceandTechnologyMicrocontrollerTheoryandApplicationsStudent’sWorkbookforClassexercisesandHomeworkStudent’sname(Chinese)_______Student’sname(Pinyin)________StudentIDnumber____________Class___________ForwritingprogramspleaseusetheWorkbookForthefollowingdrawaflowchartandwriteaprogram..Question4.10.1Question4.10.4(“reverse”)inyourWorkbookPages74-75Question4.10.1Put3Bhintolocations40h-DFh40hintoR0YNR0=E0h?FinishStart3Bhinto@R0IncrementR0LOOP: MOVR0,#40hLOOP:MOV@R0,#3Bh INCR0 CJNER0,#0E0h,LOOP SJMP $Question4.10.4Copy25h-45hto55h-75hinreverseorder55h45h75h25hMMNNPPQQQuestion4.10.4Copy25h-45hto55h-75hinreverseorder55h45h75h25hMMNNPPQQStart75hintoR1YNCopydata@R0toaddress@R1R0=46h?FinishStart25hintoR0IncrementR0DecrementR1LOOP:START: MOV R0,#25h MOV R1,#75hLOOP: MOV A,@R0 MOV @R1,A INC R0 DEC R1 CJNE R0,#46h,LOOP SJMP $Question4.10.4Sortthenumbersintheblock30h-5Fh(Highestnumberinhighestaddress)(Totalof30hnumbers)4.4.2SortingablockofdataUsetheBubble-Sort冒泡排序methodTheBubble-Sortmethod4.4.2SortingablockofdataStartScan1Scan2Scan3Scan4Scan5Scan6Scan711991991991991991991991421142142142142142142314218787878787873871646464642587364125252519925643251191919642525319136419191919331Example4.4.2StartScan1119914219913199142142871993332519987878787199199252525252519646464646464646419191919191919Example4.4.2StartScan1Scan2Scan3Scan4Scan5Scan6Scan7119919919919919919919914211421421421421421423142187878787878738716464646425873641252525199256432511919196425253191364191919193310intoR7(count)30hintoR0Data@R1toACarry=1?A–data@R0Start31hintoR1Data@R1intoAYNCHECK:SCAN:ExchangedatainAwithdata@R0StoreA@R1IncrementR0IncrementR7(count)R0=5Fh?IncrementR1R7=2Fh?FinishYYNNCONTINUE:START: MOV R7,#00hSCAN: MOV R0,#30h MOV R1,#31hCHECK: MOV A,@R1 CLR C SUBB A,@R0 JNC CONTINUE MOV A,@R1 XCH A,@R0 MOV @R1,ACONTINUE: INC R0 INC R1 CJNE R0,#5Fh,CHECK INC R7 CJNE R7,#2Fh,SCAN SJMP $Example4.4.20intoR7(count)30hintoR0Data@R1toACarry=1?A–data@R0Start31hintoR1Data@R1intoAYNCHECK:SCAN:ExchangedatainAwithdata@R0StoreA@R1IncrementR0IncrementR7(count)R0=5Fh?IncrementR1R7=2Fh?FinishYYNNCONTINUE:Howmanyscansrequired?8numbersrequires7scans1numberrequires0scansNnumbersrequiresN-1scans30hnumbersrequires2FhscansInternalRAM40h-7FhtoexternalRAMat7000h7000h40h7FhExternalRAMInternalRAMA4.4.3Copyingdatatoexternalmemory4.4.3CopyingdatatoexternalmemoryR0=80h?StartPut40hintoR0Put7000hintoDPTRData@R0to@DPTRIncrementR0IncrementDPTRFinishYNLP:InternalRAM40h-7FhtoexternalRAMat7000h40h7FhExternalRAMInternalRAM7000hA MOV R0,#40h MOV DPTR,#7000hLP: MOV A,@R0 MOVX @DPTR,A INC R0

INC DPTR CJNE R0,#80h,LP

SJMP $4.4.4FindingthelargestvalueindataFordatainaddresses20h-4Fhfindthelargestvalue.Storetheresultinlocation60h.20h4Fh21h2536C5774E60h2536C5Copydata@R0toaddress60h20hintoR0FinishIncrementR0StartCopydata@R0toaddress60hIsdata@R0>datainaddress60h?R0=50h?YYNNLOOP:Example4.4.4CONT:START: MOV R0,#20h MOV 60h,@R0LOOP: INC R0 CJNE R0,#50h,CONT SJMP $ ;FinishCONT: MOV A,@R0 CLR C SUBB A,60h ;@R0-(60h) JC LOOP ;if(60h)>A MOV 60h,@R0;@R0to60h SJMP LOOPExample4.4.4Trythefollowing..Question4.10.18Question4.10.19Question4.10.23Pages77-78(4Fh)=77h“Address4Fhcontainsdata77h”SP=60h;(30h)=24h;(31h)=10hPUSH30h;SP=61h;(SP)=24hPUSH31h;SP=62h;(SP)=10hPOP DPL;SP=61h;DPL=10hPOP DPH;SP=60h;DPH=24hQuestion4.10.1830h31h60h61h62hSPDPTRDPLDPH24101024SPSP1024StackA=84h;R0=4Bh;(40h)=20h;(4Bh)=7FhQuestion4.10.19AR0(40h)(4Bh)Start844B207FMOVA,@R07F4B207FMOV@R0,40h7F4B2020MOV 40h,A7F4B7F20MOV R0,#35h7F357F20Question4.10.23DPTRAP0MOVP0,#00h00MOVA,#8Ch8C00MOVDPTR,#8000h80008C00MOVX@DPTR,A80008C00INCDPTR80018C00INCA80018D00MOVX@DPTR,A80018D00INCDPTR80028D00INCA80028E00MOVX@DPTR,A80028E00MOVDPTR,#8001h80018E00MOVXA,@DPTR80018D00MOVP0,A80018D8DPROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制Usethestacktoevaluatethefollowing:RAMMemoryaddresses:- V:50h

W:51h X:52h Y:53h PutZintoaddress60h4.5.1UsingthestackforarithmeticADD A,YPUSH ACC ;W+Y;AllitemsonthestackPOP Z ;W+YPOP ACC ;V+XCLR CSUBB A,ZMOV Z,A ;Z=(V+X)-(W+Y)POP ACC ;V+WADD A,ZMOV Z,A;Z=(V+W)+(V+X)-(W+Y)SJMP $V EQU 50hW EQU 51hX EQU 52hY EQU 53hZ EQU 60hMOV A,V ADD A,W

PUSH ACC;V+WMOV A,VADD A,XPUSH ACC;V+XMOV A,WReturnthevalueofanyofthefirst16primenumbers质数

usingalook-uptable.4.5.2Usingalook-uptableforarithmetic

ORG 0000h

MAIN: MOV DPTR,#0200h MOVC A,@A+DPTR SJMP $

ORG 0200hTABLE: DB 0,1,2,3,5,7,11 DB 13,17,19,23,29 DB 31,37,41,43,47200h000000010203Main0507Returnthevalueofanyofthefirst16primenumbers质数

usingalook-uptable.

ORG 0000h

MAIN: MOV DPTR,#0200h MOVC A,@A+DPTR SJMP $

ORG 0200hTABLE: DB 0,1,2,3,5,7,11 DB 13,17,19,23,29 DB 31,37,41,43,47200h000000010203Main0507A=44.5.2Usingalook-uptableforarithmeticSecondmethod:

ORG 0000h

MAIN: INC A INC A MOVC A,@A+PC SJMP $TABLE:

DB 0,1,2,3,5,7,11 DB 13,17,19,23,29 DB 31,37,41,43,47000000010203MainSJMP$05070B11A=4A=6MOVC+6A=54.5.2Usingalook-uptableforarithmeticForthefollowingdrawaflowchartandwriteaprogram..Question4.10.2Pages74-75Question4.10.2Put5…8into55h…58h.Add.Putresultin60h55h56h58h60h57h05060708Result59hQuestion4.10.2Put5…8into55h…58h.Add.Putresultin60hStart05into55hFinish55intoR0A=A+@R006into56h07into57h08into58hA=0INCR0R0=59h?Ainto60hYNLOOP: MOV 55h,#05h… MOV R0,#55h CLR ALOOP: ADD A,@R0 INC R0 CJNER0,#59h,LOOP MOV 60h,A SJMP $4.5.3SignedarithmeticcalculationsACOVMOVA,#24h+24h00ADDA,#24h+48h00CLRC+48h00SUBBA,#30h+18h00CLRC+18h00ADDA,#10101011b(-55h)-3Dh00CLRC-3Dh00SUBBA,#10011011b(-65h)+28h008-bitsignednumbers:-128to+1274.5.4Multi-byteunsignedcalculations

7E04h+50EDhPutresultin50h(low)and51h(hi)

30h31h40h41h0450h51h60h61h7EED50F1CEMOV A,30hADD A,40h ;AddlobytesMOV 50h,A ;Storelo-byteMOV A,31hADDC A,41h ;Hibytes+CMOV 51h,A ;Storehi-byte 4.5.4Multi-byteunsignedcalculations

7E04h-50EDhPutresultin60h(low)and61h(hi)

30h31h40h41h0450h51h60h61h7EED50172DMOV A,30hCLR CSUBB A,40h ;SublobytesMOV 60h,A ;Storelo-byteMOV A,31hSUBB A,41h ;Hibytes–CMOV 61h,A ;Storehi-byteC=14.5.5Pseudo-randomnumbers伪随机数1269125189132112092301671509123255573413651TestingofDigitalSystems数字系统Randomnoise随机噪声Pseudo-randomnumbers为随机数12691251891321120923016715091232555713651Xo=SeedConstantMultiplier4.5.5Pseudo-randomnumbers伪随机数4.5.5Pseudo-randomnumbers伪随机数1265X0=4iXi5*XiXi+10420212101215535257473584.5.5Pseudo-randomnumbers伪随机数12651010110110010100Dividea16-bitnumberby256Modulusislowbyteofthe16-bitnumber4.5.5Pseudo-randomnumbers(Page61)12691251891321120923016715091232555713651;LetSeedX(0)=57h,multiplierA=100(64h)

SEEDEQU 57h MOV40h,#SEED ;Seedinto40h MOV R0,#40h MOV A,@R0 ;SeedintoALOOP: MOV B,#64h ;Multiplier=100 MUL AB ;Multiplier*X(i) CJNEA,#00h,CONT MOVA,#0FFh ;Complement0valueCONT: INC R0 MOV @R0,A ;X(i+1)intoRAM CJNER0,#70h,LOOP SJMP $4.5.5Pseudo-randomnumbers(Page60)12691251891321120923016715091232555713651iX(i)100*X(i)Low_byte(100*X(i))X(i+1)057h21FChFChFCh1FCh6270h70h70h270h2BC0hC0hC0h3C0h4B00h00hFFh4FFh639Ch9Ch9ChFillinthetablesinyourtextbookforthefollowing…Question4.10.24Question4.10.25Pages79Question4.10.24Question4.10.24DPTRACORG0000hMOVDPTR,#8000h8000MOVA,#0FFh8000FFCLRC8000FF0SUBBA,#56h8000A90MOVCA,@A+DPTR8000260SJMP$8000260ORG80A8hDB0FFh,26h,55h,00hQuestion4.10.25ABORG0000hMOVA,#0C6hC6MOVB,#23hC623DIVAB0517CJNEB,#17h,NOMOD0517MOVA,#0FFhFF17SJMPFINISHFF17NOMOD:CLRANENEFINISH:SJMP$FF17PROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制4.6.1SimplelogiccalculationTakethenumbers1to9andExclusive-OReachonewiththedatainaddress5Ch.Puttheresultsinlocations71hto79h5C77767574737271787901NNXXYYZZ0203Ex-ORR0R1YN01hintoR071hinR1IncrementR1PutAintoaddress@R1AEx-OR(5Ch)R0=0Ah?R0intoA71hintoR1IncrementR0FinishStartLOOP:(5Ch)=Datainlocation5ChExample4.6.1START: MOV R0,#01h MOV R1,#71hLOOP: MOV A,R0 XRL A,5Ch MOV @R1,A INC R0 INC R1 CJNE R0,#0Ah,LOOP SJMP $ ;FinishExample4.6.14.6.2UsingstackforlogicRAMMemoryaddresses:- U:30h

V:31h W:32h X:33h Y:34h Z:35h P:40hP EQU 40hU EQU 30hV EQU 31hW EQU 32hX EQU 33hY EQU 34hZ EQU 35hANDExcl-ORORPOP P ;Y*ZXRL A,P;(U+V)*(W+X)+(Y*Z)MOV P,AMOV A,YANL A,ZPUSH ACC ;Y*ZMOV A,UORL A,VPUSH ACC ;U+VMOV A,WORL A,XPUSH ACC ;W+X;ResultsnowonstackPOP P ;W+XPOP ACC ;U+VANL A,P ;(U+V)*(W+X)Example4.6.2Nowtrythefollowing…Question4.10.3“Rotate” (Program)Question4.10.5 (Flowchart&program)Page74Question4.10.3Put128into70h.Rotaterighttwice.Resultin71h. MOV A,#80h MOV 70h,A RR A RR A MOV 71h,A SJMP $100000000010000080h=12820h=32Question4.10.5Countnegnumbersin40h-5Fh.Count:10h10110001CHKNEG:;ifC=1thenincrementCOUNT RLC A JNC NEXTONE INC COUNTNEXTONE: RRC A ;Restorevalue RET1CCOUNT=040hintoR0FinishCopy@R0toAStartR0=60?LOOP:4.10.5SubroutineCHKNEGIncrementR0COUNT EQU 10h MOV R0,#40h MOV COUNT,#00hLOOP: MOV A,R0 ACALL CHKNEG INC R0 CJNE R0,#60h,LOOP SJMP $CHKNEG: RLC A JNC NEXTONE INC COUNTNEXTONE: RRC A RET4.10.5PROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制PROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制Whydoweneedtimedelays?Whydoweneedtimedelays?TrafficlightcontrolWhydoweneedtimedelays?Generatingasquarewave4.7.1SoftwaregenerationoftimedelayProgramasubroutinetorunfor100msClockspeed=12MHzWeneed1200000cycles100ms12MHzStartsubroutineReturnR1=0?DecrementR1XXintoR0YYintoR1DecrementR0R0=0?NNYY4.7.1SoftwaregenerationoftimedelaySTART: MOV R0,#XXhLOOP1: MOV R1,#YYhLOOP2: DJNZ R1,$ DJNZ R0,LOOP1 RET4.7.1Softwaregenerationoftimedelay100ms12MHzStartsubroutineReturnR1=0?DecrementR1XXintoR0YYintoR1DecrementR0R0=0?NNYYLOOP1:LOOP2:HowmanytimespastLOOP1?XXHowmanytimespastLOOP2?XX*YY4.7.1SoftwaregenerationoftimedelaySTART: MOV R0,#XXh

;onetimeLOOP1: MOV R1,#YYh

;XXtimesLOOP2: DJNZ R1,$ ;XX*YY

DJNZ R0,LOOP1 ;XXtimes RET ;onetime4.7.1SoftwaregenerationoftimedelaySourceCode#TimesexecutedTotalclockcyclesSTART:MOVR0,#XXh12112LOOP1:MOVR1,#YYh12XX12*XXDJNZR1,$24XX*YY24*XX*YYDJNZR0,LOOP124XX24*XXRET24124Totalnumberofcycles12+12*XX+24*XX*YY+24*XX+24TimebudgetfortheprogramSTART: MOV R0,#XXLOOP1: MOV R1,#YYDJNZ R1,$ DJNZ R0,LOOP1 RETSTART: MOV R0,#0FFhLOOP1: MOV R1,#0C3h DJNZ R1,$ DJNZ R0,LOOP1 RETRoundingerror舍入误差 =.22%IfYYissmall(<50)thendecreaseXXWhatisthelongesttimedelay?StartsubroutineReturnR1=0?DecrementR1XXintoR0YYintoR1DecrementR0R0=0?NNYY4.7.1SoftwaregenerationoftimedelayFFFFSourceCode#TimesexecutedTotalclockcyclesSTART:MOVR0,#0FFh12112LOOP1:MOVR1,#0FFh12FF12*FFDJNZR1,$24FF*FF24*FF*FFDJNZR0,LOOP124FF24*FFRET24124Totalnumberofcycles12*FF+24*FF*FF+24*FFTimebudgetfortheprogramDecrementR1ReturnDecrementR2YYintoR1XXintoR0ZZintoR2DecrementR0StartsubroutineR2=0?R1=0?R0=0?Use3loopsThereisaproblemwithsoftwaretimedelays“Busywaiting”忙等待CPUisbusy-butdoingnothing!TimedelaysforlightsCheckforcarsOscillatorInterruptCPUROMRAMTimer1Timer0I/OportsSerialExternalinterruptsCounterinputsP0P1P2P3TXDRXD8051MicrocontrollerHardwaretimersPROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制Textmanipulation4.8.1Convert4-bitbinarytohexASCII7DData@R010100111Data@R011111101Putresultinlocation36hBinHexASCIIAction0000030h+30h0001131h+30h0010232h+30h0011333h+30h0100434h+30h0101535h+30h0110636h+30h0111737h+30hBinHexASCIIAction1000838h+30h1001939h+30h1010A41h+37h1011B42h+37h1100C43h+37h1101D44h+37h1110E45h+37h1111F46h+37hIFNUMBER<10THENADD30h

(togive0…9)IFNUMBER>9THENADD37h

(togiveA…F)4.8.1Convert4-bitbinarytohexASCII MOVA,@R0 ANL A,#0Fh;Getlownibble PUSHACC;Pushtostack CLR C;ResetCflag SUBBA,#0Ah;Isit<10? POPACC JC NUMBERSLETTERS: ADD A,#37h ;InrangeA…F SJMPSAVENUMBERS: ADD A,#30h;Inrange0…9SAVE: MOV 36h,A SJMP$4.8.1Convert4-bitbinarytohexASCII4.8.2ConvertASCIIvaluetobinaryPortP2RegisterR700000110636hASCII001101106BinNum

ASCIIAction0000030h-30h0001131h-30h0010232h-30h0011333h-30h0100434h-30h0101535h-30h0110636h-30h0111737h-30hBinNum

ASCIIAction1000838h-30h1001939h-30h4.8.2ConvertASCIIvaluetobinarySTART:MOVP2,#0FFh;Port2asinputLOOP: MOVR7,P2 ;ReadPort2 MOVA,R7 ;ASCIItoA CLRC SUBBA,#30h ;A-30h=binary MOVR7,A ;ResulttoR7 SJMP LOOP4.8.2ConvertASCIIvaluetobinaryPleasetry… Question4.10.22 (Page78) MOV A,___ ;BtoA ____ A,#0F0h ;Gethighnibble SWAP _____ ;Swapnibbles ____ ACC ;Pushtostack CLR ____ ;ResetC SUBB A,___ ;A-10 POP ACC ___ LOWER ADD A,#07h ;>=10,add37hLOWER:ADD A,#30h ;<10add30h MOV ___,A ;SendtoPort3 RET ;ReturnQuestion4.10.22BANLAPUSHC#0AhJCP34.8.3Stringstorageandretrieval(P67)Returnthevalueofanyofthefirst16primenumbers质数

usingalook-uptable.Usingalook-uptableforarithmetic

ORG 0000h

MAIN: MOV DPTR,#0200h MOVC A,@A+DPTR SJMP $

ORG 0200hTABLE: DB 0,1,2,3,5,7,11 DB 13,17,19,23,29 DB 31,37,41,43,47200h000000010203Main0507SendoutofPort3themessage“Login:”asASCIIcharacters

ORG 0000h

MOV DPTR,#8000hLOOP: CLR A MOVC A,@A+DPTR MOV P3,A INC DPTR CJNE A,#3Ah,LOOP SJMP $

ORG 8000h DB “Login:”8000h00004C6F6769Main6E3A4.8.3Stringstorageandretrieval(P67)4.8.4TextformattingcharactersNameShortASCIIActionCarriageReturnCR0DhTobeginningoflineLineFeedLF0AhDowntonextlineFormFeedFF0ChStartanewpageTabTAB09hNexttabpositionASCIIZeroASC000hIndicatestheendofastringDB “WelcometotheNetwork”,0Dh,0AhDB “Wecloseat5pmtoday”,0Dh,0AhDB 0Dh,0Ah,09h,09hDB “Pleaselogin:“,00hWelcometotheNetworkWecloseat5pmtoday Pleaselogin:4.8.4TextformattingcharactersP08051P2.0Ready“WelcometoBeijing”totheprinter.Send

Strobeaftereachcharacter.

WaitforReady

pulsebeforenext.EndwithASC0.

StrobeP2.14.8.5Sendingastringtoprinter010101111W1YNChar=ASC0?Storemessageinmemory4.8.5InitialiseDPTRStartSendchar@DPTRtoP0Readypulse?SendStrobepulseFinishINCDPTRYCONT:NEXT:N4.8.5PRINTER EQU P0STROBE BIT P2.1READY BIT P2.0 ORG 8000h DB “WelcometoBeijing”,00h

ORG 0000h MOV DPTR,#8000hNEXT: CLR A MOVC A,@A+DPTR MOV PRINTER,A ;Printchar SETB STROBE ;SendStrobe NOP ;pulse CLR STROBE CJNE A,#00h,CONT ;ASC0? SJMP $ ;FinishCONT: SETB READY ;Waitfor JNB READY,$ ;Readypin JB READY,$ ;togohigh INC DPTR ;Nextchar SJMP NEXT4.8.5Pleasetry… Question4.10.26 (Page80)Question4.10.26ACORG0000hMOVA,#55h55CLRC550RLCAAA0JCDETECTAA0ACALLROTATEAA0DETECT:SJMP$660ROTATE:MOVA,#66h660RET660PROGRAMMINGEXAMPLES

4.4Datamanipulation数据处理

4.5Arithmeticcalculation计算

4.6Logicalexpressions逻辑4.7Timedelays延时4.8Textmanipulation文本操作

4.9Programcontrol程序控制4.9.1N-waybranching行多方分支Home-controlsystem(HCS)LightsTVCookerGatesWaterheaterA02hFunctionDeviceLabelname1OutsidelightsLIGHTS:2AirconditioningAIRCON:3SecuritysystemSECURITY:4CurtainsCURTAINS:5DoorlocksDOORS:6TelevisionTV:7CookerCOOKER:8RefrigeratorFRIDGE:9MaingatesGATES:10WaterheaterWATER:4.9.1N-waybranching行多方分支MainProgramJumptableSubroutinesMAIN: MOV P0,#0FFh ;MakeP0aninput MOV DPTR,#TABLELOOP: MOV A,P0 ;Readfunction JZ LOOP ;LOOPifA=0 RL A ;MultiplyAby2 JMP @A+DPTR ;Jumptotable;+++++++++++++++++++++++++++++++++++++++TABL

温馨提示

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

评论

0/150

提交评论