; Send all the sequence to the slave (slave address + data (OUTPUT))
SENDDATA:
; send start bit
CALL STARTBIT ; acquire bus and send slave address
; send slave address
MOV A, WRITEADD ;写入PCF8563
CALL SENDBYTE ; sets NOACK if NACK received
JB NOACK, STOPSEND ; if no acknowledge send stop
; send OUTPUT byte
MOV A, SLAVEADD
CALL SENDBYTE
MOV A, OUTPUT
CALL SENDBYTE ; sets NOACK if NACK received
STOPSEND:
CALL STOPBIT ; sends stop bit
JNB NOACK, SENDRET ; if slave sends NACK send error
SETB ERR ; sets the error flag
SENDRET:
RET
;____________________________________________________________________
; RCVDATA
; receives one or more bytes of data from an I2C slave device.
RCVDATA:
; send start bit
CALL STARTBIT ; acquire bus and send slave address
; send slave address
MOV A, READADD ;读取PCF8563的值
CALL SENDBYTE ; sets NOACK if NACK received
MOV A, SLAVEADD
CALL SENDBYTE
JB NOACK, STOPRCV ; Check for slave not responding.
CALL RCVBYTE ; Receive next data byte.
MOV INPUT,A ; Save data byte in buffer.
STOPRCV:
CALL STOPBIT
JNB NOACK, RCVRET ; if slave sends NACK send error
SETB ERR ; sets the error flag
RCVRET:
RET
SENDBYTE ; Send 8-bits in ACC to the slave
RCVBYTE; receives one byte of data from an I2C slave device
不知道这样写对不对,但是现在读出的数据都是00
先送起始位,然后是读写地址,然后是从器件内部地址,然后是数据
应该没问题吧
就是搞不定
发表时间:2004年7月28日7:55:13