微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > PIC单片机的I2C应用程序1

PIC单片机的I2C应用程序1

时间:02-24 来源:互联网 点击:

;---------------------------------------------------------------------
; WriteI2C
;---------------------------------------------------------------------

WriteI2C
banksel SSPSTAT
btfsc SSPSTAT,BF ; Is the buffer full?
goto WriteI2C ; Yes, keep waiting.
banksel SSPCON ; No, continue.
DoI2CWrite
bcf SSPCON,WCOL ; Clear the WCOL flag.
movwf SSPBUF ; Write the byte in WREG
btfsc SSPCON,WCOL ; Was there a write collision?
goto DoI2CWrite
bsf SSPCON,CKP ; Release the clock.
return

;---------------------------------------------------------------------
ReadI2C
;---------------------------------------------------------------------

banksel SSPBUF
movf SSPBUF,W ; Get the byte and put in WREG
return

end ; End of file

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top