;EEPROM access routines for AT90S8535
EERead:			
	SBIC	EECR,EEWE	;make sure EEWE=0
	RJMP	EERead	
	OUT	EEARH,ZH	;write address in EEARH-EEARL
	OUT	EEARL,ZL	
	LDI	R16,$01		;EERE=1 - read operation
	OUT	EECR, R16	
	IN	R16,EEDR	;read data in R16
	RET		
;****************************************************************
EEWrite:			
	SBIC	EECR,EEWE	;make sure EEWE=0
	RJMP	EEWrite	
	OUT	EEARH,ZH	;write address in EEARH-EEARL
	OUT	EEARL,ZL	
	OUT	EEDR,R16	;write data to EEDR
	CLI			;disable interrupts
	LDI	R16,$04		;EEMWE=1
	OUT	EECR, R16	
	LDI	R16,$02		;EEWE=1
	OUT	EECR,R16	
	SEI			;enable interrupts
	RET		
