' *** Program (Flash) Read/Write routines Sub ReadFlashRow(FSR2 As uInteger) ' Read 64 bytes of FLASH starting at TBLPTR into the ' RAM area -> by FSR0 ' TBLPTR must be set up, and MUST be on a 64 byte boundary Repeat 64 tblrd *+ movf TABLAT,W movwf POSTINC2 End Repeat End Sub Sub WriteFlashRow(FSR0 As uInteger) ' Write 64 bytes of FLASH starting at TBLPTR from the ' RAM area -> by FSR0 ' TBLPTR must be set up, and MUST be on a 64 byte boundary ' Takes about 4 msec at 20 mHz Dim saveGIE As uByte saveGIE = INTCON 'Save GIE ' First, erase EEPGD = 1 ' Process FLASH CFGS = 0 ' Process FLASH WREN = 1 ' Enable write FREE = 1 ' Enable Erase ' Setup for erase/write GIE = 0 ' Disable EECON2 = 0x55 EECON2 = 0xAA WR = 1 ' Start erase ' Restore GIE btfsc saveGIE.7 bsf GIE ' Write 8 blocks of 8 bytes each tblrd *- ' TBLPTR = TBLPTR - 1, since we incr 1st then access, below Repeat 8 ' Write 8 bytes to holding registers Repeat 8 TABLAT = POSTINC0 tblwt +* End Repeat EEPGD = 1 ' Process FLASH CFGS = 0 ' Process FLASH WREN = 1 ' Write enable GIE = 0 EECON2 = 0x55 EECON2 = 0xAA WR = 1 ' Restore GIE btfsc saveGIE.7 bsf GIE End Repeat WREN = 0 End Sub