English
Language : 

PIC16F753 Datasheet, PDF (34/238 Pages) Microchip Technology – 14/16-Pin, Flash-Based 8-Bit CMOS Microcontrollers
PIC16F753/HV753
An example of the complete four-word write sequence
is shown in Example 3-2. The initial address is loaded
into the PMADRH and PMADRL register pair; the four
words of data are loaded using indirect addressing.
EXAMPLE 3-2: WRITING TO FLASH PROGRAM MEMORY
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This write routine assumes the following:
;
A valid starting address (the least significant bits = '00')
;
is loaded in ADDRH:ADDRL
;
ADDRH, ADDRL and DATADDR are all located in data memory
;
BANKSEL
PMADRH
MOVF ADDRH,W
;Load initial address
MOVWF PMADRH
;
MOVF ADDRL,W
;
MOVWF PMADRL
;
MOVF DATAADDR,W ;Load initial data address
MOVWF FSR
;
LOOP MOVF INDF,W
;Load first data byte into lower
MOVWF PMDATL
;
INCF FSR,F
;Next byte
MOVF INDF,W
;Load second data byte into upper
MOVWF PMDATH
;
INCF FSR,F
;
BANKSEL PMCON1
BSF
PMCON1,WREN ;Enable writes
BCF
INTCON,GIE ;Disable interrupts (if using)
BTFSC INTCON,GIE ;See AN576
GOTO $-2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
Required Sequence
MOVLW 55h
;Start of required write sequence:
MOVWF PMCON2
;Write 55h
MOVLW 0AAh
;
MOVWF PMCON2
;Write 0AAh
BSF
PMCON1,WR ;Set WR bit to begin write
NOP
;Required to transfer data to the buffer
NOP
;registers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BCF
PMCON1,WREN ;Disable writes
BSF
INTCON,GIE ;Enable interrupts (comment out if not using interrupts)
BANKSEL PMADRL
MOVF PMADRL, W
INCF PMADRL,F
;Increment address
ANDLW 0x03
;Indicates when sixteen words have been programmed
SUBLW 0x03
;Change value for different size write blocks
;0x0F = 16 words
;0x0B = 12 words
;0x07 = 8 words
;0x03 = 4 words
BTFSS STATUS,Z
;Exit on a match,
GOTO LOOP
;Continue if more data needs to be written
DS40001709A-page 34
Preliminary
 2013 Microchip Technology Inc.