单片机实验伟福LabP汇编语言源程序.docx
《单片机实验伟福LabP汇编语言源程序.docx》由会员分享,可在线阅读,更多相关《单片机实验伟福LabP汇编语言源程序.docx(47页珍藏版)》请在冰豆网上搜索。
单片机实验伟福LabP汇编语言源程序
伟福.Lab2000P单片机仿真实验系统
MCS51汇编语言源程序参考
;软件实验一:
存储器块清零S1.ASM
Blockequ6000h
0000906000movdptr,#Block;起始地址
00037800movr0,#0;清256字节
0005E4clra
Loop:
0006F0movx@dptr,a
0007A3incdptr;指向下一个地址
0008D8FCdjnzr0,Loop;记数减一
000A02000A
ljmp$
end
;软件实验二:
二进制到BCD码转换S2.ASM
;将A拆为三个BCD码,并存入
Result开始的叁个单元
Resultequ20h
org0
0000020015ljmpStart
BinToBCD:
000375F064movb,#100
000684divab
0007F520movResult,a;除以100,得百位数
0009E5F0mova,b
000B75F00Amovb,#10
000E84divab
000FF521movResult+1,a;余数除以10,得十位数
001185F022movResult+2,b;余数为个位数
001422ret
Start:
0015758140movsp,#40h
0018747Bmova,#123
001A1103callBinToBCD
001C02001Cljmp$
end
;软件实验三:
二进制到ASCII码转换S3.ASM
;将A拆为二个ASCII码,并存入Result开始的二个单元
Resultequ20h
org0
0000020026ljmpStart
ASCIITab:
0003303132
0006333435
0009363738
000C394142
000F434445
001246db'0123456789ABCDEF';定义数字对应的
ASCII表
BinToHex:
0013900003movdptr,#ASCIITab
0016F5F0movb,a;暂存A
0018C4swapa
0019540Fanla,#0fh;取高四位
001B93movca,@a+dptr;查
ASCII表
001CF520movResult,a
001EE5F0mova,b;恢复A
0020540Fanla,#0fh;取低四位
002293movca,@a+dptr;查
ASCII表
0023F521movResult+1,a
002522ret
Start:
0026758140movsp,#40h
0029741Amova,#1ah
002B1113callBinToHex
002D02002Dljmp$
end
;软件实验四内存块移动S4.ASM
;移动
3000H-->4000H,256字节
00007830movr0,#30h
00027900movr1,#00h
00047A40movr2,#40h
00067B00movr3,#00h
00087F00movr7,#0
Loop:
000A8883movdph,r0
000C8982movdpl,r1
000EE0movxa,@dptr
000F8A83movdph,r2
00118B82movdpl,r3
0013F0movx@dptr,a
0014B9FF01cjner1,#0ffh,Goon1
001708incr0
Goon1:
001809incr1
0019BBFF01cjner3,#0ffh,Goon2
001C0Aincr2
Goon2:
001D0Bincr3
001EDFEAdjnzr7,Loop
0020020020ljmp$
end
;软件实验五程序跳转表S5.ASM
org0
000002001DljmpStart
00037400Func0:
mova,#0
000522ret
00067401Func1:
mova,#1
000822ret
00097402Func2:
mova,#2
000B22ret
000C7403Func3:
mova,#3
000E22ret
FuncEnter:
000F25E0adda,acc;ajmp为二字节指令
调用号
X2
0011900015movdptr,#FuncTab
001473jmp@a+dptr
FuncTab:
00150103ajmpFunc0
00170106ajmpFunc1
00190109ajmpFunc2
001B010CajmpFunc3
Start:
001D7400mova,#0
001F110FcallFuncEnter
00217401mova,#1
0023110FcallFuncEnter
00257402mova,#2
0027110FcallFuncEnter
00297403mova,#3
002B110FcallFuncEnter
002D02002Dljmp$
end
;软件实验六数据排序
S6.ASM
Sizeequ10;数据个数
Arrayequ50h;数据起始地址
Changeequ0;交换标志
Sort:
00007850movr0,#Array
00027F09movr7,#Size-1
0004C200clrChange
Goon:
0006E6mova,@r0
0007FAmovr2,a
000808incr0
000986F0movB,@r0
000BB5F002cjnea,B,NotEqual
000E8008sjmpNext
NotEqual:
00104006jcNext;前小后大
不交换
0012D200setbChange;前大后小
置交换标志
0014C6xcha,@r0;交换
001518decr0
0016C6xcha,@r0
001708incr0
Next:
0018DFECdjnzr7,Goon
001A2000E3jbChange,Sort
001D02001Dljmp$
end
;硬件实验一P1口输入、输出实验H1A.ASM
Loop:
00007401mova,#01h
00027A08movr2,#8
Output:
0004F590movP1,a000623rl
000712000FcallD(a)elay
000ADAF8djnzr2,Output
000C020000ljmpLoop
Delay:
000F7E00movr6,#0
00117F00movr7,#0
DelayLoop:
0013DEFEdjnzr6,DelayLoop
0015DFFCdjnzr7,DelayLoop
001722ret
end
;硬件实验一P1口输入、输出实验H1B.ASM
KeyLeftequP1.0
KeyRightequP1.1
LedLeftequP1.2
LedRightequP1.3
0000D290SETBKeyLeft
0002D291SETBKeyRight
Loop:
0004A290MOVC,KeyLeft
00069292MOVLedLeft,C
0008A291MOVC,KeyRight
000A9293MOVLedright,C
000C020004LJMPLoop
END
;硬件实验二继电器控制实验H2.ASM
OutputequP1.0;P1.0port
Loop:
0000C3clr
00019290movO(c)utput,c
000312000FcallDelay0006D3setb
00079290movO(c)utput,c
000912000FcallDelay
000C020000ljmpLoop
-4-
伟福
.Lab2000P单片机仿真实验系统
MCS51汇编语言程序清单
Delay:
000F7E00movr6,#0
00117F00movr7,#0
DLoop:
0013DFFEdjnzr7,DLoop
0015DEFCdjnzr6,DLoop
001722ret
end
;硬件实验三用74LS245扩展I/O口实验
CS245equ8000h
org0000h
Loop:
0000908000movdptr,#CS245
0003E0movxa,@dptr
0004020000ljmpLoop
end
;硬件实验四用74LS273扩展I/O口实验
CS273equ8000h
0000908000movdptr,#CS273
00037401mova,#1
Loop:
0005F0movx@dptr,a
000623rla
000700nop
0008020005ljmpLoop
end
;硬件实验五PWM转换电压实验H5.ASM
;输出
50%(5:
5)占空比
PWM
;输出
10%(1:
9)占空比
PWM
;输出
90%(9:
1)占空比
PWM
OUTPUTequP1.0
Loop:
0000C290clrOUTPUT
00027403movA,#3
0004120011callDelay
0007D290setbOUTPUT
00097407mova,#7
000B120011callDelay
000E020000ljmpLoop
Delay:
00117800movr0,#0
DLoop:
0013D8FEdjnzr0,DLoop
0015D5E0FBdjnzacc,DLoop
001822ret
end
H3.ASM
H4.ASM
;硬件实验六音频控制实验H6.ASM
SpeakerequP1.0
CBitequ0
Loop:
0000C200clrCBit
0002850090movSpeaker,CBit
0005120013callDelay
0008D200setbCBit
000A850090movSpeaker,CBit
000D120013callDelay
0010020000ljmpLoop
Delay:
00137832movr0,#50
0015D8FEdjnzr0,$
001722ret
end
;硬件实验七8255输入、输出实验H7.ASM
modeequ082h;方式
0,PA,PC输出,PB输入
PortAequ0f000h;PortA
PortBequ0f001h;PortB
PortCequ0f002h;PortC
CAddrequ0f003h;控制字地址
org0h
00007482mova,#mode
000290F003movdptr,#CAddr
0005F0movx@dptr,a;输出控制字
000602001BjmpEX_B
;实验
1:
PortA输出
EX_A:
00097480mova,#80H
000B90F000movdptr,#PortA
000E75F008movb,#8H
0011F0OutA:
movx@dptr,a;输出
PortA
001203rra;移位
00137D01movr5,#1
001512002Bcalldelay;延时
0018D5F0F6djnzb,OutA
;实验
2:
PortB输入PortA输出
EX_B:
001B90F001movdptr,#PortB
001EE0movxa,@dptr;读入
PortB
001F90F000movdptr,#PortA
0022F0movx@dptr,a;输出到
PortA
00237D02movr5,#2
002512002Bcalldelay
0028020000ljmp0
delay:
002B7F00movr7,#0
002DDFFEddd:
djnzr7,ddd
002FDEFCdjnzr6,ddd
0031DDFAdjnzr5,ddd
003322ret
end
;硬件实验八串行数转换并行数实验H8A.ASM
0000759800movSCON,#0;串口方式
0
000374AAmova,#0aah
0005F599movSBUF,a;输出55h
00073099FDjnbti,$
000AC299clrti
000C02000Cljmp$
end
;硬件实验八串行数转换并行数实验H8B.ASM
LDequP1.0
DATequP1.1
CLKequP1.2
0000D292setbCLK
0002C290clrLD
0004D290setbLD
00067F08
movr7,#8
Next:
000803rra
0009A291movc,DAT
000B92E7movACC.7,c
000DC292clrCLK
000FD292setbCLK
0011DFF5djnzr7,Next
0013020013
ljmp$
end
;硬件实验九并行数转换串行数实验H9A.ASM
LDequP1.0
0000C290clrLD
0002D290setbLD
0004759810movSCON,#00010000b
00073098FDWait:
jnbRI,Wait
000AE599mova,SBUF
000CC298clrri
000E02000Eljmp$
end
;硬件实验九并行数转换串行数实验H9B.ASM
LDequP1.0
DATequP1.1
CLKequP1.2
0000D292setbCLK
0002C290clrLD
0004D290setbLD
00067F08movr7,#8
Next:
000803rra
0009A291movc,DAT
000B92E7movACC.7,c
000DC292clrCLK
000FD292setbCLK
0011DFF5djnzr7,Next
0013020013
ljmp$
end
;硬件实验十计数器实验H10.ASM
0000758905movTMOD,#00000101b;方式
1,记数器
0003758C00movTH0,#0
0006758A00movTL0,#0
0009D28CsetbTR0;开始记数
Loop:
000B858A90movP1,TL0;将记数结果送
P1口
000E02000BljmpLoop
end
;硬件实验十一外部中断实验H11.ASM
LEDequP1.0
LEDBufequ0
000002000E
ljmpStart
org3
Interrupt0:
0003C0D0pushPSW;保护现场
0005B200cplLEDBuf;取反
LED
0007A200movc,LEDBuf
00099290movLED,c
000BD0D0popPSW;恢复现场
000D32
reti
Start:
000EC200clrLEDBuf
0010C290clrLED
0012758801movTCON,#01h;外部中断
0下降沿触发
001575A881movIE,#81h;打开外部中断允许位(EX0)及总中断允许位(EA)
0018020018ljmp$
end
;硬件实验十二定时器实验H12.ASM
T100usequ256-50;100us时间常数(6M)
C100usequ30h;100us记数单元
LEDBufequ0
LEDequP1.0
0000020026
ljmpStart
org000bh
T0Int:
000BC0D0pushPSW
000DE531mova,C100us+1
000F7002jnzGoon
00111530decC100us
Goon:
00131531decC100us+1
0015E530mova,C100us
00174531orla,C100us+1
00197008jnzExit;100us记数器不为
0,返回
001B753027movC100us,#high(Tick)
001E753110movC100us+1,#low(Tick)
0021B200cplLEDBuf;100us记数器为
0,重置记数器
;取反
LED
Exit:
0023D0D0popPSW
002532reti
Start:
0026758902movTMOD,#02h;方式
2,定时器
0029758CCEmovTH0,#t100us
002C758ACEmovTL0,#t100us
002F75A882movIE,#10000010b;EA=1,IT0=1
0032D28CsetbTR0;开始定时
0034C200clrLEDBuf
0036C290clrLED
0038753027movC100us,#high(Tick)
003B753110movC100us+1,#low(Tick)
Loop:
003EA200movc,LEDBuf
00409290movLED,c
004202003EljmpLoop
end
;硬件实验十三D/A转换实验H13.ASM
CS0832equ0a000h
000090A000movdptr,#CS0832
00037400mova,#0
0005F0movx@dptr,a
00067440mova,#40h
0008F0movx@dptr,a
00097480mova,#80h
000BF0movx@dptr,a
000C74C0mova,#0c0h
000EF0movx@dptr,a
000F74FFmova,#0ffh
0011F0movx@dptr,a
0012020012ljmp$
end
;硬件实验十四A/D转换实验H14.ASM
modeequ082h;方式
0,PA,PC输出,PB输入
CS0809equ8000h
PortAequ9000h;PortA
PortBequ9001h;PortB
PortCequ9002h;PortC
CAddrequ9003h;控制字地址
org0
0000909003movdptr,#CAddr
00037482mova,#mode
0005F0movx@dptr,a
0006908000movdptr,#CS0809
00097400mova,#0
000BF0movx@dptr,a;起动
A/D
000C7440mova,#40h
000ED5E0FDdjnzACC,$;延时>100us
0011E0movxa,@dptr;读入结果
00127F64movr7,#100
dly:
0014909000movdptr,#PortA
0017F0movx@dptr,a
0018DFFAdjnzr7,dly;延时
001A02