PT2257立体声电子音量控制IC,采用I2C总线控制。下面是STC89C52
单片机控制
PT2257的示例程序,注意PT2257上电后需等待200ms后才可送入I2C控制信号。本程序已测试通过,并应用于某品牌卡拉OK音响系统中。
;--------------------------------
;端口及变量定义
;--------------------------------
MUSIC_SDATA EQU P2.2
MUSIC_SCLK EQU P2.1
MUSIC_VOL EQU 60H
MUSIC_VOL1 EQU 61H
COUNTER3 EQU 62H
MUSIC_CNT EQU 40H
;--------------------------------
;音量加大
;--------------------------------
MUSIC_UP:
INC MUSIC_CNT
LCALL MUSIC_PT2257
RET
;--------------------------------
;音量减小
;--------------------------------
MIC_DN:
DEC MIC_CNT
LCALL MIC_PT2257
RET
;---------------------------------
;音乐控制程序
;---------------------------------
MUSIC_PT2257:
MOV DPTR,#VOL_TAB1
MOV A,MUSIC_CNT
MOV B,#2
MUL AB
MOV R0,A
MOV A,B
ADD A,DPH
MOV DPH,A
MOV A,R0
MOVC A,@A+DPTR
MOV MUSIC_VOL,A
MOV A,R0
INC DPTR
MOVC A,@A+DPTR
MOV MUSIC_VOL1,A
LCALL START2257_MUSIC
MOV A,#88H
LCALL SEND2257_MUSIC
MOV A,MUSIC_VOL
LCALL SEND2257_MUSIC
MOV A,MUSIC_VOL1
LCALL SEND2257_MUSIC
LCALL STOP2257_MUSIC
LCALL DELAY_12M
LCALL DELAY_12M
RET
START2257_MUSIC:
SETB MUSIC_SDATA
LCALL DELAY_10
SETB MUSIC_SCLK
LCALL DELAY_10
CLR MUSIC_SDATA
LCALL DELAY_10
CLR MUSIC_SCLK
LCALL DELAY_10
RET
STOP2257_MUSIC:
CLR MUSIC_SDATA
LCALL DELAY_10
SETB MUSIC_SCLK
LCALL DELAY_10
SETB MUSIC_SDATA
RET
SEND2257_MUSIC:
MOV COUNTER3,#08H
SEND2257A_MUSIC:
RLC A
MOV MUSIC_SDATA,C
LCALL DELAY_10
SETB MUSIC_SCLK
LCALL DELAY_10
CLR MUSIC_SCLK
LCALL DELAY_10
DJNZ COUNTER3,SEND2257A_MUSIC
LCALL S_ACK2257_MUSIC
RET
S_ACK2257_MUSIC:
SETB MUSIC_SDATA
SACK2257_MUSIC:
LCALL DELAY_10
SETB MUSIC_SCLK
MOV COUNTER3,#255
SACK2257X_MUSIC:
LCALL DELAY_10
MOV C,MUSIC_SDATA
JC SACK2257X_MUSIC_LOOP
NOP
CLR MUSIC_SCLK
RET
SACK2257X_MUSIC_LOOP:
DJNZ COUNTER3,SACK2257X_MUSIC
NOP
CLR MUSIC_SCLK
RET
;-------------------------
;延时程序
;-------------------------
DELAY_10:
MOV R7,#15
DJNZ R7,$
RET
DELAY_12M:
MOV R7,#18H
DELAY_12M1:
MOV R6,#0FFH
DJNZ R6,$
DJNZ R7,DELAY_12M1
RET
;-------------------------
;PT2257,音乐音量表
;-------------------------
VOL_TAB1:
DB 0FFH,0FFH
DB 0E4H,0D9H,0E4H,0D8H,0E4H,0D7H,0E4H,0D6H,0E4H,0D5H
DB 0E4H,0D4H,0E4H,0D3H,0E4H,0D2H,0E4H,0D1H,0E4H,0D0H
DB 0E3H,0D9H,0E3H,0D8H,0E3H,0D7H,0E3H,0D6H,0E3H,0D5H
DB 0E3H,0D4H,0E3H,0D3H,0E3H,0D2H,0E3H,0D1H,0E3H,0D0H
DB 0E2H,0D9H,0E2H,0D8H,0E2H,0D7H,0E2H,0D6H,0E2H,0D5H
DB 0E2H,0D4H,0E2H,0D3H,0E2H,0D2H,0E2H,0D1H,0E2H,0D0H
DB 0E1H,0D9H,0E1H,0D8H,0E1H,0D7H,0E1H,0D6H,0E1H,0D5H
DB 0E1H,0D4H,0E1H,0D3H,0E1H,0D2H,0E1H,0D1H,0E1H,0D1H
DB 0E0H,0D9H,0E0H,0D8H,0E0H,0D7H,0E0H,0D6H,0E0H,0D5H
DB 0E0H,0D4H,0E0H,0D3H,0E0H,0D2H,0E0H,0D1H,0E0H,0D0H