;*************************************************************************** ; ; File Name :'EEPROM.asm" ; Title : ; Date : ; Version : ; Support telephone :765 287 1987 David B. VanHorn ; Support fax :765 287 1989 ; Support Email :dvanhorn@cedar.net ; Support Snail ;1104 E 13th St, Muncie IN 47302 ; Target MCU :AT90S8515 ; ;***************************************************************************; ; D E S C R I P T I O N ; ;Example code for using the onboard EEPROM including safe read and write ; ;***************************************************************************; ; M O D I F I C A T I O N H I S T O R Y ; ; ; rev. date who why ; ---- -------- --- ------------------------------------------ ; 0.01 98.11.30 dvh Creation ; ;******************************************************************** ;Here, we take each setting from SRAM or Registers, and put them into ;EEPROM for safekeeping ;******************************************************************** ; Save_Settings: push TEMP ; push TEMP2 ; ldi XL,$01 ;Pointing to the lowest cell ldi XH,$00 ;+1 (Don't use 00) ;Save pot setting lds TEMP,POT1 ; rcall Save_EE ; lds TEMP,POT2 ; rcall Save_EE ; lds TEMP,POT3 ; rcall Save_EE ; lds TEMP,POT4 ; rcall Save_EE ; lds TEMP,POT5 ; rcall Save_EE ; lds TEMP,POT6 ; rcall Save_EE ; ldi XL,$FF ;Pointing to unused memory ldi XH,$FF ; rcall Read_EE ; pop TEMP2 ; pop TEMP ; ret ; ;******************************************************************** ;Loads settings into ram, but does NOT implement them to hardware ;******************************************************************** ; Load_Settings: push TEMP ; push TEMP2 ; ldi XL,$00 ;Start at 0001, not 0000 ldi XH,$00 ; rcall Read_EE ;Dummy read ;Recall pot settings rcall Read_EE ; sts POT1,TEMP ; rcall Read_EE ; sts POT2,TEMP ; rcall Read_EE ; sts POT3,TEMP ; rcall Read_EE ; sts POT4,TEMP ; rcall Read_EE ; sts POT5,TEMP ; rcall Read_EE ; sts POT6,TEMP ; ldi XL,$FF ;Pointing to unused memory ldi XH,$FF ; rcall Read_EE ; pop TEMP2 ; pop TEMP ; ret ; ;******************************************************************** ;Put a single byte in EEPROM, safely per manual ;******************************************************************** ; Save_EE: in TEMP2,EECR ;Poll for EECR,2=0 before continuing! andi TEMP2,$02 ; brne Save_EE ; out EEARH,XH ;Point at the current cell out EEARL,XL ; out EEDR,TEMP ;Save the data sbi EECR,2 ; sbi EECR,1 ; ld TEMP,X+ ;Move the pointer. ret ; ; ;******************************************************************** ;Gets a single byte from EEPROM, safely ;******************************************************************** ; Read_EE: in TEMP2,EECR ;Poll for EECR,2=0 before continuing! andi TEMP2,$02 ; brne Read_EE ;Potential to loop forever. out EEARH,XH ;Set up the address out EEARL,XL ; sbi EECR,1 ;Set EE Read Enable in TEMP,EEDR ;Get the data ld TEMP2,X+ ;TEMP2 is junk, but the pointer is inc'd ret ; ; ;******************************************************************** .eseg ;Put this in EEPROM .db 0 ;Location 0 is unused .db $32 ;Pot 1 t0 middle .db $32 ;Pot 2 .db $32 ;and so on .db $32 ; .db $32 ; .db $32 ; .db 0 .cseg ;Back to code