PIC单片机模拟I2C接口程序

PIC单片机模拟I2C接口程序

PIC单片机模拟I2C接口程序

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; File Name: i2c_low.asm

; Author: Alan G. Smith

; Purpose: This code is borrowed from Microchip with all of the fancy

; stuff taken out.

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

InitI2CBusMaster

;************************************************************

TxmtStartBit

bsf Bus_Busy ; on a start condition bus is busy

bsf STATUS, RP0 ; Select page 1

bsf _SDA ; set SDA high

bsf _SCL ; clock is high

call Delay40uSec ; This is necessary for setup time

bcf _SDA ; This gives a falling edge on SDA while clock is high call Delay47uSec ; Necessary for START HOLD time

return

;************************************************************

TxmtStopBit

bsf STATUS, RP0 ; Select page 1

bcf _SCL ; clock is low

bcf _SDA ; set SDA low

bsf _SCL ; clock is pulled up

call Delay40uSec ; Setup time for STOP condition

bsf _SDA ; rising edge on SDA while CLOCK is high

call Delay47uSec ; makes sure a START isn‘t sent immediately after a STOP

bcf Bus_Busy ; The bus isn‘t busy anymore

return

;************************************************************

AbortI2C

call TxmtStopBit ; Send a stop bit

bsf Abort ; set the abort bit

return

;************************************************************

TxmtSlaveAddr

movf SlaveAddr, w ; Move slave address to W

bcf ACK_Error ; reset Acknowledge error bit

movwf I2CData ; move W to I2C Data

bcf I2CData, LSB ; Set for write

你可能喜欢

  • 模拟I2C程序
  • 工程电路
  • MCS-51单片机
  • 轻松学习
  • SPI总线
  • 通信协议接口

PIC单片机模拟I2C接口程序相关文档

最新文档

返回顶部