发表于:2008/3/31 23:32:00
#0楼
$include(STC12C5410.INC)
music_cmd equ 20H
music_play bit 20H.0
music_play_flag bit 20H.1
music_rev bit 20H.2
ENQ_JS bit 20H.4
ENQ_Load bit 20H.5
ENQ_Rd_file_Head bit 20H.6
ENQ_Play bit 20H.7
music_ID equ 24H
music_format equ 25H
music_speedH equ 26H
music_speedL equ 27H
music_nameH equ 28H
music_nameL equ 29H
sound_speedH equ 2AH
sound_speedL equ 2BH
sound_freH equ 2CH
sound_freL equ 2DH
Psound_freH equ 2EH
Psound_freL equ 2FH
sound_all_timH equ 30H
sound_all_timL equ 31H
Psound_all_timH equ 32H
Psound_all_timL equ 33H
soundH_play_timH equ 34H
soundH_play_timL equ 35H
Psound_play_timH equ 36H
Psound_play_timL equ 37H
soundH equ 3AH
soundL equ 3BH
sound_format equ 3CH
T100ms equ 3DH
T_baseH equ 3EH
T_baseL equ 3FH
T10msH equ 0D8H
T10msL equ 0F0H
ORG 0000H
ljmp 0050H
ORG 000BH
ajmp T0_interrupt
ORG 0033H
ajmp PCA_LVD_interrupt
ORG 0050H
mov SP,#50H
mov music_cmd,#0
mov Psound_freH,#16H
mov Psound_freH,#5DH
T0_init:
mov TMOD,#00000001B
mov TL0,#T10msL
mov TH0,#T10msH
mov T100ms,#10
mov T_baseH,#0
setb ET0
PCA_LVD_init:
clr CR
CLR CCF0
mov CMOD,#00000010B
mov CCON,#00000000B
mov CL,#0
mov CH,#0
mov CCAP0H,Psound_freH
mov CCAP0L,Psound_freL
mov CCAPM0,#HPLS
mov IPH,#01000000B
mov IP, #01000000B
setb EPCA_LVD
Enable_T0:
Enablt_interrupt:
setb TR0
setb EA
main_loop:
mov music_ID,#0
setb music_play
lcall play_music
cpl p2.1
ljmp main_loop
ret
play_music:
jb music_play,Start_play
//Í£Ö¹²¥·Å
dis_music_play:
clr CR
mov a,music_cmd
anl a,#00000001B
mov music_cmd,a
ret
//²¥·Å
Start_play :
jb ENQ_Rd_file_Head,music_start
Rd_music_if:
mov a,music_ID
rl a
clr acc.0
mov r0,a
mov dptr,#music_lit_Tab
movc a,@a+dptr
mov music_nameH,a
mov a,r0
inc dptr
movc a,@a+dptr
mov music_nameL,a
mov DPH,music_nameH
mov DPL,music_nameL
clr a
movc a,@a+dptr
anl a,#00001111B
rl a
clr acc.0
add a,#48
mov music_format,a
inc dptr //
clr a
movc a,@a+dptr
mov music_speedH,a
inc dptr
clr a
movc a,@a+dptr
mov music_speedL,a
mov music_nameL,DPL
mov music_nameH,DPH
clr ENQ_JS
setb ENQ_Rd_file_Head
music_start:
L198: jnb ENQ_JS, L199
ret
L199:
mov DPH,music_nameH
mov DPL,music_nameL
inc dptr
mov a,#0
movc a,@a+dptr
mov soundH,a
jz music_play_over
inc dptr
mov a,#0
movc a,@a+dptr
mov soundL,a
jnz music_play_keepUp
//µ±Ç°ÇúÆ×½áÊø
music_play_over:
setb music_rev
clr ENQ_Play
clr ENQ_Rd_file_Head
ljmp play_music
ret
music_play_keepUp:
mov a,soundL
jb acc.2, sound_PLL
sound_Div:
mov a,soundL
anl a,#00000011B
mov r4,a
jz S120
sound_Div_loop:
clr c
mov a,music_speedH
rrc a
mov sound_all_timH,a
mov a,music_speedL
rrc a
mov sound_all_timL ,a
djnz r4, sound_Div_loop
ajmp S120
sound_PLL:
mov a,soundL
anl a,#00000011B
mov r4,a
jz S120
sound_PLL_loop:
clr c
mov a,music_speedL
rlc a
mov sound_all_timL,a
mov a,music_speedH
rlc a
mov sound_all_timH ,a
djnz r4,sound_PLL_loop
//¼ÆËãÒô·ûʱ³¤
S120:
mov a,soundL
jnb acc.3, noting_FD
clr c
mov a,sound_all_timL
rlc a
mov sound_all_timL ,a
mov a,sound_all_timH
rlc a
mov sound_all_timH ,a
noting_FD:
mov a,soundL
jb acc.5,S_2
jnb acc.4, L278
clr a
mov a,sound_all_timH
rrc a
mov sound_speedH,a
mov a,sound_all_timL
rrc a
mov sound_speedL,a
ljmp L278
S_2:
mov a,soundL
jb acc.4,S_3
putong_sound:
mov a,sound_all_timH
jnz SU10
mov a,sound_all_timL
jnz SU10
mov sound_speedL,sound_all_timL
mov sound_speedH,sound_all_timH
ljmp L278
SU10:
clr c
mov a,sound_all_timL
subb a,#1
mov sound_speedL,a
mov a,sound_all_timH
subb a,#0
mov sound_speedH,a
ljmp L278
S_3:
mov sound_speedL,sound_all_timL
mov sound_speedH,sound_all_timH
L278:
mov a,soundH
anl a,#01110000b
jz sound_tim_stop
mov sound_format,music_format
mov a,soundH
jb acc.7,up_half
dec sound_format
dec sound_format
ajmp noting_up_half
up_half:
jnb acc.3,noting_up_half
inc sound_format
inc sound_format
noting_up_half:
mov a,soundH
swap a
anl a,#00000111B
mov dptr,#sound_tab
movc a,@a+dptr
rl a
clr acc.0
add a,sound_format
mov dptr, #Fre_Tab
movc a,@a+dptr
mov sound_freH,a
inc dptr
clr a
movc a,@a+dptr
mov sound_freL,a
mov a,soundH
jb acc.2,up_oct
down_oct:
mov a,soundH
anl a,#00000011B
mov r4,a
down_oct_loop:
djnz r4,ack_enq_js
clr c
mov a,sound_freL
rlc a
mov sound_freL,a
mov a,sound_freH
rlc a
mov sound_freH,a
ajmp down_oct_loop
up_oct:
mov a,soundH
anl a,#00000011B
mov r4,a
up_oct_loop:
djnz r4, ack_enq_js
clr c
mov a,sound_freH
rlc a
mov sound_freH,a
mov a,sound_freL
rlc a
mov sound_freL,a
ljmp up_oct_loop
sound_tim_stop:
mov sound_speedH,#0
mov sound_speedL,#0
ack_enq_js:
setb ENQ_JS
jb ENQ_play,Nck_enq
setb ENQ_Play
setb music_play_flag
Nck_enq:
ret
T0_interrupt:
push psw
push acc
mov psw,#10H
RDTM:
cpl p3.5
mov a,TH0
mov r0,TL0
cjne a,TH0,RDTM
mov a,#T10msL
add a,TL0
mov TL0,a
mov a,#T10msH
addc a,TH0
mov TH0,a
djnz T100ms,H158
Load_T0:
mov T100ms,#10
mov a,#1
add a,T_baseL
mov T_baseL,a
mov a,#0
addc a,T_baseH
mov T_baseH,a
H158:
jnb music_play_flag,H164
jb ENQ_Load,No_Load_Pca
jnb ENQ_JS,H164
mov Psound_play_timH,sound_speedH
mov Psound_play_timL,sound_speedL;
mov Psound_all_timH,sound_all_timH
mov Psound_all_timL,sound_all_timL
mov Psound_freH,sound_freH
mov Psound_freL,sound_freL
mov CH,#0
mov CL,#0
mov CCAP0L,Psound_freL
mov CCAP0H,Psound_freH
mov a,#2
add a,music_nameL
mov music_nameL,a
clr a
addc a,music_nameH
mov music_nameH,a
clr ENQ_JS //ÇëÇó×¼±¸Òô·ûÊý¾Ý
setb ENQ_Load //Çå³ýÒô·ûÊý¾Ý¼ÓÔØÇëÇó
No_Load_Pca:
mov a,Psound_play_timH
jnz SS_play
mov a,Psound_play_timL
jnz SS_play
//ÉùÒô²¥·Å½áÊø
clr CR
mov CL,#0
mov CH,#0
ljmp L_play
SS_play:
setb CR
mov a,Psound_play_timL
clr c
subb a,#01
mov Psound_play_timL,a
mov a,Psound_play_timH
subb a,#0
mov Psound_play_timH,a
L_play:
mov a,Psound_all_timH
JNZ LL_play
mov a,Psound_all_timL
JNZ LL_play
clr ENQ_Load
ljmp H164
LL_play:
mov a,Psound_all_timL
clr c
subb a,#01
mov Psound_all_timL,a
mov a,Psound_all_timH
subb a,#0
mov Psound_all_timH ,a
H164:
pop acc
pop psw
reti
music_cmd equ 20H
music_play bit 20H.0
music_play_flag bit 20H.1
music_rev bit 20H.2
ENQ_JS bit 20H.4
ENQ_Load bit 20H.5
ENQ_Rd_file_Head bit 20H.6
ENQ_Play bit 20H.7
music_ID equ 24H
music_format equ 25H
music_speedH equ 26H
music_speedL equ 27H
music_nameH equ 28H
music_nameL equ 29H
sound_speedH equ 2AH
sound_speedL equ 2BH
sound_freH equ 2CH
sound_freL equ 2DH
Psound_freH equ 2EH
Psound_freL equ 2FH
sound_all_timH equ 30H
sound_all_timL equ 31H
Psound_all_timH equ 32H
Psound_all_timL equ 33H
soundH_play_timH equ 34H
soundH_play_timL equ 35H
Psound_play_timH equ 36H
Psound_play_timL equ 37H
soundH equ 3AH
soundL equ 3BH
sound_format equ 3CH
T100ms equ 3DH
T_baseH equ 3EH
T_baseL equ 3FH
T10msH equ 0D8H
T10msL equ 0F0H
ORG 0000H
ljmp 0050H
ORG 000BH
ajmp T0_interrupt
ORG 0033H
ajmp PCA_LVD_interrupt
ORG 0050H
mov SP,#50H
mov music_cmd,#0
mov Psound_freH,#16H
mov Psound_freH,#5DH
T0_init:
mov TMOD,#00000001B
mov TL0,#T10msL
mov TH0,#T10msH
mov T100ms,#10
mov T_baseH,#0
setb ET0
PCA_LVD_init:
clr CR
CLR CCF0
mov CMOD,#00000010B
mov CCON,#00000000B
mov CL,#0
mov CH,#0
mov CCAP0H,Psound_freH
mov CCAP0L,Psound_freL
mov CCAPM0,#HPLS
mov IPH,#01000000B
mov IP, #01000000B
setb EPCA_LVD
Enable_T0:
Enablt_interrupt:
setb TR0
setb EA
main_loop:
mov music_ID,#0
setb music_play
lcall play_music
cpl p2.1
ljmp main_loop
ret
play_music:
jb music_play,Start_play
//Í£Ö¹²¥·Å
dis_music_play:
clr CR
mov a,music_cmd
anl a,#00000001B
mov music_cmd,a
ret
//²¥·Å
Start_play :
jb ENQ_Rd_file_Head,music_start
Rd_music_if:
mov a,music_ID
rl a
clr acc.0
mov r0,a
mov dptr,#music_lit_Tab
movc a,@a+dptr
mov music_nameH,a
mov a,r0
inc dptr
movc a,@a+dptr
mov music_nameL,a
mov DPH,music_nameH
mov DPL,music_nameL
clr a
movc a,@a+dptr
anl a,#00001111B
rl a
clr acc.0
add a,#48
mov music_format,a
inc dptr //
clr a
movc a,@a+dptr
mov music_speedH,a
inc dptr
clr a
movc a,@a+dptr
mov music_speedL,a
mov music_nameL,DPL
mov music_nameH,DPH
clr ENQ_JS
setb ENQ_Rd_file_Head
music_start:
L198: jnb ENQ_JS, L199
ret
L199:
mov DPH,music_nameH
mov DPL,music_nameL
inc dptr
mov a,#0
movc a,@a+dptr
mov soundH,a
jz music_play_over
inc dptr
mov a,#0
movc a,@a+dptr
mov soundL,a
jnz music_play_keepUp
//µ±Ç°ÇúÆ×½áÊø
music_play_over:
setb music_rev
clr ENQ_Play
clr ENQ_Rd_file_Head
ljmp play_music
ret
music_play_keepUp:
mov a,soundL
jb acc.2, sound_PLL
sound_Div:
mov a,soundL
anl a,#00000011B
mov r4,a
jz S120
sound_Div_loop:
clr c
mov a,music_speedH
rrc a
mov sound_all_timH,a
mov a,music_speedL
rrc a
mov sound_all_timL ,a
djnz r4, sound_Div_loop
ajmp S120
sound_PLL:
mov a,soundL
anl a,#00000011B
mov r4,a
jz S120
sound_PLL_loop:
clr c
mov a,music_speedL
rlc a
mov sound_all_timL,a
mov a,music_speedH
rlc a
mov sound_all_timH ,a
djnz r4,sound_PLL_loop
//¼ÆËãÒô·ûʱ³¤
S120:
mov a,soundL
jnb acc.3, noting_FD
clr c
mov a,sound_all_timL
rlc a
mov sound_all_timL ,a
mov a,sound_all_timH
rlc a
mov sound_all_timH ,a
noting_FD:
mov a,soundL
jb acc.5,S_2
jnb acc.4, L278
clr a
mov a,sound_all_timH
rrc a
mov sound_speedH,a
mov a,sound_all_timL
rrc a
mov sound_speedL,a
ljmp L278
S_2:
mov a,soundL
jb acc.4,S_3
putong_sound:
mov a,sound_all_timH
jnz SU10
mov a,sound_all_timL
jnz SU10
mov sound_speedL,sound_all_timL
mov sound_speedH,sound_all_timH
ljmp L278
SU10:
clr c
mov a,sound_all_timL
subb a,#1
mov sound_speedL,a
mov a,sound_all_timH
subb a,#0
mov sound_speedH,a
ljmp L278
S_3:
mov sound_speedL,sound_all_timL
mov sound_speedH,sound_all_timH
L278:
mov a,soundH
anl a,#01110000b
jz sound_tim_stop
mov sound_format,music_format
mov a,soundH
jb acc.7,up_half
dec sound_format
dec sound_format
ajmp noting_up_half
up_half:
jnb acc.3,noting_up_half
inc sound_format
inc sound_format
noting_up_half:
mov a,soundH
swap a
anl a,#00000111B
mov dptr,#sound_tab
movc a,@a+dptr
rl a
clr acc.0
add a,sound_format
mov dptr, #Fre_Tab
movc a,@a+dptr
mov sound_freH,a
inc dptr
clr a
movc a,@a+dptr
mov sound_freL,a
mov a,soundH
jb acc.2,up_oct
down_oct:
mov a,soundH
anl a,#00000011B
mov r4,a
down_oct_loop:
djnz r4,ack_enq_js
clr c
mov a,sound_freL
rlc a
mov sound_freL,a
mov a,sound_freH
rlc a
mov sound_freH,a
ajmp down_oct_loop
up_oct:
mov a,soundH
anl a,#00000011B
mov r4,a
up_oct_loop:
djnz r4, ack_enq_js
clr c
mov a,sound_freH
rlc a
mov sound_freH,a
mov a,sound_freL
rlc a
mov sound_freL,a
ljmp up_oct_loop
sound_tim_stop:
mov sound_speedH,#0
mov sound_speedL,#0
ack_enq_js:
setb ENQ_JS
jb ENQ_play,Nck_enq
setb ENQ_Play
setb music_play_flag
Nck_enq:
ret
T0_interrupt:
push psw
push acc
mov psw,#10H
RDTM:
cpl p3.5
mov a,TH0
mov r0,TL0
cjne a,TH0,RDTM
mov a,#T10msL
add a,TL0
mov TL0,a
mov a,#T10msH
addc a,TH0
mov TH0,a
djnz T100ms,H158
Load_T0:
mov T100ms,#10
mov a,#1
add a,T_baseL
mov T_baseL,a
mov a,#0
addc a,T_baseH
mov T_baseH,a
H158:
jnb music_play_flag,H164
jb ENQ_Load,No_Load_Pca
jnb ENQ_JS,H164
mov Psound_play_timH,sound_speedH
mov Psound_play_timL,sound_speedL;
mov Psound_all_timH,sound_all_timH
mov Psound_all_timL,sound_all_timL
mov Psound_freH,sound_freH
mov Psound_freL,sound_freL
mov CH,#0
mov CL,#0
mov CCAP0L,Psound_freL
mov CCAP0H,Psound_freH
mov a,#2
add a,music_nameL
mov music_nameL,a
clr a
addc a,music_nameH
mov music_nameH,a
clr ENQ_JS //ÇëÇó×¼±¸Òô·ûÊý¾Ý
setb ENQ_Load //Çå³ýÒô·ûÊý¾Ý¼ÓÔØÇëÇó
No_Load_Pca:
mov a,Psound_play_timH
jnz SS_play
mov a,Psound_play_timL
jnz SS_play
//ÉùÒô²¥·Å½áÊø
clr CR
mov CL,#0
mov CH,#0
ljmp L_play
SS_play:
setb CR
mov a,Psound_play_timL
clr c
subb a,#01
mov Psound_play_timL,a
mov a,Psound_play_timH
subb a,#0
mov Psound_play_timH,a
L_play:
mov a,Psound_all_timH
JNZ LL_play
mov a,Psound_all_timL
JNZ LL_play
clr ENQ_Load
ljmp H164
LL_play:
mov a,Psound_all_timL
clr c
subb a,#01
mov Psound_all_timL,a
mov a,Psound_all_timH
subb a,#0
mov Psound_all_timH ,a
H164:
pop acc
pop psw
reti