单片机2位加减乘除(参考实验范例)

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

first_ge equ 60h ;伪指令

first_shi equ 61h

second_ge equ 62h

second_shi equ 63h

result_ge equ 64h

result_shi equ 65h

result_bai equ 66h

result_qian equ 67h

al equ 68h

p_can bit 40h

c_can bit 41h

over bit 42h

org 0000h

ljmp start

org 0050h

start:mov first_ge,#0

mov first_shi,#0

mov second_ge,#0

mov second_shi,#0

mov al,#5

mov result_ge,#0

mov result_shi,#0

mov result_bai,#0

mov result_qian,#0

mov 45h,#0

mov 46h,#0

mov 35h,#0

mov 36h,#0

mov 37h,#0

mov 38h,#0

clr p_can

clr c_can

clr over

mov 10h,#0

main: lcall xianshi

mov p0,#0f0h

mov a,p0

cjne a,#0f0h,next ;判断是否有键按下

ljmp main

next: lcall delay ;延时去斗

mov p0,#0f0h

mov a,p0

cjne a,#0f0h,key_num ;确定有键按下

ljmp main

lcall xianshi

key_num:

mov p0,#0f0h ;取键值

mov a,p0

mov 20h,a

mov p0,#0fh

mov a,p0

add a,20h

mov 10h,a

wait: mov P0,#0f0h ;等键放开

mov a,P0

cjne a,#0f0h,wait

mov a,10h

lcall display

lcall xianshi

ljmp main

;============================== display: ;判断键值

cjne a,#0eeh,next1

ljmp display0

next1:cjne a,#0edh,next2

ljmp display1

next2:cjne a,#0ebh,next3

ljmp display2

next3:cjne a,#0e7h,next4

ljmp display3

next4:cjne a,#0deh,next5

ljmp display4

next5:cjne a,#0ddh,next6

ljmp display5

next6:cjne a,#0dbh,next7

ljmp display6

next7:cjne a,#0d7h,next8

ljmp display7

next8:cjne a,#0beh,next9

ljmp display8

next9:cjne a,#0bdh,nexta

ljmp display9

nexta:cjne a,#0bbh,nextb

ljmp displaya

nextb:cjne a,#0b7h,nextc

ljmp displayb

nextc:cjne a,#7eh,nextd

ljmp displayc

nextd:cjne a,#7dh,nexte

ljmp displayd

nexte:cjne a,#7bh,nextf

ljmp displaye

nextf:cjne a,#77h,wrong

ljmp displayf

wrong:ret

;===================================

display0: ;1

jb c_can,d_0_0

jb p_can,d_0_1

mov first_ge,#1

setb p_can

ret

d_0_1: mov 61h , 60h

mov 60h,#1

ret

d_0_0:

jb p_can,d_0_2

mov second_ge,#1

setb p_can

ret

d_0_2:mov 63h , 62h

mov 62h,#1

ret

display1: ;4

jb c_can,d_1_0

jb p_can,d_1_1

mov first_ge,#4

setb p_can

ret

d_1_1: mov 61h , 60h

mov 60h,#4

ret

d_1_0:

jb p_can,d_1_2

mov second_ge ,#4

setb p_can

ret

相关文档
最新文档