我写了一段模拟I2C的程序,用S51测24C64和PCF8563的地址都有反映,惟独PCF8574没有反映.用PLC935的I2C口测PCF8574能通,表明地址无错. 不知道问题出在哪里了,是PCF8574的时序比较特殊吗? 我的程序如下,希望有经验的朋友指点指点. ACK BIT 10H SLA DATA 50H SUBA DATA 51H NUMBYTE DATA 52H SDA BIT P3.5 SCL BIT P3.4 MTD EQU 30H MRD EQU 40H PCF8574 EQU 4AH AT24C64 EQU 0AAH ORG 0000H AJMP MAIN ORG 0080H MAIN: MOV R4,#0F0H DJNZ R4,$
WRPCF8574:
IWRBYTE: MOV A,#4AH IWBLOOP: LCALL START LCALL WRBYTE LCALL CACK JB ACK,RETWRB MOV A,#00H LCALL WRBYTE LCALL CACK LCALL STOP RET RETWRB: POP A LCALL STOP ; LCALL WRONG
SJMP $ WRONG: SJMP $ START: SETB SDA NOP NOP SETB SCL NOP NOP NOP NOP NOP NOP CLR SDA NOP NOP NOP NOP NOP NOP CLR SCL RET STOP: CLR SDA NOP SETB SCL NOP NOP NOP NOP NOP SETB SDA NOP NOP NOP NOP RET CACK:
SETB SDA NOP NOP SETB SCL NOP NOP CLR ACK JNB SDA,CEND SETB ACK CEND: NOP CLR SCL RET WRBYTE: MOV R0,#08H WLP: RLC A JC WR1 CLR SDA SJMP SENT
WR1: SETB SDA NOP SENT: NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL DJNZ R0,WLP NOP NOP RET
END
|