;************************************************************************* ; AVR - I2C-EEPROM ; ; Copyright: ralph.dillhardt@web.de ; ; Germany-Date: 02-01-2004 ; Datei: i2c_eeprom.asm ; Microcontoller: ATmega161 mit 8MHz Taktfrequenz ; ; Ansteuerung eines 64k EEPROM - 24LC65 ; ;************************************************************************* ;-------------------------------------------------------------------------- ;AT24C64 Eeprom write 1010xxx(fix-Adr)0(write) xxx=000 ;-------------------------------------------------------------------------- i2c_write_eeprom: rcall i2c_start ;I2C Start Condition ldi i2c_buffer, 0b10100000 ;Slave addresse rcall i2c_write ;Write Slave address ldi i2c_buffer, 0b00000000 ;address1 byte rcall i2c_write ;Write address1 ldi i2c_buffer, 0b00000000 ;address0 byte rcall i2c_write ;Write address0 ldi i2c_buffer, 'P' ;data byte rcall i2c_write ;Write Data byte ldi i2c_buffer, 'a' ;data byte rcall i2c_write ;Write Data byte ldi i2c_buffer, 'r' ;data byte rcall i2c_write ;Write Data byte ldi i2c_buffer, 't' ;data byte rcall i2c_write ;Write Data byte ldi i2c_buffer, 'y' ;data byte rcall i2c_write ;Write Data byte ldi i2c_buffer, ' ' ;data byte rcall i2c_write ;Write Data byte rcall i2c_stop ;I2C Stop Condition i2c_weeprom_loop: rcall i2c_start ;I2C Start Condition ldi i2c_buffer, 0b10100000 ;Slave addresse rcall i2c_write ;Write Slave address brts i2c_weeprom_loop ;Ack Polling ret ;AT24C64 Eeprom write ende ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;AT24C64 Eeprom read 1010xxx(fix-Adr)0(write) xxx=000 ;-------------------------------------------------------------------------- i2c_read_eeproma: rcall i2c_start ;I2C Start Condition ldi i2c_buffer, 0b10100000 ;Slave addresse rcall i2c_write ;Write Slave address ldi i2c_buffer, 0b00000000 ;address1 byte rcall i2c_write ;Write address1 ldi i2c_buffer, 0b00000000 ;address0 byte rcall i2c_write ;Write address0 rcall i2c_stop ;I2C Stop Condition ret ;AT24C16 Eeprom read ende ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;AT24C64 Eeprom read 1010xxx(fix-Adr)1(read) xxx=000 ;-------------------------------------------------------------------------- i2c_read_eepromw: rcall i2c_start ;I2C Start Condition ldi i2c_buffer, 0b10100001 ;Slave addresse rcall i2c_write ;Write Slave address rcall i2c_read ;Read Data byte mov r4,i2c_buffer rcall i2c_stop ;I2C Stop Condition ret ;AT24C64 Eeprom read ende ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;AT24C64 Eeprom read 1010xxx(fix-Adr)0(write) xxx=000 ;-------------------------------------------------------------------------- i2c_read_eeprom: rcall i2c_start ;I2C Start Condition ldi i2c_buffer, 0b10100000 ;Slave addresse rcall i2c_write ;Write Slave address ldi i2c_buffer, 0b00000000 ;address1 byte rcall i2c_write ;Write address1 ldi i2c_buffer, 0b00000000 ;address0 byte rcall i2c_write ;Write address0 rcall i2c_start ;I2C Start Condition ldi i2c_buffer, 0b10100001 ;Slave addresse rcall i2c_write ;Write Slave address rcall i2c_read ;Read Data byte rcall i2c_stop ;I2C Stop Condition mov r4,i2c_buffer ret ;AT24C64 Eeprom read ende ;--------------------------------------------------------------------------