;************************报点时钟************************* ;要求:在2,3,15分的时候各报一次 ;--------------------------------------------------------- ;建立时间:6:23 2007-6-4 ;修改时间: ;********************************************************* MUSIC.OUT EQU !P1.0 ;--------------------------------------------------------- TIMER*1*H EQU 4BH TIMER*1*L EQU 0FDH ;50mS TIME*20*50 EQU 20 ;每20个溢出,产生1S TIME*60*S EQU 60 ;1分=60秒 ;--------------------------------------------------------- MUSIC.FLAG EQU 0 ;音乐响应标志 ;--------------------------------------------------------- MUSIC_GUIDE EQU 23H ;音符指针 TIMER_50MS EQU ;50豪秒计数,倒计 TIMER_S EQU ;秒计数,倒计 TIMER_M EQU ;分钟为正计数 TIMER_MID_H EQU ;暂存 TIMER_MID_L EQU ;暂存 SP*VAL EQU ;堆栈位置 ;=======================主程序============================== MAIN-PROGRAM: MOV SP, #SP*VAL MOV TMOD, #11H MOV TH1, #TIMER*1*H MOV TL1, #TIMER*1*L SETB EA SETB ET0 SETB ET1 SETB TR1 CLR MUSIC.FLAG MOV MUSIC_GUIDE, #0 MOV TIMER_50M, #TIME*20*50 MOV TIMER_S, #TIME*60*S MAIN-PROGRAM-LOOP: JNB MUSIC.FLAG, MAIN-PROGRAM-LOOP ;----------------------------------------------------------------- ;取表TABLEM,高4位-1为音乐起始地址,低4位为音乐延时的时间,当=0则关闭音乐 ; (实际这个可以直接在表中体现,但考虑同作者保持一直,所以没有改动) ;表TABLEF为音乐内容,将装载到TH0/TL0中 ;----------------------------------------------------------------- PLAY-MUSIC-HEAD: MOV DPTR, #TABLEM MOV A, MUSIC_GUIDE MOVC A, @A+DPTR MOV B, A ANL A, #0FH JNZ PLAY-AGAIN ;-----------------------音乐播放结束---------------------------------- MOV MUSIC_GUIDE, #0 SETB MUSIC.OUT CLR MUSIC.FLAG CLR TR0 SJMP MAIN-PROGRAM-LOOP ;-----------------------确定音乐拍节----------------------------------- PLAY-AGAIN: MOV R7, A MOV A, B SWAP A ANL A, #0FH JNZ PLAY-SINGLE-SONG ;-----------------------音乐播放休止符--------------------------------- CLR TR0 SETB MUSIC.OUT LCALL MUSIC-DELAY INC MUSIC_GUIDE SJMP PLAY-MUSIC-HEAD ;-----------------------提取音乐频率----------------------------------- PLAY-SINGLE-SONG: MOV DPTR, #TABLEF DEC A RL A MOV B, A MOVC A, @A+DPTR MOV TH0, A MOV TIMER_MID_H, A MOV A, B INC A MOVC A, @A+DPTR MOV TL0, A MOV TIMER_MID_L, A SETB TR0 LCALL MUSIC-DELAY INC MUSIC_GUIDE SJMP PLAY-MUSIC-HEAD ;-----------------------音乐延时----------------------------------------- MUSIC-DELAY: MOV R1, #100 MUSIC-DELAY-1: MOV R2, #30 MUSIC-DELAY-2: MOV R3, #29 MUSIC-DELAY-3: DJNZ R3, MUSIC-DELAY-3 DJNZ R2, MUSIC-DELAY-2 DJNZ R1, MUSIC-DELAY-1 DJNZ R7, MUSIC-DELAY RET ;=======================时钟0,音乐输出==================================== TIMER-0-MUSIC-OUTPUT: MOV TH0, TIMER_MID_H MOV TL0, TIMER_MID_L CPL MUSIC.OUT RETI ;=======================时钟1,计时中断==================================== TIMER-1-COUNT-TIME: MOV TH1, #TIMER*1*H MOV TL1, #TIMER*1*L PUSH PSW PUSH A DJNZ TIMER_50MS, TIMER-1-END MOV TIMER_50MS, #TIME*20*50 DJNZ TIMER_S, TIMER-1-END MOV TIMER_S, #TIME*60*S MOV A, TIMER_M ADD A, #1 DA A MOV TIMER_M, A ;-----------------------判断输出条件--------------------------------------- CJNE A, #2, TIMER-1-NEXT-1 SETB MUSIC.FLAG SJMP TIMER-1-END TIMER-1-NEXT-1: CJNE A, #3, TIMER-1-NEXT-2 SETB MUSIC.FLAG SJMP TIMER-1-END TIMER-1-NEXT-2: CJNE A, #15H, TIMER-1-END SETB MUSIC.FLAG TIMER-1-END: POP A POP PSW RETI ;================================================================== 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 |