CURR_NUM EQU 30H ;BCD
curr_num_1 equ 31h
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,#00H
mov curr_num_1,#00h;Initilize the var
clr P3.3 ;Clear the common line
MAIN_LOOP:
jb P2.7,next_loop ;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:
;Display the low value
mov a,CURR_NUM
anl a,#0FH
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,CURR_NUM
swap a
anl a,#0FH
mov dptr,#TAB_LED
movc a,@a+dptr
mov P0,a ;Display the number
mov P2,#11110111B
call DELAY_DISP
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mov a,curr_num_1
anl a,#0fh
mov dptr,#tab_led
movc a,@a+dptr
mov p0,a
mov p2,#11101111b
call delay_disp
mov a,CURR_NUM_1
swap a
anl a,#0FH
mov dptr,#TAB_LED
movc a,@a+dptr
mov p0,a
mov p2,#11011111b
call delay_disp
ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nUM_ADD:
mov a,CURR_NUM
cjne a,#99H,INC_NUM
;If CURR_NUM=099H,then reset CURR_NUM
mov a,#00H
mov curr_num,a
jmp NUM_ADD_3
INC_NUM:
mov a,curr_num
anl a,#0FH
cjne a,#09H,NUM_ADD_1
mov a,CURR_NUM
add a,#07H
mov curr_num,a
jmp NUM_ADD_EXIT
NUM_ADD_1:
inc curr_num
jmp num_add_exit
num_add_3:
mov a,CURR_NUM_1
cjne a,#99H,INC_NUM_1
;If CURR_NUM=099H,then reset CURR_NUM
mov a,#00H
jmp num_add_exit
inc_num_1:
mov a,curr_num_1
anl a,#0FH
cjne a,#09H,NUM_ADD_2
;If (low 4-bits)=9 ;then (high 4-bits)+1 and (low 4-bits)=0
;add a,#10H
;anl a,#0F0H
add a,#07H
mov curr_num_1,a
jmp NUM_ADD_EXIT
num_add_2:
inc curr_num_1
jmp num_add_exit
NUM_ADD_EXIT:
ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DELAY:
mov r7,#10
DELAY_LOOP:
mov r6,#20
djnz r6,$
mov r6,#20
djnz r6,$
djnz r7,DELAY_LOOP
ret
;****************************************************
DELAY_DISP:
mov r7,#20
DELAY_DISP_LOOP:
mov r6,#20
djnz r6,$
mov r6,#20
djnz r6,$
djnz r7,DELAY_DISP_LOOP
ret
;****************************************************
;LED code
TAB_LED:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
;****************************************************
END