📄 999999自加.txt
字号:
CURR_NUM_1 EQU 30H
CURR_NUM_2 EQU 60H
CURR_NUM_3 EQU 90H;BCD
org 0000H
jmp MAIN
;*******************************************
org 0030H ;Start program from 0030H
MAIN:
mov P0,#0FFH ;Initialize the port
mov P1,#0FFH
mov P2,#0FFH
mov P3,#0FFH
mov CURR_NUM_1,#00H ;Initilize the var
mov CURR_NUM_2,#00H
mov CURR_NUM_3,#00H
clr P3.3 ;Clear the common line
MAIN_LOOP:
jb P2.7,KEY_2 ;Wait for key down,ADD
call DELAY
call NUM_ADD
jmp NEXT_LOOP
KEY_2:
jb P2.6,NEXT_LOOP
;Wait for key down,SUB
call DELAY
call NUM_SUB
jmp NEXT_LOOP
NEXT_LOOP:
call DISPLAY_NUM
jmp MAIN_LOOP
ret
;****************************************************
DISPLAY_NUM:
;A<-A/B
mov a,curr_num_1
mov b,#0AH ;(b)=10
div ab
mov r0,a
;display the low value
mov a,b
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a ;display the number
mov p2,#11111011B
call DELAY_DISP
;display the high value
mov a,r0
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a ;display the number
mov p2,#11110111B
call DELAY_DISP
;A<-A/B
mov a,curr_num_2
mov b,#0AH ;(b)=10
div ab
mov r0,a
;display the low value
mov a,b
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a ;display the number
mov p2,#11101111B
call DELAY_DISP
;display the high value
mov a,r0
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a ;display the number
mov p2,#11011111B
call DELAY_DISP
;A<-A/B
mov a,curr_num_3
mov b,#0AH ;(b)=10
div ab
mov r0,a
;display the low value
mov a,b
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a ;display the number
mov p2,#10111111B
call DELAY_DISP
;display the high value
mov a,r0
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a ;display the number
mov p2,#01111111B
call DELAY_DISP
ret
num_add:
mov a,curr_num_1
cjne a,#59,inc_num_1 ;if curr_num_1=099 then reset curr_num_1
mov curr_num_1,#00h
mov a,curr_num_2
cjne a,#59,inc_num_2 ;if curr_num_2=099 then reset curr_num_2
mov curr_num_2,#00h
mov a,curr_num_3
cjne a,#59,inc_num_3 ;if curr_num_2=099 then reset curr_num_2
mov curr_num_3,#00h
jmp num_add_exit
inc_num_3:
inc curr_num_3
inc_num_2:
;simple add 1
inc curr_num_2
inc_num_1:
;simple add 1
inc curr_num_1
num_add_exit:
ret
num_sub:
;get previce value
mov a,curr_num_1
jz num_sub_99
num_sub_1:
;simple sub 1
dec curr_num_1
jmp num_sub_exit
num_sub_99:
mov curr_num_1,#99
mov a,curr_num_2
jz num_sub_99_99
num_sub_2:
;simple sub 1
dec curr_num_2
jmp num_sub_exit
num_sub_99_99:
mov curr_num_2,#99
MOV a,curr_num_3
jz num_sub_99_99_99
num_sub_3:
dec curr_num_2
jmp num_sub_exit
num_sub_99_99_99:
mov curr_num_2,#99
num_sub_exit:
call DELAY
ret
;delay for a interval
DELAY:
mov r7,#15
DELAY_LOOP:
mov r6,#20
djnz r6,$
mov r6,#200
djnz r6,$
djnz r7,DELAY_LOOP
ret
DELAY_DISP:
mov r7,#015
DELAY_DISP_LOOP:
mov r6,#150
djnz r6,$
mov r6,#200
djnz r6,$
djnz r7,DELAY_DISP_LOOP
ret
;led code
TAB_LED:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -