Atmega128(l) – Rainbow Electronics ATmega128L User Manual
Page 276

276
ATmega128(L)
2467B–09/01
ldi
spmcrval, (1< call Do_spm ; transfer data from RAM to Flash page buffer looplo, low(PAGESIZEB) ;init loop variable ldi loophi, high(PAGESIZEB) ;not required for PAGESIZEB<=256 Wrloop: ld r0, Y+ ld r1, Y+ ldi spmcrval, (1< call Do_spm adiw ZH:ZL, 2 sbiw loophi:looplo, 2 ;use subi for PAGESIZEB<=256 brne Wrloop ; execute page write ZL, low(PAGESIZEB) ;restore pointer sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256 ldi spmcrval, (1< call Do_spm ; re-enable the RWW section spmcrval, (1< call Do_spm ; read back and check, optional 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 jmp Error sbiw loophi:looplo, 1 ;use subi for PAGESIZEB<=256 brne Rdloop ; return to RWW section Return: lds temp1, SPMCR sbrs temp1, RWWSB ; If RWWSB is set, the RWW section is not ready yet ret spmcrval, (1< call Do_spm rjmp Return Do_spm: ; check for previous SPM complete Wait_spm: lds temp1, SPMCR sbrc temp1, SPMEN rjmp Wait_spm ; input: spmcrval determines SPM action temp2, SREG cli Wait_ee: sbic EECR, EEWE rjmp Wait_ee ; SPM timed sequence SPMCR, spmcrval
ldi
subi
ldi
ldi
; verify that RWW section is safe to read
; re-enable the RWW section
ldi
; disable interrupts if enabled, store status
in
; check that no EEPROM write access is present
sts