[an error occurred while processing this directive]
|
;============================== H E A D E R ===================================
;SERIAL EEPROM SYSTEM LIBRARY
;Assembler: ASM-51
;Platform: AT89C51, Osc: 11059200 MHz
;Chip: AT24c64 - 64K (8192 x 8)
;Ver: 1
;Author: 507
;Date: 29/10/2004
;==============================================================================
;--- IMPORT VARIABLES ---
;SCL_PORT - clock line port
;SDA_PORT - data line port
;--- EXPORT PROCEDURES ---
;EEPROM_Read, EEPROM_Write
;--- USING RESOURCES SUMMARY ---
;hardware: 2 lines: SDA, SCL
;softawre: R1, stack: 4 bytes
;========================== P R O C E D U R E S ===============================
;IN: DPTR - source addr, R0 - destination addr, B - size
;uses: A,R0,R1,B,C, stack: 4
EEPROM_Read: lcall EEPROM_SET_ADDR
lcall I2C_Start
mov A,#10100001b ;read command
lcall I2C_SB
eer_l0: mov R1,#8
setb SDA_PORT
eer_l1: setb SCL_PORT
mov C,SDA_PORT
rlc A
clr SCL_PORT
djnz R1,eer_l1
mov @R0,A
inc R0
dec B
mov A,B
jz eer_j0
clr SDA_PORT ;acknowledge
eer_j0: setb SCL_PORT
clr SCL_PORT
jnz eer_l0
lcall I2C_Stop ;stop condition
ret
;------------------------------------------------------------------------------
;IN: DPTR - destination addr, R0 - source addr, B - size
;uses: A,R0,R1,B,DPTR,C, stack: 4
EEPROM_Write: lcall EEPROM_SET_ADDR
eew_l1: mov A,@R0
inc R0
lcall I2C_SB
djnz B,eew_j1
call EEPROM_END_WRITE
ret
eew_j1: inc DPTR
mov A,DPL
anl A,#00011111b ;up to 32 bytes
jnz eew_l1
call EEPROM_END_WRITE
ljmp EEPROM_Write
;------------------------------------------------------------------------------
;uses: A,R1,C, stack: 2
EEPROM_END_WRITE: call I2C_Stop
eeprom_ew_l0: call I2C_Start
mov A,#10100000b
lcall I2C_SB
jc eeprom_ew_l0
ret
;------------------------------------------------------------------------------
;Set data word address
;IN: DPTR - current address
;uses: A,R1,C, stack: 2
EEPROM_SET_ADDR: call I2C_Start
mov A,#10100000b
call I2C_SB
mov A,DPH ;set addr counter
call I2C_SB
mov A,DPL
call I2C_SB
ret
;------------------------------------------------------------------------------
;Init I2C
;uses: none
I2C_INIT: setb SCL_PORT
setb SDA_PORT
ret
;------------------------------------------------------------------------------
;Send start condition
;RESULT: SCL=0, SDA=0
;uses: none
I2C_START: setb SDA_PORT
setb SCL_PORT
clr SDA_PORT
clr SCL_PORT
ret
;------------------------------------------------------------------------------
;Send stop condition
;RESULT: SCL=1, SDA=1
;uses: none
I2C_STOP: clr SCL_PORT
clr SDA_PORT
setb SCL_PORT
setb SDA_PORT
ret
;------------------------------------------------------------------------------
;Send byte
;IN: ACC - byte
;RETURN: flag C = ACK BIT (0-ACK 1-NACK)
;uses: R1,C
I2C_SB: mov R1,#8
clr SCL_PORT
i2c_sb_l0: rlc A
mov SDA_PORT,C
setb SCL_PORT
clr SCL_PORT
djnz R1,i2c_sb_l0
setb SDA_PORT
setb SCL_PORT
mov C,SDA_PORT
clr SCL_PORT
ret
;------------------------------------------------------------------------------
E-mail: info@telesys.ru