Atmel ATmega328P Xplained Mini MEGA328P-XMINI MEGA328P-XMINI Data Sheet

Product codes
MEGA328P-XMINI
Page of 657
261
ATmega48A/PA/88A/PA/168A/PA/328/P [DATASHEET]
Atmel-8271H-AVR- ATmega-Datasheet_08/2014
;
read back and check, optional
ldi
looplo, low(PAGESIZEB);init loop variable
ldi
loophi, high(PAGESIZEB);not required for 
PAGESIZEB<=256
subi
YL, low(PAGESIZEB);restore pointer
sbci
YH, high(PAGESIZEB)
Rdloop:
lpm
r0, Z+
ld
r1, Y+
cpse
r0, r1
rjmp
Error
sbiw
loophi:looplo, 1;use subi for PAGESIZEB<=256
brne
Rdloop
;
return to RWW section
;
verify that RWW section is safe to read
Return:
in
temp1, SPMCSR
sbrs
temp1,  RWWSB
; If RWWSB is set, the RWW section is not 
ready yet
ret
;
re-enable the RWW section
ldi
spmcrval, (1<<RWWSRE) | (1<<SPMEN)
rcall
Do_spm
rjmp
Return
Do_spm:
;
check for previous SPM complete
Wait_spm:
in
temp1, SPMCSR
sbrc
temp1, SPMEN
rjmp
Wait_spm
;
input: spmcrval determines SPM action
;
disable interrupts if enabled, store status
in
temp2, SREG
cli
;
check that no EEPROM write access is present
Wait_ee:
sbic
EECR, EEPE
rjmp
Wait_ee
;
SPM timed sequence
out
SPMCSR, spmcrval
spm
;
restore SREG (to enable interrupts if originally enabled)
out
SREG, temp2
ret