下面是一段调试成功的源程序。看看它的应答CACK子程序吧,CPU发一个数据就调用CACK,而CACK是把数据线拉低,真奇怪。
SLA DATA 50H SUBA DATA 51H NUMBYTE DATA 52H SDA BIT P3.1 SCL BIT P3.0 MTD EQU 30H MRD EQU 40H ORG 00H AJMP MAIN ORG 80H
IWRNBYTE: MOV R3,NUMBYTE LCALL START MOV A,SLA LCALL WRBYTE LCALL CACK MOV A,SUBA LCALL WRBYTE LCALL CACK MOV R1,#MTD WRDA: MOV A,@R1 LCALL WRBYTE LCALL CACK INC R1 DJNZ R3,WRDA RETWRN: LCALL STOP RET
IRDNBYTE: MOV R3,NUMBYTE LCALL START MOV A,SLA LCALL WRBYTE LCALL CACK MOV A,SUBA LCALL WRBYTE LCALL CACK LCALL START MOV A,SLA INC A LCALL WRBYTE LCALL CACK MOV R1,#MRD RON1: LCALL RDBYTE MOV @R1,A MOV P2,A LCALL DELAY DJNZ R3,SACK LCALL MNACK RETRDN: LCALL STOP RET SACK: LCALL MACK INC R1 SJMP RON1 START: SETB SDA NOP SETB SCL NOP NOP NOP NOP NOP CLR SDA NOP NOP NOP NOP CLR SCL NOP RET STOP: CLR SDA NOP NOP SETB SCL NOP NOP NOP NOP NOP SETB SDA NOP NOP NOP NOP NOP RET MACK: CLR SDA NOP NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL NOP NOP RET MNACK: SETB SDA NOP NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL NOP NOP RET CACK: CLR SDA NOP NOP SETB SCL NOP NOP NOP CLR SCL NOP NOP NOP RET WRBYTE: MOV R0,#08H WLP: RLC A JC WRI SJMP WRO WLP1: DJNZ R0,WLP NOP RET WRI: SETB SDA NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL SJMP WLP1 WRO: CLR SDA NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL SJMP WLP1
RDBYTE: MOV R0,#08H RLP: SETB SDA NOP NOP SETB SCL NOP NOP NOP MOV C,SDA MOV A,R2 CLR SCL RLC A MOV R2,A NOP NOP NOP DJNZ R0,RLP RET
MAIN: MOV R4,#0F0H DJNZ R4,$ MOV A,#00H MOV R0,#30H S1: MOV @R0,A INC R0 INC A CJNE R0,#40H,S1 MOV SLA,#0A0H MOV SUBA,#30H MOV NUMBYTE,#16 LCALL IWRNBYTE NOP MOV SLA,#0A0H MOV SUBA,#30H MOV NUMBYTE,#16 LCALL IRDNBYTE AJMP MAIN
DELAY: MOV R5,#10 D1: MOV R6,#200 D2: MOV R7,#200 DJNZ R7,$ DJNZ R6,D2 DJNZ R5,D1 RET END
程序很长,哪位仁兄给看看,先谢了。
|