'********************************************************************** '** '** eeprom.bsc : PICBsc I2C EEPROM functions '** assumes a Microchip 24...256 EEPROM at $A0 '** '** Copyright (C) 2004, Kyle A. York '** All rights reserved '** '********************************************************************** ' 'constant byte EEPROM_ADDR = $a0 ' ' external functions: ' eeprom_ready_wait(eeprom_id) : data set to 1 if ready ' eeprom_write_begin(eeprom_id, eeprom_data_addr) : begin a write ' eeprom_write(eeprom_data) : write data ' eeprom_write_end() : complete the write ' eeprom_read_begin(eeprom_id, eeprom_data_addr) : begin read ' eeprom_read(eeprom_data) : read data ' eeprom_read_end() : end read ' ' notes: ' eeprom_* names reserved ' writes must stay in a 64 byte region (they wrap) ' reads continue through memory ' byte eeprom_id word eeprom_data_addr byte eeprom_data proc eeprom_data_addr_set(eeprom_id, eeprom_data_addr) call i2c_start() call i2c_write(eeprom_id) call i2c_write(eeprom_data_addr >> 8) call i2c_write(eeprom_data_addr) end proc proc eeprom_write_begin(eeprom_id, eeprom_data_addr) call eeprom_data_addr_set(eeprom_id, eeprom_data_addr) end proc proc eeprom_write(eeprom_data) call i2c_write(eeprom_data) end proc proc eeprom_write_end() call i2c_stop() end proc proc eeprom_ready_wait() ' ' wait for the write to complete ' do call i2c_start() call i2c_write(EEPROM_ADDR) while (!i2c_ack) end proc proc eeprom_read_begin(eeprom_id, eeprom_data_addr) call eeprom_data_addr_set(eeprom_id, eeprom_data_addr) call i2c_rep_start() call i2c_write(EEPROM_ADDR + 1) end proc proc eeprom_read(eeprom_data) call i2c_read(0) eeprom_data = i2c_data end proc proc eeprom_read_end() call i2c_stop() end proc