WRITE
CALL ERASURE_A ;先擦除再写入
BCF INTCON,GIE ; Disable ints so required sequences will execute properly
BANKSEL PMADRH ; Bank 3
MOVLW 0X0B ; Load initial address
MOVWF PMADRH
MOVLW 0X00
MOVWF PMADRL
MOVLW 0X60 ; Load initial data address
MOVWF FSR0L
MOVLW 0X00 ; Load initial data address
MOVWF FSR0H
BCF PMCON1,CFGS ; Not configuration space
BSF PMCON1,WREN ; Enable writes
BSF PMCON1,LWLO ; Only Load Write Latches
WRITE_LOOP
MOVIW FSR0++ ; Load first data byte into lower
MOVWF PMDATL
MOVIW FSR0++ ; Load second data byte into upper
MOVWF PMDATH
MOVF PMADRL,W ; Check if lower bits of address are '00000'
XORLW 0x17 ; Check if we're on the last of 32 addresses
ANDLW 0x17
BTFSC STATUS,Z ; Exit if last of 32 words,
GOTO START_WRITE
MOVLW 55h ; Start of required write sequence:
MOVWF PMCON2 ; Write 55h
MOVLW 0AAh
MOVWF PMCON2 ; Write AAh
BSF PMCON1,WR ; Set WR bit to begin write
NOP ; NOP instructions are forced as processor loads program memory write latches
NOP
INCF PMADRL ; Still loading latches Increment address
GOTO WRITE_LOOP ; Write next latches
START_WRITE
BCF PMCON1,LWLO ; No more loading latches - Actually start Flash program memory write
MOVLW 55h ; Start of required write sequence:
MOVWF PMCON2 ; Write 55h
MOVLW 0AAh
MOVWF PMCON2 ; Write AAh
BSF PMCON1,WR ; Set WR bit to begin write
NOP
NOP
BCF PMCON1,WREN ; Disable writes
BANKSEL W_TEMP
CALL DELAY_RC
BSF INTCON,GIE ; Enable interrupts
RETURN |