CURR_NUM_H EQU 30H ;HEX CURR_NUM_M EQU 32H CURR_NUM_S EQU 33H VAR_TIMER EQU 31H ;Soft timer DAT_74164 bit P0.6 CLK_74164 bit P0.7 DIG_1 bit p0.0 DIG_2 bit p0.1 DIG_3 bit p0.2 DIG_4 bit p0.3 DIG_5 bit p0.4 DIG_6 bit p0.5 ;******************************************* org 0000H jmp MAIN org 000BH jmp interrupt_T0 ;******************************************* org 0030H ;Start program from 0030H MAIN: mov P0,#0FFH ;Initialize the port mov P1,#0FFH mov P2,#0FFH mov P3,#0FFH /*Initilize the var*/ mov CURR_NUM_H,#0 mov CURR_NUM_M,#0 mov CURR_NUM_S,#0 mov VAR_TIMER,#00H /*Initialize T0*/ mov TMOD,#01H mov TH0,#0B1H ;20ms,load number mov TL0,#0E0H setb TR0 ;Start T0 setb ET0 ;Enable T0 inerrupt setb EA ;Enable interrupt ;mov IE,#82H ;#10000010B MAIN_LOOP: call DISPLAY_NUM ;Display number jmp MAIN_LOOP ret ;**************************************************** interrupt_T0: push acc ;Pay attention to here push psw ;Reset T0,must be done ;clr TF0 ;auto clear the tag of overflow mov TH0,#0B1H ;20ms,reload number mov TL0,#0E0H inc VAR_TIMER ;Add 20ms /*If VAR_TIMER=50,then time for 1s */ mov a,VAR_TIMER cjne a,#50,INT_T0_EXIT mov VAR_TIMER,#00H call Time_Clock INT_T0_EXIT: pop psw pop acc reti ;**************************************************** DISPLAY_NUM: ;A<-A/B, mov a,CURR_NUM_S mov b,#0Ah div ab mov r0,a ;Display the low value mov a,b mov dptr,#TAB_LED movc a,@a+dptr call sendTo74164 ;Display the numbet clr DIG_6 setb DIG_5 setb DIG_4 setb DIG_3 setb DIG_2 setb DIG_1 call DELAY_DISP ;Display the high value mov a,r0 mov dptr,#TAB_LED movc a,@a+dptr call sendTo74164 ;Display the numbet clr DIG_5 setb DIG_1 setb DIG_2 setb DIG_3 setb DIG_4 setb DIG_6 call DELAY_DISP mov a,CURR_NUM_M mov b,#0Ah div ab mov r0,a ;Display the low value mov a,b mov dptr,#TAB_LED movc a,@a+dptr call sendTo74164 ;Display the numbet clr DIG_4 setb DIG_5 setb DIG_6 setb DIG_3 setb DIG_2 setb DIG_1 call DELAY_DISP ;Display the high value mov a,r0 mov dptr,#TAB_LED movc a,@a+dptr call sendTo74164 ;Display the numbet clr DIG_3 setb DIG_1 setb DIG_2 setb DIG_5 setb DIG_4 setb DIG_6 call DELAY_DISP mov a,CURR_NUM_H mov b,#0Ah div ab mov r0,a ;Display the low value mov a,b mov dptr,#TAB_LED movc a,@a+dptr call sendTo74164 ;Display the numbet clr DIG_2 setb DIG_5 setb DIG_4 setb DIG_3 setb DIG_6 setb DIG_1 call DELAY_DISP ;Display the high value mov a,r0 mov dptr,#TAB_LED movc a,@a+dptr call sendTo74164 ;Display the numbet clr DIG_1 setb DIG_5 setb DIG_2 setb DIG_3 setb DIG_4 setb DIG_6 call DELAY_DISP ret ;******************************************* ;Send data of A to chip 74LS164 sendTo74164: push 07h push acc mov r7,#08 ;send 8 bits SEND164_LOOP: clr CLK_74164 ;clear clock-line for reading data rlc a mov DAT_74164,c ;move data-bit to data-line setb CLK_74164 ;send data to 74164 djnz r7,SEND164_LOOP clr CLK_74164 ;clear clock-line for reading data pop acc pop 07h ret ;**************************************************** Time_Clock: mov a,CURR_NUM_S cjne a,#59,INC_NUM_S mov a,CURR_NUM_M mov CURR_NUM_S,#00H cjne a,#59,INC_NUM_M mov a,CURR_NUM_H mov CURR_NUM_M,#00H cjne a,#59,INC_NUM_H mov CURR_NUM_H,#00H jmp Time_EXIT INC_NUM_S: inc CURR_NUM_S jmp Time_EXIT INC_NUM_M: inc CURR_NUM_M jmp Time_EXIT INC_NUM_H: inc CURR_NUM_H Time_EXIT: ret ;**************************************************** ;**************************************************** DELAY_DISP: mov r7,#10 DELAY_DISP_LOOP: mov r6,#50 djnz r6,$ mov r6,#100 djnz r6,$ djnz r7,DELAY_DISP_LOOP ret ;**************************************************** ;**************************************************** ;LED code TAB_LED: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H ;**************************************************** END