; *************************************************************************** ; copyright : (C) 2025 by Martin Preuss ; email : martin@libchipcard.de ; ; *************************************************************************** ; * This file is part of the project "AqHome". * ; * Please see toplevel file COPYING of that project for license details. * ; *************************************************************************** #ifndef AQH_AVR_COMMON_EEPROM_W_H #define AQH_AVR_COMMON_EEPROM_W_H ; *************************************************************************** ; code .cseg ; --------------------------------------------------------------------------- ; Utils_WriteEepromIncr ; ; Write a byte to EEPROM (see example in ATtiny24/44/84 manual p.18). ; ; @param R16 byte to write ; @param X EEPROM Address to write to ; @return CFLAG set if data written, cleared on error ; @clobbers R17 Eeprom_WriteByte: mov r17, r16 rcall Eeprom_CheckAddr ; (r16) mov r16, r17 brcs Eeprom_WriteByte_addrOk ret Eeprom_WriteByte_addrOk: ; call routine with IRQs disabled push r15 inr r15, SREG cli rcall Eeprom_WriteByte_noirq outr SREG, r15 pop r15 sec ret Eeprom_WriteByte_noirq: ; wait for EEPROM to be ready Eeprom_WriteByte_waitLoop: .ifdef EEPE sbic EECR, EEPE ; wait for previous write to complete (if any) .else sbic EECR, EEWE ; wait for previous write to complete (if any) .endif rjmp Eeprom_WriteByte_waitLoop ; write data .ifdef EEPM1 ldi r17, (0<