Вот пример, но лучше дай мыло, сброшу полный код на все
//number of 32 byte pages to erase
#define dpNumErasePages 16384/32
//number of 16 word pages to program
#define dpNumProgrammingPages 8192/16
//number of 64 byte pages to read back
#define dpNumReadPages 16384/64
#define dpSizeOfProgramRow 16
void dpProgramMemory(void)
{
unsigned long int loop;
unsigned long int data;
unsigned int hi,lo;
int32 FullAddr;
int i;
SelectLowVoltageProgramming();
//direct access to config memory
SendPic18CommandAndData(0x00,0x8EA6); //BSF EECON1, EPGD
SendPic18CommandAndData(0x00,0x8CA6); //BSF EECON1, CFGS
SendPic18CommandAndData(0x00,0x84A6); //BSF EECON1, WREN
//direct access to code memory and enable writes
SendPic18CommandAndData(0x00,0x8EA6); //BSF EECON1, EPGD
SendPic18CommandAndData(0x00,0x9CA6); //BCF EECON1, CFGS
//32 byte rows, up to 16kbytes or 8k words
//which is 512 iterations
FullAddr = 0;
for (loop=0; loop {
SetRowPointer(FullAddr);
//read the data from usb port in 16 word chunks
for (i=0; i<(dpSizeOfProgramRow-1); i++)
{
lo = UsbReadData();
hi = UsbReadData();
data = Make16(hi,lo);
SendPic18CommandAndData(0x0D,data);
}
lo = UsbReadData();
hi = UsbReadData();
data = Make16(hi,lo);
SendPic18CommandAndData(0x0f,data);
//send a NOP, but with the specific clock timing on the command
SendPic18ProgPulse();
Send2Bytes(0);
FullAddr = FullAddr + (dpSizeOfProgramRow*2);
//send back an ACK so that the progress can be monitored
UsbWriteData(0xAA);
} //of for
SendPic18CommandAndData(0x00,0x94A6); //BCF EECON1, WREN
DeselectLowVoltageProgramming();
} //of dpProgramMemory()