OutACK:
clr P1.SDAbit ; MAKE SURE THAT THE DATA LINE IS LOW ...
jmp ClockPulse ; CLOCK OUT THE ACK CYCLE
;******************************************************************************
;** Name: GetACK
;** Description: Clock the IIC Device for ACK cycle
;** Function: This subroutine returns the sampled logic level on the SDA during
;** high clock cycle. The IIC Device holds the SDA line HIGH if
;** it does not receive the correct number of clocks or it's stuck in
;** a previously initiated write command.
;** Calls: ClockPulse
;** Input: None
;** Return Value: C = ACKnowledge bit
;** Register Usage: None
;******************************************************************************
GetACK:
setb P1.SDAbit ; FORCE SDA LINE HIGH
acall ClockPulse ; GENERATE ONE CLOCK PULSE
ret
;******************************************************************************
;** Name: ACKPoll
;** Description: Wait for an ACK from the IIC Device
;** Function: This subroutine monitors the IIC Device response
;** following a dummy write command. The program returns when it
;** either receives an ACK bit or the maximum number of tries is
;** reached.
;** Calls: Start, SlavAddr, Stop
;** Input: None
;** Return Value: C = ACKnowledge bit [=0 ACK ,=1 No ACK was received]
;** Register Usage: A, R1
;******************************************************************************
ACKPoll:
mov R1,#MaxDelay ; LOAD MAX NO. OF ACK POLLING CYCLE
ACKPollnxt:
acall Start ; START THE ACK POLL CYCLE AND
clr C ; [C=0] WRITE OPERATION BIT
acall SlavAddr ; SEND THE SLAVE ADDRESS. THEN
; MONITOR THE SDA LINE FOR AN ACK FROM
; THE IIC Device. TERMINATE THE
acall Stop ; OPERATION BY A STOP CONDITION.
jnc ACKPollExit ; EXIT IF THE ACK WAS RECEIVED
djnz R1,ACKPollnxt ; LOOP WHILE THE MAXIMUM NO. OF CYCLES
; HAVE NOT EXPIRED. ELSE RETURN WITH C=1
ACKPollExit:
ret
;******************************************************************************
;** Name: Start
;** Description: Send a start command to the IIC Device
;** Function: This subroutine generates a start condition on the bus. The start
;** condition is defined as a high-low transition on the SDA
www.ic base.c om