单片机实验程序汇总.docx
- 文档编号:28895916
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:36
- 大小:17.72KB
单片机实验程序汇总.docx
《单片机实验程序汇总.docx》由会员分享,可在线阅读,更多相关《单片机实验程序汇总.docx(36页珍藏版)》请在冰豆网上搜索。
单片机实验程序汇总
单片机程序汇总
软件实验:
1.数据传送试验
org0
begin1:
movr0,#30h
movr7,#30h
loop1:
mov@r0,#55h
incr0
djnzr7,loop1
begin2:
movr1,#90h
movr0,#30h
movr7,#30h
loop2:
mova,@r0
mov@r1,a
incr0
incr1
djnzr7,loop2
begin3:
movr0,#30h
movr7,#30h
movdptr,#200h
loop3:
mova,@r0
movx@dptr,a
incr0
incdptr
djnzr7,loop3
ajmp$
end
2.数据分类与校验实验
org0
begin1:
movr0,#30h
movr7,#30h
mova,#1
loop1:
mov@r0,a
incr0
inca
djnzr7,loop1
begin2:
movr0,#30h
movr7,#30h
movr1,#90h
loop2:
mova,@r0
jbacc.0,jishu
ajmppassage
jishu:
mov@r1,a
incr1
passage:
incr0
djnzr7,loop2
begin3:
movr0,#30h
movr7,#30h
loop3:
mova,@r0
jnbp,next
incr0
djnzr7,loop3
next:
setbacc.7
mov@r0,a
incr0
djnzr7,loop3
ajmp$
end
3.简单算术运算
org0
clrc
clra
begin1:
mov30h,#10
mov31h,#20
mova,30h
adda,31h
mov33h,a
clra
addca,#00h
mov32h,a
clrc
mova,#30
adda,33h
mov33h,a
clra
addca,#00h
adda,32h
mov32h,a
begin2:
movb,#10
mova,30h
mulab
mov33h,a
mov32h,b
mova,31h
movb,#5
divab
clrc
adda,33h
mov33h,a
clra
addca,#00h
adda,32h
mov32h,a
clrc
mova,33h
subba,#10
mov33h,a
mova,32h
subba,#00h
mov32h,a
begin3:
mov30h,#00h
mov31h,#00h
movr7,#99
movr6,#1
mova,r6
loop3:
incr6
clrc
adda,r6
mov31h,a
clra
addca,#00h
adda,30h
mov30h,a
mova,31h
djnzr7,loop3
ajmp$
end
4.定点数算术运算实验
org0
xequ30h
yequ40h
resultequ50h
movx,#12h
movx+1,#34h
movx+2,#36h
movx+3,#39h
movy,#56h
movy+1,#78h
movy+2,#65h
movy+3,#47h
main1:
movr0,#x
movr1,#y
clrc
lcallsadd
ajmp$
sadd:
mova,@r0
adda,@r1
movresult,a
incr0
incr1
mova,@r0
addca,@r1
movresult+1,a
incr0
incr1
mova,@r0
addca,@r1
movresult+2,a
incr0
incr1
mova,@r0
addca,@r1
movresult+3,a
clra
addca,#00h
movresult+4,a
main2:
movr2,#x
movr3,#x+1
movr4,#y
movr5,#y+1
clrc
lcallmultiply
ajmp$
multiply:
mova,r3
movb,r5
mulab
movr7,a
movr6,b
mova,r2
movb,r5
mulab
adda,r6
movr6,a
clra
;
addca,b
movr5,a
mova,r3
movb,r4
mulab
adda,r6
movr6,a
mova,r5
addca,b
movr5,a
clra
addca,#00h
xcha,r4
;
movb,r2
mulab
adda,r5
movr5,a
clra
addca,r4
movr4,a
main3:
movr2,#x
movr3,#x+1
movr4,#y
movr5,#y+1
movr6,#00
movr7,#00
movr1,#16
lcalldivide
ajmp$
divide:
clrc
mova,r5
rlca
movr5,a
mova,r4
rlca
movr4,a
mova,r7
rlca
movr7,a
mova,r6
rlca
movr6,a
clrc
mova,r7
subba,r3
movb,a
mova,r6
subba,r2
jcnext
movr7,b
movr6,a
incr5
next:
djnzr1,divide
ajmp$
end
5.逻辑运算实验
org0
begin1:
xequ30h
yequ31h
zequ32h
movx,#12h
movy,#56h
mova,x
anla,y
movz,a
mova,x
orla,y
movz+1,a
mova,x
xrla,y
movz+2,a
begin2:
xequ00h
yequ01h
zequ02h
mov20h,#59h
setbf0
movc,x
anlc,y
mov06h,c
anlc,/f0
mov07h,c
movc,f0
anlc,/06h
orlc,07h
movz,c
begin3:
xequ30h
yequ31h
movx,#06h
mova,x
clrc
rlca
clrc
rlca
clrc
rlca
movr7,a
mova,x
clrc
rlca
adda,r7
movy,a
ajmp$
end
6.数制转换实验
org0
begin1:
mov30h,#59h
mova,30h
movb,#100
divab
mov31h,a
mova,b
movb,#10
divab
mov32h,a
mov33h,b
begin2:
movr7,#16
mov50h,#00h
movr0,#30h
movr1,#50h
loop2:
mova,@r1
mov@r0,a
incr0
inc@r1
djnzr7,loop2
movsp,#3fh
movr7,#10
movr0,#30h
loop2b:
mova,@r0
adda,#30h
mov60h,a
push60h
incr0
djnzr7,loop2b
movr7,#6
loop2c:
mova,@r0
adda,#37h
mov60h,a
push60h
incr0
djnzr7,loop2c
begin3:
mov30h,#34h
mov31h,#56h
movr2,#16
clra
movr3,a
movr4,a
movr5,a
loop3:
clrc
mova,31h
rlca
mov31h,a
mova,30h
rlca
mov30h,a
mova,r5
addca,r5
daa
movr5,a
mova,r4
addca,r4
daa
movr4,a
mova,r3
addca,r3
daa
movr3,a
djnzr2,loop3
mova,r3
anla,#0f0h
swapa
adda,#30h
mov40h,a
mova,r3
anla,#0fh
swapa
adda,#30h
mov41h,a
mova,r4
anla,#0f0h
swapa
adda,#30h
mov42h,a
mova,r3
anla,#0fh
swapa
adda,#30h
mov43h,a
mova,r5
anla,#0f0h
swapa
adda,#30h
mov44h,a
mova,r5
anla,#0fh
swapa
adda,#30h
mov45h,a
ajmp$
end
7.数据统计实验
org0
begin1:
movr0,#30h
movr1,#2fh
mov2fh,#50h
movr7,#50h
loop1:
mova,@r1
mov@r0,a
incr0
inc@r1
djnzr7,loop1
movr7,50h
movr6,#00h
movr0,#30h
loop1b:
mova,@r0
subba,#80h
jcnext1
incr6
next1:
clrc
incr0
djnzr7,loop1b
movb,r6
begin2:
movr2,#50h
movr0,#30h
movr6,#00h
movr7,#00h
loop2:
mova,@r0
jnbacc.0,next2
incr6
next2:
jbacc.7,next2b
incr7
next2b:
incr0
djnzr2,loop2
begin3:
movr0,#30h
movr2,#4fh
movr4,31h;r4存放最大值
mova,@r0
loop3:
clrc
subba,r4
jcnext3
mova,@r0
movr4,a
next3:
incr0
mova,@r0
djnzr2,loop3
begin3b:
movr0,#30h
movr2,#50h
movr3,31h;r3存放最小值
loop3b:
mova,@r0
subba,r3
jncnext3b
mova,@r0
movr3,a
next3b:
incr0
djnzr2,loop3b
ajmp$
end
硬件实验
1.P3口输出控制实验
org0
loop:
setbp3.5
calldelay
clrp3.5
calldelay
sjmploop
delay:
movr7,#0
dl2:
movr6,#0
dl1:
nop
nop
djnzr6,dl1
djnzr7,dl2
ret
end
2.P1口输出控制实验
org0
main:
mova,#0feh
movr7,#8
start:
movp1,#0ffh
rra
movp1,a
calldelay
djnzr7,start
movr7,#8
mova,#0feh
start1:
movp1,#0ffh
rla
movp1,a
calldelay
djnzr7,start1
ajmpmain
delay:
movr5,#0
dl2:
movr6,#0
dl1:
nop
nop
djnzr6,dl1
djnzr5,dl2
ret
end
3.定时器应用实验
org0
movtmod,#01h
setbtr0
movb,#0feh
loop:
mova,#00h
movth0,#4ch
movtl0,#00h
wait:
jbctf0,next
sjmpwait
next:
movth0,#4ch
movtl0,#00h
inca
cjnea,#20,wait
/*cplp3.5*/
movp1,b
mova,b
rla
movb,a
clra
sjmploop
end
4.LED数码管显示实验
/*a1equ8000h
a2equ8100h
a3equ8200h
a4equ8300h
led1equ0afh
led2equ88h
led3equ0afh
led4equ86h
org0
movdptr,#a1
mova,#led1
movx@dptr,a
movdptr,#a2
mova,#led2
movx@dptr,a
movdptr,#a3
mova,#led3
movx@dptr,a
movdptr,#a4
mova,#led4
movx@dptr,a*/
/*org0
countequ30h
movcount,#00h
ljmpmain
org0100h
main:
mova,count
movb,#10
divab
xcha,b
movdptr,#tab
movca,@a+dptr
movdptr,#8300h
movx@dptr,a
mova,b
movb,#10
divab
movdptr,#tab
movca,@a+dptr
movdptr,#8100h
movx@dptr,a
mova,b
movdptr,#tab
movca,@a+dptr
movdptr,#8200h
movx@dptr,a
calldelay
inccount
sjmpmain*/
org0
countequ30h
movcount,#00h
movr5,#16
ljmpmain
org0100h
main:
mova,count
movdptr,#tab
movca,@a+dptr
movdptr,#8300h
movx@dptr,a
movdptr,#8200h
movx@dptr,a
movdptr,#8100h
movx@dptr,a
movdptr,#8000h
movx@dptr,a
calldelay
inccount
djnzr5,main
ajmp$
tab:
db88h,0afh,0c4h,86h,0a3h,92h,90h,8fh,80h,82h,81h,0b0h,0d8h,0a4h,0d0h,0d1h
delay:
movr7,#0
dl2:
movr6,#0
dl1:
nop
nop
nop
djnzr6,dl1
djnzr7,dl2
ret
end
5.计时器应用实验
org0
ljmpstart
org100h
start:
movtmod,#15h
movtl0,#0
movth0,#0
loop:
setbtr0
calldelay
clrtr0
movr6,tl0
movr7,th0
calldisplay
movtl0,#0
movth0,#0
sjmpstart
delay:
mova,#0
movth1,#4ch
movtl1,#00h
setbtr1
wait:
jbctf1,work
sjmpwait
work:
movth1,#4ch
movtl1,#00h
clrtf1
inca
cjnea,#20,wait
cplp1.0
clra
ret
display:
mov30h,r7
mov31h,r6
movr2,#16
clra
movr3,a
movr4,a
movr5,a
loop3:
clrc
mova,31h
rlca
mov31h,a
mova,30h
rlca
mov30h,a
mova,r5
addca,r5
daa
movr5,a
mova,r4
addca,r4
daa
movr4,a
mova,r3
addca,r3
daa
movr3,a
djnzr2,loop3
mova,r4
anla,#0f0h
swapa
movdptr,#tab
movca,@a+dptr
movdptr,#8000h
movx@dptr,a
mova,r4
anla,#0fh
movdptr,#tab
movca,@a+dptr
movdptr,#8100h
movx@dptr,a
mova,r5
anla,#0f0h
swapa
movdptr,#tab
movca,@a+dptr
movdptr,#8200h
movx@dptr,a
mova,r5
anla,#0fh
movdptr,#tab
movca,@a+dptr
movdptr,#8300h
movx@dptr,a
ret
tab:
db88h,0afh,0c4h,86h,0a3h,92h,90h,8fh,80h,82h
end
6.定时中断实验
systequ30h
constequ6
org0
ljmpmain
org000bh
incsyst
reti
org0100h
main:
movsp,#60h
movie,#82h
movth0,#const
movtl0,#const
movtmod,#02h
movsyst,#0
setbtr0
movb,#0feh
loop1:
movr7,#10
loop:
mova,syst
adda,#56
jncloop
movsyst,#0
djnzr7,loop
mova,b
rla
movb,a
movp1,a
cplp3.5
sjmploop1
end
7.外部中断实验
systequ30h
syst1equ31h
constequ6
org0
ljmpmain
org0003h
ljmpint_0
org000bh
incsyst
reti
org0100h
main:
movsp,#60h
movie,#83h
movip,#02
movtcon,#01h
movth0,#const
movtl0,#const
movtmod,#22h
movsyst,#0
setbtr0
movb,#0feh
loop1:
movr7,#10
loop:
mova,syst
adda,#56
jncloop
movsyst,#0
djnzr7,loop
mova,b
rla
movb,a
movp1,a
sjmploop1
int_0:
pushacc
pushpsw
pushsyst
movp1,#0
movsyst,#0
movr6,#20
loop2:
mova,syst
adda,#56
jncloop2
movsyst,#0
djnzr6,loop2
popsyst
poppsw
popacc
reti
end
8.D/A输出实验
org0
ljmpstart
org0100h
start:
movsp,#60h
movtmod,#01h
mova,#0
movdptr,#8400h
loop:
movx@dptr,a
inca
calldelay
sjmploop
delay:
pushacc
pushpsw
mova,#0
movth0,#0feh
movtl0,#98h
setbtr0
wait:
jbctf0,work
sjmpwait
work:
movth0,#0feh
movtl0,#98h
clrtf0
inca
cjnea,#20,wait
clra
poppsw
popacc
ret
end
9.A/D应用实验
org0
ljmpmain
org0100h
main:
movr0,#30h
movr7,#8
movdptr,#0800h
loop1:
mov@r0,dph
movx@dptr,a
loop:
jnbp3.3,next
sjmploop
next:
:
mov
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 实验 程序 汇总
![提示](https://static.bdocx.com/images/bang_tan.gif)