《微机原理与接口技术》实训程序代码.docx
- 文档编号:7728828
- 上传时间:2023-01-26
- 格式:DOCX
- 页数:12
- 大小:17.07KB
《微机原理与接口技术》实训程序代码.docx
《《微机原理与接口技术》实训程序代码.docx》由会员分享,可在线阅读,更多相关《《微机原理与接口技术》实训程序代码.docx(12页珍藏版)》请在冰豆网上搜索。
《微机原理与接口技术》实训程序代码
实训1排序程序设计
六.参考代码
DATASEGMENT
DW0055H,0033H,0066H,0077H,0099H,0011H,0022H,0088H,0044H,0000H
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVCX,9
LOOP1:
MOVDX,CX
MOVBX,0
LOOP2:
MOVAX,[BX]
INCBX
INCBX
CMPAX,[BX]
JLEDONE;小于或等于转移
XCHG[BX],AX
DECBX
DECBX
MOV[BX],AX
INCBX
INCBX
DONE:
DECDX
JNELOOP2
LOOPLOOP1
MOVAX,4C00H
INT21H
CODEENDS
ENDSTART
实训二8259A外部中断
六.参考代码
CS273equ8000H
ICW1euq00010011b;单片8259,上升沿触发中断,写ICW4ICW2equ00100000b;中断号为20HICW4equ00000001b;工作在8086/88方式OCW1equ11111110b;只响应IR0CS8259Aequ0A000hCS8259Bequ0A001h
datasegment
CNTdb0
dataends
codesegment
asummecs:
code,ds:
dta
ienterprocnear
pushax
pushdx
movdx,CS273
incCNT
moval,CNT
outdx,al;输出计数值
movdx,CS8259A
moval,20h
outdx,al
popdx
popax
iret
ienterendp
iinitproc
movdx,CS8259A
moval,ICW1
outdx,al
movdx,CS8259B
moval,ICW2
outdx,al
moval,ICW4
outdx,al
moval,OCW1
outdx,al
ret
iinitendp
startprocnear
cli
movax,0
movds,ax
movbx,4*ICW2
movax,code;
movax,offsetienter;中断入口地址(段地址为0)
mov[bx],ax
movax,0
incbx
incbx
mov[bx],ax;代码段地址为0
calliinit
movax,data
movds,ax
movCNT,0;计数初值为0
moval,CNT
movdx,CS273
outdx,al
sti
LP:
nop;等待中断
jmpLP
startendp
codeends
endstart
实训三8255输入/输出
七.参考代码
modeequ082h;方式0,PA,PC输出,PB输入PortAequ8000h;PortAPortBequ8001h;PortB
PortCequ8002h;PortC
CAddrequ8003h;控制字地址
codesegment
assumecs:
code
startprocnear
Start:
moval,mode
movdx,CAddr
outdx,al;输出控制字
moval,80H
movcx,08H
OutA:
movdx,PortA
outdx,al;输出PortA
movdx,PortC
outdx,al
shral,1;移位
movah,100
calldelay;延时
loopOutA
delayprocnear
pushax
moval,0
pushcx
movcx,ax
loop$
popcx
popax
ret
delayendp
codeends
enfstart
实训48251A串行通讯
七.参考代码
CS8251Dequ8000h;8251控制口地址
CS8251Cequ8001h
datasegment
sourcedb256dup(055h)
targetdb256dup(0aah)
RBufdb0
TBufdb0
dataends
codesegment
assumecs:
code,ds:
data
IInitprocnear;8251初始化
movdx,CS8251C
moval,01001111b;1位停止位,无校验,8位数据,波特率因子64
outdx,al
moval,00010101b;清除错标志,允许发送接收
ret
IInitendp
sendprocnear;串口发送
movdx,CS8251C
moval,00010101b
outdx,al
WaitTXD:
inal,dx
testal,1;发送缓冲器是否为空
jzWaitTXD
moval,TBuf;取要发送的字
movdx,CS8251D
outdx,al;发送数据
ret
sendendp
receiveprocnear;串行接收
movdx,CS8251C
WaitRXD:
inal,dx
testal,2;是否已收到一个字
jeWaitRXD
movdx,CS8251D
inal,dx;读取接收的字
movRBuf,al
ret
receiveend
startprocnear
movax,data
moves,ax
movsi,offsetsource
movdi,offsettarget
movcx,256
movds,ax
callIInit
MLoop:
movdx,CS8251C
inal,dx;是否接收下一个字
testal,2
jnercvdata
cmpcx,0
jeMLoop
moval,[si]
incsi
movTbuf,al
callsand
loopMLoop
jimpMLoop
rcvdata:
callreceive;读入接收的字
moval,RBuf
mov[di],al
incdi
jmpMLoop
startendp
codeends
end
实训58253计数器
七.参考代码
CONTROLequ08003h
COUNT0equ08000hCOUNT1equ08001hCOUNT2equ08002hcodesegmentassumecs:
codetartprocnearmoval,36h;00110110B;计数器0,16位,方式3,二进制
movdx,CONTROL
outdx,al
movax,10000
movdx,COUNT0
outdx,al;计数器低字节
moval,ah
outdx,al;计数器高字节
moval,76h;01110110B;计数器1,16位,方式3,二进制
movdx,CONTROL
outdx,al
movax,100
movdx,COUNT1
outdx,al;计数器低字节
moval,ah
outdx,al;计数器高字节
jmp$
startendp
codeends
endstart
实训6交通灯控制
六.参考代码
appmacroyy;控制显示宏指令
movdx,03c1h
moval,yy
outdx,al
movcx,00d0h
calldelay
endm
fresmacroxx,yy;控制闪烁宏指令
appxx
appyy
endm
tsmacroxx;控制测试宏指令
movdx,03c0h
inal,dx
testal,xx
endm
codesegmnetstack‘stack’
magdb‘outofwok!
’,0ah,0dh,24h
assumeds:
code,cs:
code,es:
code,ss:
code
start:
movax,cs
movds,ax
moves,ax
movss,ax
moval,90h
movdx,3c3h
outdx,al;置8255a方式字,使A口输入,B口输出
callzjdn
callfjdn
go:
app0ch;主干道通行
movcx,40h
b0:
pushcx
callzjdn
callfjdn
app0ch
popcx
loopb0
movcx,00d0h
calldelay
callczf;从主干道通行变为支通行
callzjdn
callfjdn
callczf
app21h;支路通行
movcx,20h
b2:
pushcx
callzjdn
app21h
popcx
loopb2
callcfz;从支路通行变为主干道通行
callzjdn
callfjdn
callcfz
movah,01h
int16h
zjagain
jnzexit;有键盘输入,结束运行
again:
jmpgo
exit:
movah,09h
movdx,offsetmsg
int21h
movah,4dh
int21h
zjdnprocnear;检测主干道特种车子程序,一旦有就放行
pushcx
ts01b
jzp1
movdx,03c1h
inal,dx
testal,21h
jzs1
callcfz
s1:
app0ch
movcx,0200h
calldelay
p1:
popcx
ret
zjdnendp
fjdnprocnear;检测支路特种车子程序,如有且主干道无才放行
pushcx
ts01b
jzff
callzjdn
ff:
ts02h
jzp2
movdx,03c1h
inal,dx
testal,0ch
jzs2
callczf
s2:
app21h
movcx,0200h
calldelay
p2:
popcx
ret
fjdnendp
delayproc;延时子程序
d2:
movax,0100h
dela:
decax
jnzdela
loopd2
ret
delayendp
cfzprocnear
pushcx
movbx,03h
w3:
fres11h,10h
decbx
jnzw3
popcx
ret
cfzendp
czfprocnear;从主干道通行变为支路通行
pushcx
movbx,03h
w1:
fresoah,02h
decbx
jnzw1
popcx
ret
czfendp
db200dup(?
)
endstart
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 微机原理与接口技术 微机 原理 接口 技术 程序代码