/**
* \file progP24F.c - algorithms to program the PIC24 family of microcontrollers
* Copyright (C) 2009-2021 Alberto Maccioni
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
* or see
*/
/*
ICSP Code(KWord) EE(B) Config Code_er Row Row_wr EE_er EE_wr Conf_wr wr_seq
24F0xKAxxx HV|LV 1.375-5.5 512 00-10(8b) 4064 32 4004 4050 4004 4004 NO
24FJxxGA0xx LV 5.5-44 NO Code-2(16b) 404F 64 4001 - - 4003 NO
24FJxxGA1x/GB0x LV 11-22 NO Code-4(16b) 404F 64 4001 - - 4003 NO
xDA/GB2/GA3/GC " 22-87 " " "
(new TABLPAG)
24FJxxGB1x LV 22-87 NO Code-3(16b) 404F 64 4001 - - 4003 NO
24HJ-33FJ LV 2-88 NO 00-12/16(8b) 404F 64 4001 - - 4000 NO
24E-33E LV 11-88 NO Code-20(8b) 400F 2 4001 - - 4001 55-AA
(new TABLPAG, new algorithm)
30Fxx10-16 HV2 4-48 0-4K 00-0C(16b) 407F 32 4001 seq. 4004 4008 55-AA
30F2020-23 LV5V 2-4 NO 00-0E(16b) 407F 32 4001 - - 4008 55-AA
*/
#include "common.h"
void CheckData(int a,int b,int addr,int *err)
{
if(a!=b){
#ifdef _MSC_VER
CString str;
#endif
PrintMessage(strings[S_NL]);
PrintMessage4(strings[S_CodeVError],addr,addr,a,b); //"Error writing address %4X: written %02X, read %02X\r\n"
(*err)++;
}
}
struct ID24{
int id;
char *device;
} PIC24LIST[]={
{0x0040,"30F2010"},
{0x0041,"24HJ64GP206"},
{0x0047,"24HJ64GP210"},
{0x0049,"24HJ64GP506"},
{0x004B,"24HJ64GP510"},
{0x005D,"24HJ128GP206"},
{0x005F,"24HJ128GP210"},
{0x0061,"24HJ128GP506"},
{0x0063,"24HJ128GP510"},
{0x0065,"24HJ128GP306"},
{0x0067,"24HJ128GP310"},
{0x0071,"24HJ256GP206"},
{0x0073,"24HJ256GP210"},
{0x007B,"24HJ256GP610"},
{0x0080,"30F5011"},
{0x0081,"30F5013"},
{0x0089,"33FJ64MC506"},
{0x008A,"33FJ64MC508"},
{0x008B,"33FJ64MC510"},
{0x0091,"33FJ64MC706"},
{0x0097,"33FJ64MC710"},
{0x00A1,"33FJ128MC506"},
{0x00A3,"33FJ128MC510"},
{0x00A9,"33FJ128MC706"},
{0x00AE,"33FJ128MC708"},
{0x00AF,"33FJ128MC710"},
{0x00B7,"33FJ256MC510"},
{0x00BF,"33FJ256MC710"},
{0x00C1,"30F3012/33FJ64GP206"},
{0x00C3,"30F3013"},
{0x00CD,"33FJ64GP306"},
{0x00CF,"33FJ64GP310"},
{0x00D5,"33FJ64GP706"},
{0x00D6,"33FJ64GP708"},
{0x00D7,"33FJ64GP710"},
{0x00D9,"33FJ128GP206"},
{0x00E5,"33FJ128GP306"},
{0x00E7,"33FJ128GP310"},
{0x00ED,"33FJ128GP706"},
{0x00EE,"33FJ128GP708"},
{0x00EF,"33FJ128GP710"},
{0x00F5,"33FJ256GP506"},
{0x00F7,"33FJ256GP510"},
{0x00FF,"33FJ256GP710"},
{0x0100,"30F4012"},
{0x0101,"30F4011"},
{0x0141,"30F4013"},
{0x0160,"30F3014"},
{0x0188,"30F6010"},
{0x0192,"30F6011"},
{0x0193,"30F6012"},
{0x0197,"30F6013"},
{0x0198,"30F6014"},
{0x01C0,"30F3010"},
{0x01C1,"30F3011"},
{0x0200,"30F5015"},
{0x0201,"30F5016"},
{0x0240,"30F2011"},
{0x0241,"30F2012"},
{0x0280,"30F6015"},
{0x0281,"30F6010A"},
{0x02C0,"30F6011A"},
{0x02C1,"30F6013A"},
{0x02C2,"30F6012A"},
{0x02C3,"30F6014A"},
{0x0400,"30F2020"},
{0x0403,"30F2023"},
{0x0404,"30F1010"},
{0x0405,"24FJ64GA006"},
{0x0406,"24FJ96GA006"},
{0x0407,"24FJ128GA006"},
{0x0408,"24FJ64GA008"},
{0x0409,"24FJ96GA008"},
{0x040A,"24FJ128GA008"},
{0x040B,"24FJ64GA010"},
{0x040C,"24FJ96GA010"},
{0x040D,"24FJ128GA010"},
{0x0444,"24FJ16GA002"},
{0x0445,"24FJ32GA002"},
{0x0446,"24FJ48GA002"},
{0x0447,"24FJ64GA002"},
{0x044C,"24FJ16GA004"},
{0x044D,"24FJ32GA004"},
{0x044E,"24FJ48GA004"},
{0x044F,"24FJ64GA004"},
{0x0601,"33FJ32MC302"},
{0x0603,"33FJ32MC304"},
{0x0605,"33FJ32GP302"},
{0x0607,"33FJ32GP304"},
{0x0611,"33FJ64MC202"},
{0x0613,"33FJ64MC204"},
{0x0615,"33FJ64GP202"},
{0x0617,"33FJ64GP204"},
{0x0619,"33FJ64MC802"},
{0x061B,"33FJ64MC804"},
{0x061D,"33FJ64GP802"},
{0x061F,"33FJ64GP804"},
{0x0621,"33FJ128MC202"},
{0x0623,"33FJ128MC204"},
{0x0625,"33FJ128GP202"},
{0x0627,"33FJ128GP204"},
{0x0629,"33FJ128MC802"},
{0x062B,"33FJ128MC804"},
{0x062D,"33FJ128GP802"},
{0x062F,"33FJ128GP804"},
{0x0645,"24HJ32GP302"},
{0x0647,"24HJ32GP304"},
{0x0655,"24HJ64GP202"},
{0x0657,"24HJ64GP204"},
{0x0665,"24HJ128GP202"},
{0x0667,"24HJ128GP204"},
{0x0675,"24HJ64GP502"},
{0x0677,"24HJ64GP504"},
{0x067D,"24HJ128GP502"},
{0x067F,"24HJ128GP504"},
{0x0771,"24HJ256GP206A"},
{0x0773,"24HJ256GP210A"},
{0x077B,"24HJ256GP610A"},
{0x07B7,"33FJ256MC510A"},
{0x07BF,"33FJ256MC710A"},
{0x07F5,"33FJ256GP506A"},
{0x07F7,"33FJ256GP510A"},
{0x07FF,"33FJ256GP710A"},
{0x0800,"33FJ12MC201"},
{0x0801,"33FJ12MC202"},
{0x0802,"33FJ12GP201"},
{0x0803,"33FJ12GP202"},
{0x080A,"24HJ12GP201"},
{0x080B,"24HJ12GP202"},
{0x0C00,"33FJ06GS101"},
{0x0C01,"33FJ06GS102"},
{0x0C02,"33FJ06GS202"},
{0x0C03,"33FJ16GS502"},
{0x0C04,"33FJ16GS402"},
{0x0C05,"33FJ16GS504"},
{0x0C06,"33FJ16GS404"},
{0x0D00,"24F04KA201"},
{0x0D01,"24F16KA101"},
{0x0D02,"24F04KA200"},
{0x0D03,"24F16KA102"},
{0x0D08,"24F08KA101"},
{0x0D0A,"24F08KA102"},
{0x0F03,"33FJ16MC304"},
{0x0F07,"33FJ16GP304"},
{0x0F09,"33FJ32MC202"},
{0x0F0B,"33FJ32MC204"},
{0x0F0D,"33FJ32GP202"},
{0x0F0F,"33FJ32GP204"},
{0x0F17,"24HJ16GP304"},
{0x0F1D,"24HJ32GP202"},
{0x0F1F,"24HJ32GP204"},
{0x1001,"24FJ64GB106"},
{0x1003,"24FJ64GB108"},
{0x1007,"24FJ64GB110"},
{0x1008,"24FJ128GA106"},
{0x1009,"24FJ128GB106"},
{0x100A,"24FJ128GA100"},
{0x100B,"24FJ128GB108"},
{0x100E,"24FJ128GA110"},
{0x100F,"24FJ128GB110"},
{0x1010,"24FJ192GA106"},
{0x1011,"24FJ192GB106"},
{0x1012,"24FJ192GA108"},
{0x1013,"24FJ192GB108"},
{0x1016,"24FJ192GA110"},
{0x1017,"24FJ192GB110"},
{0x1018,"24FJ256GA106"},
{0x1019,"24FJ256GB106"},
{0x101A,"24FJ256GA108"},
{0x101B,"24FJ256GB108"},
{0x101E,"24FJ256GA110"},
{0x101F,"24FJ256GB110"},
{0x1780,"33EP512MC204"},
{0x1781,"33EP512MC202"},
{0x1783,"33EP512MC206"},
{0x1784,"33EP512MC504"},
{0x1785,"33EP512MC502"},
{0x1787,"33EP512MC506"},
{0x178F,"33EP512GP506"},
{0x1790,"24EP512MC204"},
{0x1791,"24EP512MC202"},
{0x1793,"24EP512MC206"},
{0x1798,"24EP512GP204"},
{0x1799,"24EP512GP202"},
{0x179B,"24EP512GP206"},
{0x178C,"33EP512GP504"},
{0x178D,"33EP512GP502"},
{0x1C00,"33EP32MC204"},
{0x1C01,"33EP32MC202"},
{0x1C02,"33EP32MC203"},
{0x1C04,"33EP32MC504"},
{0x1C05,"33EP32MC502"},
{0x1C06,"33EP32MC503"},
{0x1C0C,"33EP32GP504"},
{0x1C0D,"33EP32GP502"},
{0x1C0E,"33EP32GP503"},
{0x1C10,"24EP32MC204"},
{0x1C11,"24EP32MC202"},
{0x1C12,"24EP32MC203"},
{0x1C18,"24EP32GP204"},
{0x1C19,"24EP32GP202"},
{0x1C1A,"24EP32GP203"},
{0x1D20,"33EP64MC204"},
{0x1D21,"33EP64MC202"},
{0x1D22,"33EP64MC203"},
{0x1D23,"33EP64MC206"},
{0x1D24,"33EP64MC504"},
{0x1D25,"33EP64MC502"},
{0x1D26,"33EP64MC503"},
{0x1D27,"33EP64MC506"},
{0x1D2C,"33EP64GP504"},
{0x1D2D,"33EP64GP502"},
{0x1D2E,"33EP64GP503"},
{0x1D2F,"33EP64GP506"},
{0x1D30,"24EP64MC204"},
{0x1D31,"24EP64MC202"},
{0x1D32,"24EP64MC203"},
{0x1D33,"24EP64MC206"},
{0x1D38,"24EP64GP204"},
{0x1D39,"24EP64GP202"},
{0x1D3A,"24EP64GP203"},
{0x1D3B,"24EP64GP206"},
{0x1E40,"33EP128MC204"},
{0x1E41,"33EP128MC202"},
{0x1E43,"33EP128MC206"},
{0x1E44,"33EP128MC504"},
{0x1E45,"33EP128MC502"},
{0x1E47,"33EP128MC506"},
{0x1E4C,"33EP128GP504"},
{0x1E4D,"33EP128GP502"},
{0x1E4F,"33EP128GP506"},
{0x1E50,"24EP128MC204"},
{0x1E51,"24EP128MC202"},
{0x1E53,"24EP128MC206"},
{0x1E58,"24EP128GP204"},
{0x1E59,"24EP128GP202"},
{0x1E5B,"24EP128GP206"},
{0x1F60,"33EP256MC204"},
{0x1F61,"33EP256MC202"},
{0x1F63,"33EP256MC206"},
{0x1F64,"33EP256MC504"},
{0x1F65,"33EP256MC502"},
{0x1F67,"33EP256MC506"},
{0x1F6C,"33EP256GP504"},
{0x1F6D,"33EP256GP502"},
{0x1F6F,"33EP256GP506"},
{0x1F70,"24EP256MC204"},
{0x1F71,"24EP256MC202"},
{0x1F73,"24EP256MC206"},
{0x1F78,"24EP256GP204"},
{0x1F79,"24EP256GP202"},
{0x1F7B,"24EP256GP206"},
{0x4000,"33FJ32GS406"},
{0x4001,"33FJ64GS406"},
{0x4002,"33FJ32GS606"},
{0x4003,"33FJ64GS606"},
{0x4004,"33FJ32GS608"},
{0x4005,"33FJ64GS608"},
{0x4008,"33FJ32GS610"},
{0x4009,"33FJ64GS610"},
{0x4100,"24FJ128GB206"},
{0x4102,"24FJ128GB210"},
{0x4104,"24FJ256GB206"},
{0x4106,"24FJ256GB210"},
{0x4108,"24FJ128DA206"},
{0x4109,"24FJ128DA106"},
{0x410A,"24FJ128DA210"},
{0x410B,"24FJ128DA110"},
{0x410C,"24FJ256DA206"},
{0x410D,"24FJ256DA106"},
{0x410E,"24FJ256DA210"},
{0x410F,"24FJ256DA110"},
{0x4202,"24FJ32GA102"},
{0x4203,"24FJ32GB002"},
{0x4206,"24FJ64GA102"},
{0x4207,"24FJ64GB002"},
{0x420A,"24FJ32GA104"},
{0x420B,"24FJ32GB004"},
{0x420E,"24FJ64GA104"},
{0x420F,"24FJ64GB004"},
{0x46C0,"24FJ64GA306"},
{0x46C2,"24FJ128GA306"},
{0x46C4,"24FJ64GA308"},
{0x46C6,"24FJ128GA308"},
{0x46C8,"24FJ64GA310"},
{0x46CA,"24FJ128GA310"},
{0x4884,"24FJ64GC010"},
{0x4885,"24FJ128GC010"},
{0x4888,"24FJ64GC006"},
{0x4889,"24FJ128GC006"},
{0x488A,"24FJ64GC008"},
{0x488B,"24FJ128GC008"},
};
static bool PIC24_ID(int id)
{
char s[64];
int i;
for(i=0;i500){ //limit number of lines printed
strcat(aux,"(...)\r\n");
i=(dim>4)&0xF;
int EEbaseAddr=0x1000-dim2;
int newTABLPAG=options&0x100?1:0;
if(FWVersion<0x700){
PrintMessage1(strings[S_FWver2old],"0.7.0"); //"This firmware is too old. Version %s is required\r\n"
return;
}
if(entry<2&&!CheckV33Regulator()){ //except 30Fxx which is on 5V
PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board
return;
}
if(saveLog){
OpenLogFile();
fprintf(logfile,"Read24Fx(%d,%d,%d,%d,%d) (0x%X,0x%X,0x%X,0x%X,0x%X)\n",dim,dim2,options,appIDaddr,executiveArea,dim,dim2,options,appIDaddr,executiveArea);
}
dim*=2; //from words to bytes
if(dim>0x80000||dim<0){
PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n"
return;
}
if(dim2>0x4000||dim2<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
unsigned char *memExec=0;
executiveArea*=2;
if(executiveArea) memExec=(unsigned char *)malloc(executiveArea);
for(i=0;i2){ //only if separate config area
sizeCONFIG=48;
for(i=0;i<48;i++) memCONFIG[i]=0xFF;
}
if((entry==1)||(entry==2)){ //High voltage programming: 3.3V + 1.5V + R drop + margin
if(!StartHVReg(entry==2?12:6)){ //12V only for 30Fxx !!!
PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n"
return;
}
}
else StartHVReg(-1); //LVP: current limited to (5-0.7-3.6)/10k = 50uA
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=10000>>8;
bufferU[j++]=10000&0xff;
bufferU[j++]=EN_VPP_VCC; //enter program mode
bufferU[j++]=0x0;
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=WAIT_T2;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
if((entry==0)||(entry==3)){ //LVP: pulse on MCLR
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
}
else PrintMessage(strings[S_HVICSP]); //"High Voltage ICSP\r\n"
bufferU[j++]=WAIT_T3; //>10ms before key (GA3xx-GC0xx)
bufferU[j++]=TX16;
bufferU[j++]=2;
bufferU[j++]=0x4D;
bufferU[j++]=0x43;
bufferU[j++]=0x48;
bufferU[j++]=0x51;
bufferU[j++]=WAIT_T3; //min 1ms
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=30000>>8;
bufferU[j++]=30000&0xff;
bufferU[j++]=WAIT_T3; //min 25ms
if(entry==2){ //30Fx entry
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=ICSP_NOP;
}
else{
//Additional 5 clock cycles upon entering program mode
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
}
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>12)&0xF); //MOV XXXX,W6
bufferU[j++]=(appIDaddr>>4)&0xFF;
bufferU[j++]=((appIDaddr<<4)&0xF0)+6;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SIX_N;
bufferU[j++]=4;
bufferU[j++]=0x20; //MOV XXXX,W0
bufferU[j++]=0x00;
bufferU[j++]=0x00;
bufferU[j++]=0x88; //MOV W0,TABLPAG
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=0x20; //MOV 0,W6
bufferU[j++]=0x00;
bufferU[j++]=0x06;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17)!=High){ //advance page
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20;
bufferU[j++]=(i>>21)&0xFF;
bufferU[j++]=(i>>13)&0xF0;
bufferU[j++]=SIX; //MOV W0,TABLPAG
bufferU[j++]=0x88;
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17;
}
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++]
bufferU[j++]=0xBA;
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--]
bufferU[j++]=0xBA;
bufferU[j++]=0xD3;
bufferU[j++]=0xD6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
if(i2){ //config area @ 0xF80000
if(saveLog) fprintf(logfile,"\nCONFIG:\n");
bufferU[j++]=SIX_N;
bufferU[j++]=4;
bufferU[j++]=0x20; //MOV XXXX,W0
bufferU[j++]=0x0F;
bufferU[j++]=0x80;
bufferU[j++]=0x88; //MOV W0,TABLPAG
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=0x20; //MOV XXXX,W6
bufferU[j++]=0x00;
bufferU[j++]=0x06;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=FLUSH;
for(;j,W6 (base address)
bufferU[j++]=(EEbaseAddr>>4)&0xFF;
bufferU[j++]=(EEbaseAddr&0xF0)+6;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=0x04; //GOTO 0x200
bufferU[j++]=0x02;
bufferU[j++]=0x00;
for(k2=0,i=0;iDIMBUF-6||i==dim2-2){
bufferU[j++]=FLUSH;
for(;j>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=EN_VPP_VCC; //0
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j2){ //only if separate config area
PrintMessage(strings[S_ConfigMem]); //"\r\nConfig Memory:\r\n"
if(config==3||config==4||config==6){
PrintMessage1("0xF80000: FBS = 0x%02X\r\n",memCONFIG[0]);
if(config==4){ //0xF80000-16
PrintMessage1("0xF80002: FSS = 0x%02X\r\n",memCONFIG[4]);
}
PrintMessage1("0xF80004: FGS = 0x%02X\r\n",memCONFIG[8]);
PrintMessage1("0xF80006: FOSCSEL = 0x%02X\r\n",memCONFIG[12]);
PrintMessage1("0xF80008: FOSC = 0x%02X\r\n",memCONFIG[16]);
PrintMessage1("0xF8000A: FWDT = 0x%02X\r\n",memCONFIG[20]);
PrintMessage1("0xF8000C: FPOR = 0x%02X\r\n",memCONFIG[24]);
PrintMessage1("0xF8000E: FICD = 0x%02X\r\n",memCONFIG[28]);
if(config==3){ //0xF80000-10 except 02
PrintMessage1("0xF80010: FDS = 0x%02X\r\n",memCONFIG[32]);
}
else if(config==4){ //0xF80000-16
PrintMessage1("0xF80010: UID0 = 0x%02X\r\n",memCONFIG[32]);
PrintMessage1("0xF80012: UID1 = 0x%02X\r\n",memCONFIG[36]);
PrintMessage1("0xF80014: UID2 = 0x%02X\r\n",memCONFIG[40]);
PrintMessage1("0xF80016: UID3 = 0x%02X\r\n",memCONFIG[44]);
}
}
else if(config==5){ //0xF80000-0C (16 bit)
PrintMessage2("0xF80000: FOSC = 0x%02X%02X\r\n",memCONFIG[1],memCONFIG[0]);
PrintMessage2("0xF80002: FWDT = 0x%02X%02X\r\n",memCONFIG[5],memCONFIG[4]);
PrintMessage2("0xF80004: FBORPOR = 0x%02X%02X\r\n",memCONFIG[9],memCONFIG[8]);
PrintMessage2("0xF80006: FBS = 0x%02X%02X\r\n",memCONFIG[13],memCONFIG[12]);
PrintMessage2("0xF80008: FSS = 0x%02X%02X\r\n",memCONFIG[17],memCONFIG[16]);
PrintMessage2("0xF8000A: FGS = 0x%02X%02X\r\n",memCONFIG[21],memCONFIG[20]);
PrintMessage2("0xF8000C: FICD = 0x%02X%02X\r\n",memCONFIG[25],memCONFIG[24]);
}
}
else{
//last 2 program words
PrintMessage2("CONFIG1: 0x%04X\r\nCONFIG2: 0x%04X\r\n",(memCODE[dim-3]<<8)+memCODE[dim-4]\
,(memCODE[dim-7]<<8)+memCODE[dim-8]);
if(config==1){ //last 3 program words
PrintMessage1("CONFIG3: 0x%04X\r\n",(memCODE[dim-11]<<8)+memCODE[dim-12]);
}
if(config==2){ //last 4 program words
PrintMessage1("CONFIG4: 0x%04X\r\n",(memCODE[dim-15]<<8)+memCODE[dim-16]);
}
}
PrintMessage(strings[S_CodeMem]); //"\r\nCode memory:\r\n"
DisplayCODE24F(dim);
if(dim2){
PrintMessage(strings[S_EEMem]); //"\r\nEEPROM memory:\r\n"
DisplayEE24F();
}
if(executiveArea){
char s[256],t[256];
int d,valid,empty=1;
char* aux=(char*)malloc((dim/COL+1)*2*(16+COL*9));
aux[0]=0;
s[0]=0;
empty=1;
PrintMessage(strings[S_ExeMem]); //"\r\nExecutive memory:\r\n"
for(i=0;i0x100000||dim<0){
PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n"
return;
}
unsigned char *memExec=0;
executiveArea*=2;
if(executiveArea) memExec=(unsigned char *)malloc(executiveArea);
for(i=0;i>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=EN_VPP_VCC; //enter program mode
bufferU[j++]=0x0;
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=WAIT_T2;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=WAIT_T3;
bufferU[j++]=TX16;
bufferU[j++]=2;
bufferU[j++]=0x4D;
bufferU[j++]=0x43;
bufferU[j++]=0x48;
bufferU[j++]=0x51;
bufferU[j++]=WAIT_T3; //min 1ms
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=55000>>8;
bufferU[j++]=55000&0xff;
bufferU[j++]=WAIT_T3; //min 50ms
//Additional 5 clock cycles upon entering program mode
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>12)&0xF); //MOV XXXX,W6
bufferU[j++]=(appIDaddr>>4)&0xFF;
bufferU[j++]=((appIDaddr<<4)&0xF0)+6;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0xF8;
bufferU[j++]=0x87;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SIX_N;
bufferU[j++]=4;
bufferU[j++]=0x20; //MOV XXXX,W0
bufferU[j++]=0x00;
bufferU[j++]=0x00;
bufferU[j++]=0x88; //MOV W0,TABLPAG
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
bufferU[j++]=0x20; //MOV 0,W6
bufferU[j++]=0x00;
bufferU[j++]=0x06;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0xF8;
bufferU[j++]=0x87;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17)!=High){ //advance page
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20;
bufferU[j++]=(i>>21)&0xFF;
bufferU[j++]=(i>>13)&0xF0;
bufferU[j++]=SIX; //MOV W0,TABLPAG
bufferU[j++]=0x88;
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17;
}
bufferU[j++]=SIX_LONG5; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDH.B [W6++],[W7++]
bufferU[j++]=0xBA;
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_LONG5; //TBLRDH.B [++W6],[W7--]
bufferU[j++]=0xBA;
bufferU[j++]=0xD3;
bufferU[j++]=0xD6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
if(i>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=EN_VPP_VCC; //0
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j>4)&0xF;
int EEbaseAddr=0x1000-dim2;
int newTABLPAG=options&0x100000?1:0;
int err=0;
if(FWVersion<0x700){
PrintMessage1(strings[S_FWver2old],"0.7.0"); //"This firmware is too old. Version %s is required\r\n"
return;
}
if(entry<2&&!CheckV33Regulator()){ //except 30Fxx which is on 5V
PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board
return;
}
if(saveLog){
OpenLogFile();
fprintf(logfile,"Write24Fx(%d,%d,%d,%d,%d,%.1f) (0x%X,0x%X,0x%X,0x%X,0x%X,%.3f)\n"
,dim,dim2,options,appIDaddr,rowSize,wait,dim,dim2,options,appIDaddr,rowSize,wait);
}
dim*=2; //from words to bytes
if(dim>0x80000||dim<0){
PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n"
return;
}
if(dim2>0x1000||dim2<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
j=size;
if(j%(rowSize*4)){ //grow to an integer number of rows
size=(j/(rowSize*4)+1)*rowSize*4;
memCODE=(unsigned char*)realloc(memCODE,size);
for(;jsize) dim=size;
if(sizeEE<0x1000) dim2=0;
if(dim<1){
PrintMessage(strings[S_NoCode]); //"Empty code area\r\n"
return;
}
if((entry==1)||(entry==2)){ //High voltage programming: 3.3V + 1.5V + R drop + margin
if(!StartHVReg(entry==2?12:6)){ //12V only for 30Fxx !!!
PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n"
return;
}
}
else StartHVReg(-1); //LVP: current limited to (5-0.7-3.6)/10k = 50uA
if(config>2){ //only if separate config area
PrintMessage(strings[S_ConfigMem]); //"\r\nConfig Memory:\r\n"
if(config==3||config==4||config==6){
PrintMessage1("0xF80000: FBS = 0x%02X\r\n",memCONFIG[0]);
if(config==4){ //0xF80000-16
PrintMessage1("0xF80002: FSS = 0x%02X\r\n",memCONFIG[4]);
}
PrintMessage1("0xF80004: FGS = 0x%02X\r\n",memCONFIG[8]);
PrintMessage1("0xF80006: FOSCSEL = 0x%02X\r\n",memCONFIG[12]);
PrintMessage1("0xF80008: FOSC = 0x%02X\r\n",memCONFIG[16]);
PrintMessage1("0xF8000A: FWDT = 0x%02X\r\n",memCONFIG[20]);
PrintMessage1("0xF8000C: FPOR = 0x%02X\r\n",memCONFIG[24]);
PrintMessage1("0xF8000E: FICD = 0x%02X\r\n",memCONFIG[28]);
if(config==3){ //0xF80000-10 except 02
PrintMessage1("0xF80010: FDS = 0x%02X\r\n",memCONFIG[32]);
}
else if(config==4){ //0xF80000-16
PrintMessage1("0xF80010: UID0 = 0x%02X\r\n",memCONFIG[32]);
PrintMessage1("0xF80012: UID1 = 0x%02X\r\n",memCONFIG[36]);
PrintMessage1("0xF80014: UID2 = 0x%02X\r\n",memCONFIG[40]);
PrintMessage1("0xF80016: UID3 = 0x%02X\r\n",memCONFIG[44]);
}
}
else if(config==5){ //0xF80000-0C (16 bit)
PrintMessage2("0xF80000: FOSC = 0x%02X%02X\r\n",memCONFIG[1],memCONFIG[0]);
PrintMessage2("0xF80002: FWDT = 0x%02X%02X\r\n",memCONFIG[5],memCONFIG[4]);
PrintMessage2("0xF80004: FBORPOR = 0x%02X%02X\r\n",memCONFIG[9],memCONFIG[8]);
PrintMessage2("0xF80006: FBS = 0x%02X%02X\r\n",memCONFIG[13],memCONFIG[12]);
PrintMessage2("0xF80008: FSS = 0x%02X%02X\r\n",memCONFIG[17],memCONFIG[16]);
PrintMessage2("0xF8000A: FGS = 0x%02X%02X\r\n",memCONFIG[21],memCONFIG[20]);
PrintMessage2("0xF8000C: FICD = 0x%02X%02X\r\n",memCONFIG[25],memCONFIG[24]);
}
}
else{
//last 2 program words
PrintMessage2("CONFIG1: 0x%04X\r\nCONFIG2: 0x%04X\r\n",(memCODE[dim-3]<<8)+memCODE[dim-4]\
,(memCODE[dim-7]<<8)+memCODE[dim-8]);
if(config==1){ //last 3 program words
PrintMessage1("CONFIG3: 0x%04X\r\n",(memCODE[dim-11]<<8)+memCODE[dim-12]);
}
if(config==2){ //last 4 program words
PrintMessage1("CONFIG4: 0x%04X\r\n",(memCODE[dim-15]<<8)+memCODE[dim-16]);
}
}
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=2000>>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=EN_VPP_VCC; //enter program mode
bufferU[j++]=0x0;
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=WAIT_T2;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
if((entry==0)||(entry==3)){ //LVP: pulse on MCLR
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
}
else PrintMessage(strings[S_HVICSP]); //"High Voltage ICSP\r\n"
bufferU[j++]=WAIT_T3;
bufferU[j++]=TX16;
bufferU[j++]=2;
bufferU[j++]=0x4D;
bufferU[j++]=0x43;
bufferU[j++]=0x48;
bufferU[j++]=0x51;
bufferU[j++]=WAIT_T3; //min 1ms
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=30000>>8;
bufferU[j++]=30000&0xff;
bufferU[j++]=WAIT_T3; //min 25ms
if(entry==2){ //30Fx entry
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=ICSP_NOP;
}
else{
//Additional 5 clock cycles upon entering program mode
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
}
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>12)&0xF); //MOV XXXX,W6
bufferU[j++]=(appIDaddr>>4)&0xFF;
bufferU[j++]=((appIDaddr<<4)&0xF0)+6;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=2000>>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=FLUSH;
for(;j>8;
//bulk erase command
bufferU[j++]=SIX_N;
bufferU[j++]=4;
bufferU[j++]=0x24; //MOV XXXX,W10
if(erase==0){ //0x4064
bufferU[j++]=0x06;
bufferU[j++]=0x4A;
}
else if(erase==1){ //0x404F
bufferU[j++]=0x04;
bufferU[j++]=0xFA;
}
else if(erase>=2){ //0x407F
bufferU[j++]=0x07;
bufferU[j++]=0xFA;
}
bufferU[j++]=0x88; //MOV W10,NVMCON
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=0x20; //MOV XXXX,W0
bufferU[j++]=0x00;
bufferU[j++]=0x00;
bufferU[j++]=0x88; //MOV W0,TABLPAG
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //TBLWTL W0,[W0] (dummy write)
bufferU[j++]=0xBB;
bufferU[j++]=0x08;
bufferU[j++]=0x00;
if(erase>=2){ //30Fx, unlock and external timing
bufferU[j++]=SIX_N;
bufferU[j++]=4;
bufferU[j++]=0x20; //MOV 0x55,W8
bufferU[j++]=0x05;
bufferU[j++]=0x58;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=0x20; //MOV 0xAA,W8
bufferU[j++]=0x0A;
bufferU[j++]=0xA8;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=WAIT_T3;
if(erase==3){ //200 ms timing
bufferU[j++]=FLUSH;
for(;j0?0x1A:0x4A; //0x4001/0x4004
bufferU[j++]=0x88; //MOV W10,NVMCON
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=0x20; //MOV XXXX,W0
bufferU[j++]=0x00;
bufferU[j++]=0x00;
bufferU[j++]=0x88; //MOV W0,TABLPAG
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=0x04; //GOTO 0x200
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j=dim) break;
}
if((i>>17)!=High){ //advance page
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20;
bufferU[j++]=(i>>21)&0xFF;
bufferU[j++]=(i>>13)&0xF0;
bufferU[j++]=SIX; //MOV W0,TABLPAG
bufferU[j++]=0x88;
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17;
}
bufferU[j++]=SIX_N;
bufferU[j++]=8;
bufferU[j++]=0x20+((i>>13)&0xF); //MOV i/2,W7
bufferU[j++]=(i>>5)&0xFF;
bufferU[j++]=((i<<3)&0xF0)+7;
bufferU[j++]=0x20+((memCODE[i+1]>>4)&0xF); //MOV LSW0,W0
bufferU[j++]=((memCODE[i+1]<<4)&0xF0)+((memCODE[i]>>4)&0xF);
bufferU[j++]=(memCODE[i]<<4)&0xF0;
bufferU[j++]=0x20+((memCODE[i+6]>>4)&0xF); //MOV MSB1:MSB0,W1
bufferU[j++]=((memCODE[i+6]<<4)&0xF0)+((memCODE[i+2]>>4)&0xF);
bufferU[j++]=((memCODE[i+2]<<4)&0xF0)+1;
bufferU[j++]=0x20+((memCODE[i+5]>>4)&0xF); //MOV LSW1,W2
bufferU[j++]=((memCODE[i+5]<<4)&0xF0)+((memCODE[i+4]>>4)&0xF);
bufferU[j++]=((memCODE[i+4]<<4)&0xF0)+2;
bufferU[j++]=0x20+((memCODE[i+9]>>4)&0xF); //MOV LSW2,W3
bufferU[j++]=((memCODE[i+9]<<4)&0xF0)+((memCODE[i+8]>>4)&0xF);
bufferU[j++]=((memCODE[i+8]<<4)&0xF0)+3;
bufferU[j++]=0x20+((memCODE[i+14]>>4)&0xF); //MOV MSB3:MSB2,W4
bufferU[j++]=((memCODE[i+14]<<4)&0xF0)+((memCODE[i+10]>>4)&0xF);
bufferU[j++]=((memCODE[i+10]<<4)&0xF0)+4;
bufferU[j++]=0x20+((memCODE[i+13]>>4)&0xF); //MOV LSW3,W5
bufferU[j++]=((memCODE[i+13]<<4)&0xF0)+((memCODE[i+12]>>4)&0xF);
bufferU[j++]=((memCODE[i+12]<<4)&0xF0)+5;
bufferU[j++]=0xEB; //CLR W6
bufferU[j++]=0x03;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_N;
bufferU[j++]=0x88; //Append 2 NOP
bufferU[j++]=0xBB; //TBLWTL [W6++],[W7]
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++]
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7]
bufferU[j++]=0xEB;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++]
bufferU[j++]=0x1B;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTL [W6++],[W7]
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++]
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7]
bufferU[j++]=0xEB;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++]
bufferU[j++]=0x1B;
bufferU[j++]=0xB6;
k++;
if(k==rowSize/4){ //Write row
if(erase>1){ //30Fx, unlock and external timing
bufferU[j++]=FLUSH;
for(;j0?0x1A:0x4A; //0x4001/0x4004
bufferU[j++]=0x88; //MOV W10,NVMCON
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=0x20; //MOV 0x55,W8
bufferU[j++]=0x05;
bufferU[j++]=0x58;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=0x20; //MOV 0xAA,W8
bufferU[j++]=0x0A;
bufferU[j++]=0xA8;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=WAIT_T3;
bufferU[j++]=WAIT_T3;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR
bufferU[j++]=0xA9;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
}
else{ //internal timing
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
}
k=0;
}
bufferU[j++]=FLUSH;
for(;j=dim) break;
if((i>>17)!=High){ //advance page
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20;
bufferU[j++]=(i>>21)&0xFF;
bufferU[j++]=(i>>13)&0xF0;
bufferU[j++]=SIX; //MOV W0,TABLPAG
bufferU[j++]=0x88;
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17;
}
bufferU[j++]=SIX; //MOV i/2,W6
bufferU[j++]=0x20+((i>>13)&0xF);
bufferU[j++]=(i>>5)&0xFF;
bufferU[j++]=((i<<3)&0xF0)+6;
bufferU[j++]=SIX; //MOV #VISI,W7
bufferU[j++]=0x20;
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++]
bufferU[j++]=0xBA;
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--]
bufferU[j++]=0xBA;
bufferU[j++]=0xD3;
bufferU[j++]=0xD6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++]
bufferU[j++]=0xBA;
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--]
bufferU[j++]=0xBA;
bufferU[j++]=0xD3;
bufferU[j++]=0xD6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
if(err>=max_err){
PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n"
}
//****************** erase, write and verify EEPROM ********************
if(dim2&&err>12;
if(eewrite==0){ //24FxxKAxx
bufferU[j++]=SIX; //MOV 0x4050,W10
bufferU[j++]=0x24;
bufferU[j++]=0x05;
bufferU[j++]=0x0A;
bufferU[j++]=SIX; //MOV W10,NVMCON
bufferU[j++]=0x88;
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=SIX; //MOV 0x7F,W0
bufferU[j++]=0x20;
bufferU[j++]=0x07;
bufferU[j++]=0xF0;
bufferU[j++]=SIX; //MOV W0,TABLPAG
bufferU[j++]=0x88;
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=SIX; //MOV EEbaseAddr,W0
bufferU[j++]=0x2F;
bufferU[j++]=EEbaseAddr>>4;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX; //TBLWTL W0,[W0]
bufferU[j++]=0xBB;
bufferU[j++]=0x08;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;/**/
//Erase EEPROM
bufferU[j++]=SIX; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=WAIT_T3;
bufferU[j++]=WAIT_T3;
bufferU[j++]=WAIT_T3;
bufferU[j++]=SIX; //MOV 0x4004,W10
bufferU[j++]=0x24;
bufferU[j++]=0x00;
bufferU[j++]=0x4A;
bufferU[j++]=SIX; //MOV W10,NVMCON
bufferU[j++]=0x88;
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>4;
bufferU[j++]=((i<<4)&0xF0)+7;
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20+((memEE[i+1]>>4)&0xF);
bufferU[j++]=((memEE[i+1]<<4)&0xF0)+((memEE[i]>>4)&0xF);
bufferU[j++]=(memEE[i]<<4)&0xF0;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++]
bufferU[j++]=0xBB;
bufferU[j++]=0x1B;
bufferU[j++]=0x80;
if(eewrite==0){ //24FxxKAxx
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
}
else if(eewrite==1){ //30Fxxxx
bufferU[j++]=SIX_N;
bufferU[j++]=6;
bufferU[j++]=0x24; //MOV 0x4004,W10
bufferU[j++]=0x00;
bufferU[j++]=0x4A;
bufferU[j++]=0x88; //MOV W10,NVMCON
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=0x20; //MOV 0x55,W8
bufferU[j++]=0x05;
bufferU[j++]=0x58;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=0x20; //MOV 0xAA,W8
bufferU[j++]=0x0A;
bufferU[j++]=0xA8;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=WAIT_T3;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR
bufferU[j++]=0xA9;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
}
bufferU[j++]=FLUSH;
for(;j>4;
bufferU[j++]=0x06;
bufferU[j++]=SIX; //MOV #VISI,W7
bufferU[j++]=0x20;
bufferU[j++]=0x78;
bufferU[j++]=0x47;
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
int errE=0;
for(i=k2=EEbaseAddr;iDIMBUF-7||i==dim2-4){
bufferU[j++]=FLUSH;
for(;j2&&config<5&&err>16;
bufferU[j++]=SIX_N;
bufferU[j++]=6;
bufferU[j++]=0x20; //MOV 0xF8,W0
bufferU[j++]=0x0F;
bufferU[j++]=0x80;
bufferU[j++]=0x88; //MOV W0,TABLPAG
if(newTABLPAG){
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
}
else{
bufferU[j++]=0x01;
bufferU[j++]=0x90;
}
bufferU[j++]=0x24; //MOV 0x400x,W10
bufferU[j++]=0x00;
if(confword==0)bufferU[j++]=0x0A; //0x4000
else if(confword==1)bufferU[j++]=0x3A; //0x4003
else if(confword==2)bufferU[j++]=0x4A; //0x4004
else if(confword==3)bufferU[j++]=0x8A; //0x4008
bufferU[j++]=0x88; //MOV W10,NVMCON
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=0x20; //MOV 0,W7
bufferU[j++]=0x00;
bufferU[j++]=0x07;
bufferU[j++]=0x04; //GOTO 0x200
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
for(i=0;i<12;i++){
//Write CONFIG
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20;
bufferU[j++]=(memCONFIG[i*4]>>4)&0xF;
bufferU[j++]=(memCONFIG[i*4]<<4)&0xF0;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++]
bufferU[j++]=0xBB;
bufferU[j++]=0x1B;
bufferU[j++]=0x80;
if(memCONFIG[i*4]<0xFF){ //write if not empty
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
}
bufferU[j++]=FLUSH;
for(;j=5&&err>12);
bufferU[j++]=(value>>4);
bufferU[j++]=(value<<4);
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++]
bufferU[j++]=0xBB;
bufferU[j++]=0x1B;
bufferU[j++]=0x80;
if(value<0xFFFF){ //write if not empty
bufferU[j++]=SIX_N;
bufferU[j++]=6;
bufferU[j++]=0x24; //MOV 0x400x,W10
bufferU[j++]=0x00;
bufferU[j++]=0x8A; //0x4008
bufferU[j++]=0x88; //MOV W10,NVMCON
bufferU[j++]=0x3B;
bufferU[j++]=0x0A;
bufferU[j++]=0x20; //MOV 0x55,W8
bufferU[j++]=0x05;
bufferU[j++]=0x58;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=0x20; //MOV 0xAA,W8
bufferU[j++]=0x0A;
bufferU[j++]=0xA8;
bufferU[j++]=0x88; //MOV W8,NVMKEY
bufferU[j++]=0x3B;
bufferU[j++]=0x38;
bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
bufferU[j++]=WAIT_T3;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR
bufferU[j++]=0xA9;
bufferU[j++]=0xE7;
bufferU[j++]=0x61;
}
bufferU[j++]=FLUSH;
for(;j0x100000||dim<0){
PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n"
return;
}
if(dim>size) for(i=size;i>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=EN_VPP_VCC; //enter program mode
bufferU[j++]=0x0;
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=WAIT_T2;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=WAIT_T3;
bufferU[j++]=TX16;
bufferU[j++]=2;
bufferU[j++]=0x4D;
bufferU[j++]=0x43;
bufferU[j++]=0x48;
bufferU[j++]=0x51;
bufferU[j++]=WAIT_T3; //min 1ms
bufferU[j++]=EN_VPP_VCC; //VDD + VPP
bufferU[j++]=0x5;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=55000>>8;
bufferU[j++]=55000&0xff;
bufferU[j++]=WAIT_T3; //min 50ms
//Additional 5 clock cycles upon entering program mode
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x4; //CK=1
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0; //CK=0
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>12)&0xF); //MOV XXXX,W6
bufferU[j++]=(appIDaddr>>4)&0xFF;
bufferU[j++]=((appIDaddr<<4)&0xF0)+6;
bufferU[j++]=0x20; //MOV #VISI,W7
bufferU[j++]=0xF8;
bufferU[j++]=0x87;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=SET_PARAMETER;
bufferU[j++]=SET_T3;
bufferU[j++]=2000>>8;
bufferU[j++]=2000&0xff;
bufferU[j++]=FLUSH;
for(;j=dim) break;
bufferU[j++]=SIX_N;
bufferU[j++]=5;
bufferU[j++]=0xEB; //CLR W6
bufferU[j++]=0x03;
bufferU[j++]=0x00;
bufferU[j++]=0xEB; //CLR W7
bufferU[j++]=0x03;
bufferU[j++]=0x80;
bufferU[j++]=0x20+((memCODE[i+1]>>4)&0xF); //MOV LSW0,W0
bufferU[j++]=((memCODE[i+1]<<4)&0xF0)+((memCODE[i]>>4)&0xF);
bufferU[j++]=(memCODE[i]<<4)&0xF0;
bufferU[j++]=0x20+((memCODE[i+6]>>4)&0xF); //MOV MSB1:MSB0,W1
bufferU[j++]=((memCODE[i+6]<<4)&0xF0)+((memCODE[i+2]>>4)&0xF);
bufferU[j++]=((memCODE[i+2]<<4)&0xF0)+1;
bufferU[j++]=0x20+((memCODE[i+5]>>4)&0xF); //MOV LSW1,W2
bufferU[j++]=((memCODE[i+5]<<4)&0xF0)+((memCODE[i+4]>>4)&0xF);
bufferU[j++]=((memCODE[i+4]<<4)&0xF0)+2;
bufferU[j++]=SIX_N;
bufferU[j++]=0x84; //Append 2 NOP
bufferU[j++]=0xBB; //TBLWTL [W6++],[W7]
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++]
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7]
bufferU[j++]=0xEB;
bufferU[j++]=0xB6;
bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++]
bufferU[j++]=0x1B;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_N;
bufferU[j++]=8;
bufferU[j++]=0x20+((i>>13)&0xF); //MOV i/2,W3
bufferU[j++]=(i>>5)&0xFF;
bufferU[j++]=((i<<3)&0xF0)+3;
bufferU[j++]=0x20; //MOV i/2/64K,W4
bufferU[j++]=(i>>21)&0xFF;
bufferU[j++]=((i>>13)&0xF0)+4;
bufferU[j++]=0x88; //MOV W3,NVMADR
bufferU[j++]=0x39;
bufferU[j++]=0x53;
bufferU[j++]=0x88; //MOV W4,NVMADRU
bufferU[j++]=0x39;
bufferU[j++]=0x64;
bufferU[j++]=0x20; //MOV 0x55,W1
bufferU[j++]=0x05;
bufferU[j++]=0x51;
bufferU[j++]=0x88; //MOV W1,NVMKEY
bufferU[j++]=0x39;
bufferU[j++]=0x71;
bufferU[j++]=0x20; //MOV 0xAA,W1
bufferU[j++]=0x0A;
bufferU[j++]=0xA1;
bufferU[j++]=0x88; //MOV W1,NVMKEY
bufferU[j++]=0x39;
bufferU[j++]=0x71;
bufferU[j++]=SIX_LONG5; //BSET NVMCON,#WR
bufferU[j++]=0xA8;
bufferU[j++]=0xE7;
bufferU[j++]=0x29;
bufferU[j++]=FLUSH;
for(;j=dim) break;
if((i>>17)!=High){ //advance page
bufferU[j++]=SIX; //MOV XXXX,W0
bufferU[j++]=0x20;
bufferU[j++]=(i>>21)&0xFF;
bufferU[j++]=(i>>13)&0xF0;
bufferU[j++]=SIX; //MOV W0,TABLPAG
bufferU[j++]=0x88;
bufferU[j++]=0x02;
bufferU[j++]=0xA0;
bufferU[j++]=SIX_LONG; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=FLUSH;
for(;j>17;
}
bufferU[j++]=SIX; //MOV i/2,W6
bufferU[j++]=0x20+((i>>13)&0xF);
bufferU[j++]=(i>>5)&0xFF;
bufferU[j++]=((i<<3)&0xF0)+6;
bufferU[j++]=SIX; //MOV #VISI,W7
bufferU[j++]=0x20;
bufferU[j++]=0xF8;
bufferU[j++]=0x87;
bufferU[j++]=ICSP_NOP;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDH.B [W6++],[W7++]
bufferU[j++]=0xBA;
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_LONG5; //TBLRDH.B [++W6],[W7--]
bufferU[j++]=0xBA;
bufferU[j++]=0xD3;
bufferU[j++]=0xD6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0x96;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDH.B [W6++],[W7++]
bufferU[j++]=0xBA;
bufferU[j++]=0xDB;
bufferU[j++]=0xB6;
bufferU[j++]=SIX_LONG5; //TBLRDH.B [++W6],[W7--]
bufferU[j++]=0xBA;
bufferU[j++]=0xD3;
bufferU[j++]=0xD6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //TBLRDL [W6++],[W7]
bufferU[j++]=0xBA;
bufferU[j++]=0x0B;
bufferU[j++]=0xB6;
bufferU[j++]=REGOUT;
bufferU[j++]=SIX_LONG5; //GOTO 0x200
bufferU[j++]=0x04;
bufferU[j++]=0x02;
bufferU[j++]=0x00;
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
if(err>=max_err){
PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n"
}
//****************** exit ********************
bufferU[j++]=SET_CK_D;
bufferU[j++]=0x0;
bufferU[j++]=EN_VPP_VCC; //0
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j