单片机实验题目及答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1234,要求用按键修改数码管上的值一个按键作位选键、一个作加1键。

0000,要求实现电子钟功能,只显示分秒,按键用来校正电子钟的时间,一个按键作位选键、一个作加1键。

3、如下图所示,数码管初始显示12345678,要求用按键修改数码管上的值一个按键作位
选键、一个作加1键。

4、如下图所示,甲乙两单片机,在甲单片机上有两按键,在乙单片机上有4只数码管,初始显示1234,要求用甲单片机的按键修改乙单片机上数码管的值一个按键作位选键、一个作加1键。

信号发生器,产生频率为1K的信号,用单片机测出此信号源的频率,并将频率值用16进制的方式显示在4位数码管上。

信号,此信号频率为1K,用单片机测出此信号源的每个周期中高电平的持续时间(测脉宽),并将测脉宽值用16进制的方式显示在4位数码管上。

一、数码管+按键
disbuf0 equ 30h
disbuf1 equ 31h
disbuf2 equ 32h
disbuf3 equ 33h
ORG 0000h
ajmp main
main:
mov sp, #70h
mov disbuf0, #4
mov disbuf1, #3
mov disbuf2, #2
mov disbuf3, #1
mov r4, #0
mov r5, #0
loop:
call display
call key
ajmp loop
display:
mov p2, #-1
mov a, #disbuf0
add a, r5
mov r0, a
mov a, @r0
mov dptr, #disptab
movc a, @a+dptr
mov p0, a
mov dptr, #weitab
mov a, r5
movc a, @a+dptr
mov p2, a
inc r5
cjne r5, #4, dispok
mov r5, #0
dispok:
ret
disptab:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH
weitab:
DB 0F7H,0FBH,0FDH,0FEH
key:
jnb p3.0, key_sel
jnb p3.1, key_inc
ajmp keyok
key_sel:
inc r4
cjne r4, #4, sel_up
mov r4, #0
sel_up:
jnb p3.0, $
ajmp keyok
key_inc:
mov a, #disbuf0
add a, r4
mov r0, a
inc @r0
cjne @r0, #10, inc_up
mov @r0, #0
inc_up:
jnb p3.1, $
ajmp keyok
keyok:
ret
end
二、电子钟
buf0 EQU 30H
buf1 EQU 31H
buf2 EQU 32H
buf3 EQU 33H
count_S EQU 40H
count_M EQU 41H
ORG 0000H
Ajmp Main
ORG 001BH
Ajmp inter_T1 ;R5数码管个数
;R0,R1送地址中的值
Main: ;R2计数
CALL init_T1
MOV sp, #70H
MOV R5, #0
MOV buf0, #0
MOV buf1, #0
MOV buf2, #0
MOV buf3, #0
Loop:
CALL Display
AJMP Loop
init_T1:
MOV A, TMOD
ANL A, #0FH ;高四位清零,低四位保留ORL A, #10H
MOV TMOD, A
MOV TH1, #HIGH(-10000)
MOV TL1, #LOW(-10000)
SETB ET1
SETB EA
SETB TR1
RET
inter_T1:
PUSH ACC
PUSH PSW
INC R2
CJNE R2, #100, Wait_S
MOV R2, #0
INC count_S
MOV A, count_S
CJNE A, #60, dealnum
MOV count_S, #0
INC count_M
MOV A, count_M
CJNE A, #60, dealnum
MOV count_M, #0
dealnum:
CALL HextoBCD
Wait_s:
MOV TH1, #HIGH(-10000)
MOV TL1, #LOW(-10000)
POP PSW
POP ACC
RETI
HextoBCD:
MOV A, count_M
MOV B, #10
DIV AB
MOV buf3, A
MOV buf2, B
MOV A, count_S
MOV B, #10
DIV AB
MOV buf1, A
MOV buf0, B
RET
Display:
MOV P2,#-1
MOV A, #buf0
ADD A, R5
MOV R0, A
MOV A, @R0
MOV DPTR, #DispTab
MOVC A, @A+DPTR
MOV P0, A
MOV DPTR, #WeiTab
MOV A, R5
MOVC A, @A+DPTR
MOV P2, A
INC R5
CJNE R5, #4, Dispok
MOV R5, #0
Dispok:
RET
DispTab:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH
DB 7DH, 07H, 7FH, 6FH, 76H WeiTab:
DB 0F7H,0FBH,0FDH,0FEH
END
三、八位数码管+573
disbuf0 equ 30h
disbuf1 equ 31h
disbuf2 equ 32h
disbuf3 equ 33h
disbuf4 equ 34h
disbuf5 equ 35h
disbuf6 equ 36h
disbuf7 equ 37h
ORG 0000H
ajmp main
main: mov sp,#70h
mov disbuf0,#8
mov disbuf1,#7
mov disbuf2,#6
mov disbuf3,#5
mov disbuf4,#4
mov disbuf5,#3
mov disbuf6,#2
mov disbuf7,#1
mov r5,#0
mov r4,#0
loop: call disp
;call delay
call key
ajmp loop
disp: mov a,#disbuf0
add a,r5
mov r0,a
mov a,@r0
mov p0,#-1
setb p3.0
clr p3.0
mov dptr,#distab
movc a,@a+dptr
mov p0,a
setb p2.0
clr p2.0
mov dptr,#weitab
mov a,r5
movc a,@a+dptr
mov p0,a
setb p3.0
clr p3.0
inc r5
cjne r5,#8,disok
mov r5,#0
disok: ret
key: jnb p3.6,key_sel
jnb p3.7,key_inc
ret
key_sel: inc r4
cjne r4,#8,key_up
mov r4,#0
key_up: jnb p3.6,$
ret
key_inc: mov a,#disbuf0
add a,r4
mov r0,a
mov a,@r0
inc a
cjne a,#10,up
mov a,#0
up: jnb p3.7,$
mov @r0,a
ret
;delay: mov r7,#0fh
;l1: mov r6,#0fh
; djnz r6,$
; djnz r7,l1
; ret
distab: db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
weitab: db 07fh,0bfh,0dfh,0efh,0f7h,0fbh,0fdh,0feh
end
四、串行通信- 按键
ORG 0000H
ajmp main
main:
mov sp, #70
call init_es
loop:
call key
ajmp loop
key:
jnb P1.6, key_sel
jnb p1.7, key_inc
ajmp keyok
key_sel:
jnb p1.6, $
mov a, #01h
mov sbuf ,a
jnb ti, $
clr ti
ajmp keyok
key_inc:
jnb p1.7, $
mov a, #02h
mov sbuf, a
jnb ti, $
clr ti
keyok:ret
init_es:
mov a, tmod
anl a, #0fh
orl a, #20h
mov tmod,a
mov scon, #50h
mov th1, #(-11059200/(384*9600))
setb es
setb ea
setb tr1
ret
end
串行通信-接收
disbuf0 equ 30h
disbuf1 equ 31h
disbuf2 equ 32h
disbuf3 equ 33h
org 0000h
ajmp main
org 0023h
ajmp inter_es
main:
mov sp, #70h
mov r4, #0
mov r5, #0
mov disbuf0, #1
mov disbuf1, #2
mov disbuf2, #3
mov disbuf3, #4
call init_es
loop:
call display
ajmp loop
init_es:
mov a, tmod
anl a, #0fh
orl a, #20h
mov tmod, a
mov scon, #50h
mov th1, #(-11059200/(384*9600))
setb es
setb ea
setb tr1
ret
inter_es:
push acc
push psw
clr ri
mov a, sbuf
cjne a, #01h, next_inc
inc r4
cjne r4, #4, interok
mov r4, #0
ajmp interok
next_inc:
cjne a, #02h, interok
mov a, #disbuf0
add a, r4
mov r0, a
inc @r0
cjne @r0, #10, interok
mov @r0, #0
interok:
pop psw
pop acc
reti
display:
mov a, #disbuf0
add a, r5
mov r0, a
mov a, @r0
mov p2, #-1
mov dptr, #disptab
movc a, @a+dptr
mov p0, a
mov dptr, #weitab
mov a, r5
movc a, @a+dptr
mov p2, a
inc r5
cjne r5, #4, dispok
mov r5, #0
dispok:
ret
disptab:
db 3fh, 06h, 5bh, 4fh, 66h, 6dh, 7dh, 07h, 7fh, 6fh weitab:
db 0f7h, 0fbh, 0fdh, 0feh
end
五、测频率
disbuf0 equ 30h
disbuf1 equ 31h
disbuf2 equ 32h
disbuf3 equ 33h
org 0000h
ajmp main
org 001bh
ajmp inter_t1
main:
mov sp, #70h
call init_t1
loop:
call display
ajmp loop
init_t1:
mov tmod, #15h
mov th0, #0
mov tl0, #0
mov th1, #high(-10000)
mov tl1, #low(-10000)
setb et1
setb ea
setb tr1
setb tr0
ret
inter_t1:
push acc
push psw
inc r2
mov th1, #high(-10000)
mov tl1, #low(-10000)
cjne r2, #100, ok
mov r2, #0
clr tr0
clr tr1
call hextobcd
mov th0, #0
mov tl0, #0
setb tr1
setb tr0
ok:
pop psw
pop acc
reti
hextobcd:
mov a, th0
mov b, #16
div ab
mov disbuf3, a
mov disbuf2, b
mov a, tl0
mov b, #16
div ab
mov disbuf1, a
mov disbuf0, b
ret
display:
mov p2, #-1
mov a, #disbuf0
add a, r5
mov r0, a
mov a, @r0
mov dptr, #disptab
movc a, @a+dptr
mov p0, a
mov dptr, #weitab
mov a, r5
movc a, @a+dptr
mov p2, a
inc r5
cjne r5, #4, dispok
mov r5, #0
dispok:
ret
disptab:
DB 3fh,06h, 5bh,4fh, 66h, 6dh, 7dh, 07h, 7fh, 6fh, 77h,7CH, 49H, 51H, 79H, 71H
weitab:
DB 0F7H,0FBH,0FDH,0FEH
End
六、测脉宽
disbuf0 equ 30h
disbuf1 equ 31h
disbuf2 equ 32h
disbuf3 equ 33h
org 0000h
ajmp main
main:
mov sp, #70
call init_t1
loop:
call pulse
call display
ajmp loop
init_t1:
mov a, tmod
anl a, #0fh
orl a, #90h
mov tmod, a
ret
pulse:
mov th1, #0
mov tl1, #0
jb p3.3, $
jnb p3.3, $
setb tr1
jb p3.3, $
clr tr1
call hextobcd
hextobcd:
mov a, th1
mov b, #16
div ab
mov disbuf3, a
mov disbuf2, b
mov a, tl1
mov b, #16
div ab
mov disbuf1, a
mov disbuf0, b
ret
display:
mov p2, #-1
mov a, #disbuf0
add a, r5
mov r0, a
mov a, @r0
mov dptr, #disptab
movc a, @a+dptr
mov p0, a
mov dptr, #weitab
mov a, r5
movc a, @a+dptr
mov p2, a
inc r5
cjne r5, #4, dispok
mov r5, #0
dispok:
ret
disptab:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH
DB 7DH, 07H, 7FH, 6FH, 77H, 7CH, 49H, 5EH, 79H, 71H
WeiTab:
DB 0F7H,0FBH,0FDH,0FEH
END。

相关文档
最新文档