;----------------------时间显示(时间计数到设定时间---------------------- ;要求:时间精度到0.1S,三位整数+1位小数,同时显示3位设定的数据(时间) ;晶振:12MHz ;------------------------------------------------------------------------ ;使用TIMER0作为显示,并建立计数标志 ;在主程序中计算时间 ;------------------------------------------------------------------------ ;建立时间:1:00 2007-6-5 ;修改时间: ;======================================================================== DISPLAY*LEN EQU 7 ;7位显示 TIMER*0*H EQU 0F8H ;2mS TIMER*0*L EQU 30H ;------------------------------------------------------------------------ TIME.FLAG EQU 0 ;------------------------------------------------------------------------ DISPLAY_COUNT[11] EQU 22H ;显示位计数器 DISPLAY_COUNT_LAST EQU ;上一位的显示位 DISPLAY_UNIT(8) EQU ;0是2mS计数,其他的是显示 SP*VAL EQU ;=======================主程序=========================================== : : MOV SP, #SP*VAL MOV TMOD, #11H MOV TH0, #TIMER*0*H MOV TL0, #TIMER*0*L SETB EA SETB ET0 SETB TR0 MOV DISPLAY_COUNT, #DISPLAY*LEN MOV DISPLAY_COUNT_LAST, #0 MOV DISPLAY_UNIT(0), #50 MAIN-PROGRAM-LOOP: JNB TIME.FLAG, MAIN-PROGRAM-LOOP CLR TIME.FLAG DJNZ DISPLAY_UNIT(0), MAIN-PROGRAM-LOOP-EXIT MOV DISPLAY_UNIT(0), #50 INC DISPLAY_UNIT(1) MOV A, DISPLAY_UNIT(1) CJNE A, #10, MAIN-PROGRAM-LOOP-COMP MOV DISPLAY_UNIT(1), #0 INC DISPLAY_UNIT(2) MOV A, DISPLAY_UNIT(2) CJNE A, #10, MAIN-PROGRAM-LOOP-COMP MOV DISPLAY_UNIT(2), #0 INC DISPLAY_UNIT(3) MOV A, DISPLAY_UNIT(3) CJNE A, #10, MAIN-PROGRAM-LOOP-COMP MOV DISPLAY_UNIT(3), #0 INC DISPLAY_UNIT(4) MAIN-PROGRAM-LOOP-COMP: MOV R0, #DISPLAY_UNIT(1) MOV R1, #DISPLAY_UNIT(5) MOV R2, #3 CLR C MAIN-PROGRAM-LOOP-COMP-LOOP: MOV A, @R0 SUBB A, @R1 INC R0 INC R1 DJNZ R2, MAIN-PROGRAM-LOOP-COMP-LOOP JC MAIN-PROGRAM-LOOP-EXIT ;-----------------------满足设定要求并清零------------------------------------ MOV DISPLAY_UNIT(1), #0 MOV DISPLAY_UNIT(2), #0 MOV DISPLAY_UNIT(3), #0 MOV DISPLAY_UNIT(4), #0 MAIN-PROGRAM-LOOP-EXIT: SJMP MAIN-PROGRAM-LOOP-EXIT ;=======================显示中断=============================================== TIMER-0-DISPLAY: MOV TH0, #TIMER*0*H MOV TL0, #TIMER*0*L PUSH A PUSH PSW SETB RS0 SETB TIME.FLAG ;-----------------------清上次的显示-------------------------------------------- ;以下基本是原有的格式 ;------------------------------------------------------------------------------- MOV A, #00H MOV DPTR, #41H MOVX @DPTR, A ;-----------------------输出字段码----------------------------------------------- MOV A, #DISPLAY_UNIT(0) ADD A, DISPLAY_COUNT MOV R0, A MOV A, @R0 MOV DPTR, #42H SWAP A ORL A, #0FH MOVX @DPTR, A ;-----------------------输出位扫描---------------------------------------------- MOV DPTR, #DISPLAY-BIT-LAB MOV A, DISPLAY_COUNT MOVC A, @A+DPTR MOV DPTR, #40H MOV @DPTR, A ;-----------------------退出---------------------------------------------------- POP PSW POP A RETI ;======================显示位表================================================ DISPLAY-BIT-LAB: DB 0,没看出规律,没有硬件图,不知道了 |