;** ProgByte: Transfer byte from RAM buffer to IIC Device
;** SeqRead: Read multiple bytes, starting from current address pointer
;** RandomRead: Read a byte from a specific memory location
;** ACKPoll: Return when the write cycle completes.
;** OutACK: Process the acknowledge output cycle
;** GetACK: process the acknowledge from the slave device
;**
;** NOTE 1. These rountines can run at 12.0MHz, While IIC Maxspeed is 400K
;** 2. The IIC Device must based on 16-bits address, so the sequence:
;**
;** START Slave Address Address Data STOP
;** \XXXXXXXW AAAAAAAA AAAAAAAA DDDDDDDD /
;**
ACK ACK ACK ACK
;**
;******************************************************************************
;******************************************************************************
;* PROGRAM CONSTANTS
;******************************************************************************
SDAbit EQU 00H ; PORT-1 BITS FUNCTIONING AS BIDIRECTIONAL
SCLbit EQU 01H ; SERIAL DATA (SDA) AND SERIAL CLOCK OUTPUT (SCL)
MaxDelay EQU 0FFH ; NUMBER OF TIMES TO CHECK ACKNOWLEDGE POLLING
DeviceID EQU 6FH ; DEVICE SLAVE ADDRESS
; X1208\1209 SLAVE ADDRESS: 1101111B
;*******************************************************************************
;******************************************************************************
;** Name: SeqRead
;** Description: Read sequentially from the IIC Device.
;** Function: This subroutine extracts contents of the IIC Device and stores
;** them into the specified RAM buffer. The total number of bytes to
;** read should be provided along with the buffer address. This
;** routine assumes that the address pointer has already been
;** initialized using the RandomRead routine.
;**
;** Calls: Start, SlavAddr, InByte, StopRead
;** Input: R0 = RAM Buffer Base Address
;** R1 = Number of bytes to read
;** Output: None
;** Register Usage: A, R0, R1
;******************************************************************************
ORG 0300H ; IIC.ASM MAPPED IN: 300~3D2H
SeqRead:
acall Start ; START
setb c ; [C=1] READ OPERATION BIT
acall SlavAddr ; SEND THE SLAVE ADDRESS BYTE
SeqReadLoop:
acall InByte ; START READING FROM THE CURRENT ADDRESS
mov @R0,A ; TOTAL NUMBER OF BYTES TO READ OUT OF
inc R0 ; IIC Device
djnz R1,SeqReadNxt
www.ic base.c om