请各位高手帮忙看看了,弄了很久都没弄明白为什么计时一开始准的,一个闹钟时间到后调用音乐子程序,然后回来计时就边快了。。(计时用T1,音乐子程序用T0,在T1中断服务程序里调用了音乐子程序)
ORG 0000H AJMP MAIN ORG 000BH LJMP INTT0 ORG 001BH LJMP INTT1 ORG 0100H MAIN: MOV 30H,#00H MOV 31H,#00H MOV 32H,#00H MOV 33H,#14H SETB PT0 CLR PT1
MOV TMOD,#10H MOV TL1,#00H MOV TH1,#4CH SETB ET1 SETB TR1 SETB EA AJMP $
INTT1: MOV SP,#60H PUSH PSW PUSH ACC MOV TH1,#4CH ;晶振11.0592M,50ms定时 MOV TL1,#00H DJNZ 33H,RETURN MOV 33H,#14H ;20次计满为1s INC 32H MOV A,32H CJNE A,#60,RETURN ;判断秒钟到60s MOV 32H,#00H ;到60s清零 MOV A,31H ADD A,#1 DA A MOV 31H,A
TABTIME: ;一分钟扫一次定时表,比较计时到否 PUSH PSW PUSH ACC COMPARE: MOV 20H,#00H COMP1:MOV A,20H MOV DPTR,#TABLE MOVC A,@A+DPTR CJNE A,30H,COMP2 INC 20H MOV A,20H MOVC A,@A+DPTR CJNE A,31H,COMP3 LCALL MUSIC AJMP COMP3 COMP2:INC 20H COMP3:INC 20H COMP4:MOV A,20H CJNE A,#06H,COMP1 RETURN1: POP ACC POP PSW
CJNE A,#60H,RETURN MOV 31H,#00H MOV A,30H ADD A,#1 DA A MOV 30H,A CJNE A,#24H,RETURN MOV 30H,#00H RETURN: POP ACC POP PSW RETI
MUSIC: ;音乐子程序,用T0中断 PUSH PSW PUSH ACC PUSH DPL PUSH DPH
MAIN1: MOV TMOD,#01H SETB ET0 SETB EA SETB TR0 START0: SETB P1.0 MOV 40H,#00H NEXT: MOV A,40H MOV DPTR,#TABLEM MOVC A,@A+DPTR MOV R0,A JZ ENDD ANL A,#0FH MOV R7,A MOV A,R0 SWAP A ANL A,#0FH JNZ SING CLR TR0 LJMP D1 SING: DEC A MOV 52H,A RL A MOV DPTR,#TABLEF MOVC A,@A+DPTR MOV TH0,A MOV 51H,A MOV A,52H RL A INC A MOVC A,@A+DPTR MOV TL0,A MOV 50H,A SETB TR0 D1: LCALL DELAY INC 40H LJMP NEXT ENDD: CLR TR0 LJMP EXIT
INTT0: PUSH PSW PUSH ACC MOV TL0,50H MOV TH0,51H CPL P1.0 POP ACC POP PSW RETI
DELAY:MOV R1,#100 DELAY1:MOV R2,#30 DELAY2:MOV R3,#29 DELAY3:DJNZ R3,DELAY3 DJNZ R2,DELAY2 DJNZ R1,DELAY1 DJNZ R7,DELAY RET
EXIT: POP DPH POP DPL POP ACC POP PSW RET
TABLE:DW 0002H,0003H,0015H TABLEM: DB 44H,54H,64H,44H DB 44H,54H,64H,44H DB 64H,74H,88H DB 64H,74H,88H DB 82H,92H,82H,72H,64H,44H DB 82H,92H,82H,72H,64H,44H DB 44H,84H,48H DB 44H,14H,48H DB 00H TABLEF: DW 64260,64400,64524,64580,64684,64777,64820,64898 DW 64968,65030,65058,65110,65157,65178,65217
END
|