;USE BACK BUTTOM TO RETURN TO PREVIOUS PAGE ;Published in 2003 by Richard Cappels, www.projects.cappels.org Consulting Available. ;No liability assumed by the publisher. See the disclaimer at www.projects.cappels.org for details. ;Original EEPROM Drver written by Sean Ellis (see below). He did the hard part. .nolist .include "2313def.inc" .list ;This program containsI2C Routines from the Temperature Logger application ;written by sellis (Sean Ellis), Registered at AVRfreaks.net (www.avrfreaks.net) ;on January 10, 2002. ProjectID: 49. The block write routine was omitted, and remaining ;code slightly modified to be more compact in a processor with a RAM stack. ;CUSTOMIZATION AND USE: ;Pull-up resistors are required on SDA and SCL lines. See the I2C spec. for details. ;The subroutine, I2CInit, needs to be called during initialization, preferable after the I/O ;ports are initialized. I2CInit will set up the I2C I/O pins and initialize the bus. ;The EEPROM code needs to be customized to deal with the I/O pins being used and the ;processor clock speed. All constants and registers that need to be modified are found ;in the I2C Memory Driver section. Check and if necessary, change usage of I2CPORT, I2CDDR, ;and I2CPIN in the I2C routines if necessary. Also change the values of bSDA and bSCL to ;agree with the I/O bits used for SDA and SCL respectively. ;Delays to accommodate various bus speed and processor clock rates are controlled by ;the constant I2CDelayConstant. ;The device address constant (ADDR24LC64 in this case) needs to match that of the ;EEPROM being used. The 24LC64 and 24LC256 use address A0 when their address pins are tied low. ;There are two main subroutines of interest. ;WriteI2Mem writes the byte contained in register "I2WData" into the EEPROM location ;pointed to by ZH,ZL. ;ReadI2Mem reads the byte at the EEPROM location pointed to by ZH,ZL and returns the byte in ;register "temp". ;**************Start I2C Memory Driver Constants and Registers ;I2C routines written by sellin (Sean Ellis) ;temp and I2WDtata must be high registers .def DCounter = r2 ; Used for counting loops. Can be used for other things in other routines .def temp = r16 ; Return value from functions. Can be used for other things in other rotuines .def I2WData = r17 ; Write data for EEPROM reoutines ; I2C Device addressing .equ ADDR24LC64 = 0xA0 ; 'LC64, 'LC128, and 'LC256 address byte (1010 000R) .equ I2CREAD = 0x01 ; read/write bit = read .equ I2CWRITE = 0x00 ; read/write bit = write .equ I2CDelayConstant=$04 ; Constant for delay loop- change as function of uC clock frequency ; IO Port Bits .equ bSDA = 6 ;* SET THIS The bit on the I/O Port used for SDA .equ bSCL = 5 ;* SET THIS The bit on the I/O Port used for SCL .equ mSDA = (1<