;
; eeprom.inc: data eeprom helper functions
;
; author: Marko Kanala, raato ]a t[ mulletronic.com
;
; LICENSE
; Creative Commons Attribution-NonCommercial-ShareALike 2.5
;
; You are free:
;
; * to copy, distribute, display, and perform the work
; * to make derivative works
;
; Under the following conditions:
;
; 1. Attribution. You must attribute the work in the manner specified by the
; author or licensor.
; 2. Noncommercial. You may not use this work for commercial purposes.
; 3. Share Alike. If you alter, transform, or build upon this work, you may
; distribute the resulting work only under a license identical to this one.
;
; * For any reuse or distribution, you must make clear to others the license
; terms of this work.
; * Any of these conditions can be waived if you get permission from the
; copyright holder.
;
; Your fair use and other rights are in no way affected by the above.
;
; This is a human-readable summary of the Legal Code.
; See full license at http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode
;
; Copyright: Marko Kanala (raato@mulletronic.com).
;
;
; loads a value from eeprom address in WREG.
;
; value read should be read from EEDATA register.
;
eeprom_load:
movwf EEADR
bcf EECON1, EEPGD ; access data eeprom
bcf EECON1, CFGS ; ...
bsf EECON1, RD ; initiate read
return
;
; saves a value to eeprom.
;
; data to be written should be loaded to EEDATA register.
; eeprom address should be loaded to WREG.
eeprom_save:
movwf EEADR
bcf EECON1, EEPGD ; access data eeprom
bcf EECON1, CFGS ; ...
bsf EECON1, WREN ; enable writes
bcf INTCON, GIE ; disable interrupts
movlw 0x55 ; initiate
movwf EECON2
movlw 0xaa
movwf EECON2
bsf EECON1, WR ; ... write
eeprom_save_wait:
clrwdt
btfsc EECON1, WR ; wait for write to finish
bra eeprom_save_wait
bsf INTCON, GIE ; enable interrupts
bcf EECON1, WREN ; disable writes
return
External Labels :