fk0, легенда (11.11.2010 18:02, просмотров: 199) ответил AVF на вы их готовить не умеете :) (С) хотя возврат с PIC24 к PIC16F877 - в разовой поделке из надо было из того что под рукой оказалось показался садо-мазо
#include "as18f87j10.h"
global _flash_last
global _flash_last_reset
global _flash_last_end
psect lastpage,class=CODE,delta=1,reloc=2
; Algorithm:
; erase and write all pages except last two (where code stored)
; FROM PAGE N-2:
; erase write N-1 page except 128 bytes at end (where flashing func. stored)
; copy contents of last page into RAM
; FROM PAGE N-1 (last 128 bytes):
; erase and write N-2 page
; reset
; flash single page and return
; Interruts must be disabled!
; TBLPTR=last byte addr in last page
; FSR0=data to be written into page (last byte in RAM)
; PRODH=0xAA, PRODL=0x55, FSR1=EECON2, FSR2=EECON2, EECON1=0x94 (EEPGD=1, CFGS=0, WREN=1)
; --STACK: _flash_last_reset, _flash_write_chunk, FSR0, TBLPTR, _flash_last*(N-1)
_flash_last:
; at first erase whole page
L0: bsf FREE ; enable erasing
rcall write ; page where TABLAT pointer will be erased
; write whole page
movlw 16 ; 16 64-byte chunks for 1024-byte page
movwf INTCON2
; write signle 64-byte chunk
; TBLPTR=last byte addr of chunk
; FSR0=data to be written (last byte)
_flash_write_chunk:
movlw 64 ; write single chunk of 64 bytes
loop:
movff POSTDEC0, TABLAT
tblwt *-
decfsz WREG
bra loop
tblrd +* ; TABLAT points to begin of chunk
bcf FREE ; enable writing
rcall write ; chunk where TABLAT pointer will be written
tblrd *- ; at end of prev. page
decfsz INTCON2 ; next chunk?
bra _flash_write_chunk
return ; jump to _flash_last, _flash_last_clean or _flash_last_reset
write:
movf PRODL, w
movwf INDF1
movf PRODH, w
movwf INDF2
bsf WR ; page where TABLAT points will be written or erased
return
_flash_last_reset:
reset
_flash_last_end:
[ZX]