SS EQU P0.0 ;语音片选
INT EQU P0.1
MOSI EQU P0.2;串行数据输入至语音IC
;MISO EQU P0.2;串行数据由语音IC输出
SCLK EQU P0.3;语音IC串行时钟
DATAOUT EQU P3.0
DATAIN EQU P3.1
PLAY0 EQU 30H
PLAY1 EQU 31H
PLAY2 EQU 32H
PLAYING EQU 33H
POWUPING EQU 34H
ORG 0000H
SJMP START
ORG 0030H
START:
MOV SP,#60H
mov a,#0xff
mov p3,a
sjmp zl
mov r4,#10h ;Clear Word
lcall ap7003zl
mov r4,#12h ;set R_Level2
lcall ap7003zl
mov r4,#15h ;Set R_Mode 1
lcall ap7003zl
mov r4,#0ch ;Store Word12
lcall ap7003zl
mov r4,#0dh ;Store Flag
lcall ap7003zl
mov r4,#17h ;Clear Outputs
lcall ap7003zl
zl:
jb p1.0,a1
jnb p1.0,$
ACALL STOPWRDN04
; acall delayc
a1: jb p1.1,a2
jnb p1.1,$
mov a,#00h
mov PLAY0,a
mov PLAY1,a
ACALL fY04
a2: jb p1.2,a3
jnb p1.2,$
mov a,#00h
mov PLAY0,a
mov PLAY1,a
ACALL lY04
a3: ajmp zl
sjmp $
STOPWRDN04:
MOV POWUPING,#00010000B ;送入停止信号
MOV A,POWUPING
CLR SS;P1.6
ACALL SEND
SETB SS;P1.6
RET
LY04:
ACALL POWERUP ;上电子程序
ACALL DELAY25 ;延迟子程序,至少延迟25ms
CLR SS;P1.6 ;选中ISD4004
MOV PLAY2,#10100000B ;存放SETREC 命令
MOV A,PLAY0 ;送录音地址低8 位
ACALL SEND ;调用送地址子程序
MOV A,PLAY1 ;送录音地址高8 位
ACALL SEND
MOV A,PLAY2 ;送SETPLAY 命令
ACALL SEND
SETB SS;P1.6
CLR SS;P1.6
MOV PLAYING,#10110000B ;送入录音指令
MOV A,PLAYING
ACALL SEND
SETB SS;P1.6
RET
fy04:
ACALL POWERUP ;上电子程序
ACALL DELAY25 ;延迟子程序,至少延迟25ms
CLR SS;P1.6 ;选中ISD4004
MOV PLAY2,#11100000B ;存放SETPLAY 命令
MOV A,PLAY0 ;送放音地址低8 位
ACALL SEND ;调用送地址子程序
MOV A,PLAY1 ;送放音地址高8 位
ACALL SEND
MOV A,PLAY2 ;送SETPLAY 命令
ACALL SEND
SETB SS;P1.6
CLR SS;P1.6
MOV PLAYING,#11110000B ;送入放音指令
MOV A,PLAYING
ACALL SEND
SETB SS;P1.6
RET
POWERUP: ;送上电指令子程序
MOV POWUPING,#00100000B ;送入语音芯片上电信号
MOV A,POWUPING
CLR SS;P1.6
ACALL SEND
SETB SS;P1.6
RET
SEND: ;向ISD4004 送指令,地址等的子程序
CLR MOSI
CLR SCLK;P3.2
MOV R1,#8
OUTBIT1:
CLR SCLK;P3.2 ;时钟下降
RRC A
MOV MOSI,C ;输出1 位
NOP
NOP
NOP
SETB SCLK;P3.2 ;时钟上升沿到
NOP
NOP
NOP
DJNZ R1,OUTBIT1
RET
ap7003zl: ;ap7003的指令(指令在r4)
mov a,r4
clr cy
rlc a
rlc a
rlc a
mov r4,a
clr dataout
lcall delay12ms
;--以上为起始位,拉低12ms
setb dataout
mov r2,#05h
apzl:
mov a,r4
clr cy
rlc a
mov r4,a
jc wy
wl: setb dataout;为0
lcall delay4ms
clr dataout
lcall delay8ms
sjmp apjzl
wy: setb dataout;为1
lcall delay8ms
clr dataout
lcall delay4ms
apjzl: setb dataout
djnz r2,apzl
ret
delay12ms:
mov r7,#15h
delay12ms1:
mov r6,#0ffh
djnz r6,$
djnz r7,delay12ms1
ret
delay8ms:
mov r7,#0eh
delay8ms1:
mov r6,#0ffh
djnz r6,$
djnz r7,delay8ms1
ret
delay4ms:
mov r7,#07h
delay4ms1:
mov r6,#0ffh
djnz r6,$
djnz r7,delay4ms1
ret
DELAY25:MOV R7,#0FFH
DELAY251:MOV R6,#0FFH
DJNZ R6,$
DJNZ R7,DELAY251
RET
END