i2cs.inc


Author: Jonathan Weaver, jonw0224@netscape.net
Date: 7/10/2003
Version: 1.0
Filename: i2cs.inc
Description: Software immulated I2C Slave Device. I2CPort sets I/O port for I2C. CLK sets clock pin. SDA sets data pin.

External Variable List


;external CLK CLK is a literal which determines which pin will be the clock signal
;external CLK SDA is a literal which determines which pin will be the data signal
;external cntr Temporary Counter, declare as register in main program
;external I2CPORT I2CPORT is a literal which determines which port will be used as the I2C port. Example setup for CLK = RB6 and SDA = RB7.

CLK equ 0x06
SDA equ 0x07
I2CPORT equ PORTB
;external i2csdata I2C Data byte, declare as register in main program


Procedure Heading List


I2CSGetAck
I2CSGetByte
I2CSGetStop
I2CSPutAck
I2CSPutByte
I2CSWaitStart


Procedure Descriptions


I2CSGetAck
Description:
Detects if the master sent an acknowledge. Expects: to be called when clock is low
Returns: 0x00 in WREG if Ack detected. 0xFF in WREG if Ack not detected


I2CSGetByte
Description:
Recieves a byte and sends an acknowledge. Recieved byte appears in i2csdata
Returns: 0x00 in WREG


I2CSGetStop
Description:
Tests if the next clock cycle is stop, start, or continued transmission.
Returns: If Stop detected, returns hFF in WREG. If Start detected, returns hFE in WREG. If continued transmission, recieves next byte and returns h00 in WREG. Next byte appears in i2csdata


I2CSPutAck
Description:
Send an acknowledge.
Returns: 0x00 in WREG


I2CSPutByte
Description:
Sends a byte. Expects: the byte to send to be in i2csdata.
Returns: 0x00 in WREG if Ack detected. 0xFF in WREG if Ack not detected


I2CSWaitStart
Description:
Waits for a start condition. Never returns unless Start detected and byte recieved.
Returns: 0x00 in WREG. Byte returned in i2csdata