51單片機對SAA7113初始化和控制的程序
RET
;*******通過I2C總線讀出某一寄存器的數(shù)據(jù)*********
I2C_READ: ACALL I2C_START
MOV A, # DeviceaddressW ;調(diào)7113地址,寫入
ACALL I2C_SEND_1BYTE
ACALL CHECK_ACK
JNB I2C_ERROR, RD200
RD100: ACALL I2C_STOP
RET
RD200: MOV A, Subaddress ;調(diào)要讀的寄存器地址
ACALL I2C_SEND_1BYTE ; 發(fā)送寄存器地址字節(jié)
ACALL CHECK_ACK
JB I2C_ERROR, RD100
ACALL I2C_START ;重發(fā)起動信號
MOV A, # DeviceaddressR ;調(diào)7113地址,讀
ACALL I2C_SEND_1BYTE
ACALL CHECK_ACK
JB I2C_ERROR, RD100
ACALL I2C_RECEIVE_1BYTE ;接收讀出的數(shù)據(jù)
MOV DATA_I2C,A ;讀出數(shù)據(jù)轉(zhuǎn)存
ACALL SEND_NOACK ;發(fā)送非應(yīng)答位
ACALL I2C_STOP ;停止
RET
;***************初始化7113,配置各寄存器************************
INIT_SAA7113: MOV DPTR, #SAA7113_Subaddress
MOV R7, #28
INIT100: MOV A, #0
MOV C A, @A+DPTR
MOV Subaddress, A ;調(diào)寄存器地址
MOV A,#28
MOVC A, @A+DPTR
MOV DATA_I2C, A ;調(diào)寄存器配置數(shù)據(jù)
INC DPTR
ACALL I2C_WRITE ;配置1個寄存器
JB I2C_ERROR, INIT200
DJNZ R7,INIT100
INIT200: RET
;***************SAA7113寄存器初始化配置數(shù)據(jù)**********************
SAA7113_Subaddress:
DB 01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH,0BH,0CH,0DH,0EH
DB 0FH,10H,11H,12H,13H,15H,16H,17H,40H,58H,59H,5AH,5BH,5EH
;共28個
I2C_REG_VALUE_AI11:
DB 08H,0C0H,33H,00H,00H,0EBH,0E0H,0B8H,01H,7EH,46H,43H,01H,01H
DB 0FH,00H,0CH,0A7H,00H,00H,00H,00H,02H,00H,54H,07H,80H,00H
;*************對SAA7113某一寄存器的改寫與讀出*******************
WRITE_READ: MOV Subaddress, #0AH ; 設(shè)寄存器地址為0AH
MOV DATA_I2C, #88H ;改寄存器的值為88H
ACALL I2C_WRITE ;改寫
ACALL I2C_READ ;讀出
評論