From a047db1259d3822b554d300ecc48fb2052bfc849 Mon Sep 17 00:00:00 2001 From: Attila Veghelyi Date: Mon, 9 Jun 2025 17:25:22 +0200 Subject: Follow version 0.12.4 --- progP16.c | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 205 insertions(+), 38 deletions(-) (limited to 'progP16.c') diff --git a/progP16.c b/progP16.c index be9f5a0..2f5f5f9 100644 --- a/progP16.c +++ b/progP16.c @@ -1,6 +1,6 @@ /** * \file progP16.c - algorithms to program the PIC16 (14 bit word) family of microcontrollers - * Copyright (C) 2009-2023 Alberto Maccioni + * Copyright (C) 2009-2025 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 @@ -175,6 +175,7 @@ struct ID16{ {0x2AE>>1,"16LF1784 rev%d\r\n",0x1F}, //10 1010 111x xxxx {0x2B0>>1,"16LF1786 rev%d\r\n",0x1F}, //10 1011 000x xxxx {0x2B2>>1,"16LF1787 rev%d\r\n",0x1F}, //10 1011 001x xxxx + {0x2BC>>1,"12LF1552 rev%d\r\n",0x1F}, //10 1011 110x xxxx {0x2C0>>1,"16LF1903 rev%d\r\n",0x1F}, //10 1100 000x xxxx {0x2C2>>1,"16LF1902 rev%d\r\n",0x1F}, //10 1100 001x xxxx {0x2C4>>1,"16LF1907 rev%d\r\n",0x1F}, //10 1100 010x xxxx @@ -225,6 +226,8 @@ struct ID16{ {0x3043,"16F1704\r\n",0}, {0x3044,"16LF1708\r\n",0}, {0x3045,"16LF1704\r\n",0}, + {0x3046,"16LF1566\r\n",0}, + {0x3047,"16LF1567\r\n",0}, {0x3048,"16F1716\r\n",0}, {0x3049,"16F1713\r\n",0}, {0x304A,"16LF1716\r\n",0}, @@ -417,6 +420,15 @@ struct ID16{ {0x3104,"16F17175\r\n",0}, {0x3105,"16F17156\r\n",0}, {0x3106,"16F17176\r\n",0}, + {0x3121,"16F13113\r\n",0}, + {0x3122,"16F13123\r\n",0}, + {0x3123,"16F13143\r\n",0}, + {0x3124,"16F13114\r\n",0}, + {0x3125,"16F13124\r\n",0}, + {0x3126,"16F13144\r\n",0}, + {0x3127,"16F13115\r\n",0}, + {0x3128,"16F13125\r\n",0}, + {0x3129,"16F13145\r\n",0}, }; static bool PIC16_ID(int id) @@ -597,6 +609,7 @@ void Read16Fxxx(int dim,int dim2,int dim3,int vdd) PacketIO(vdd?55:5); //****************** read code ******************** PrintMessage(strings[S_CodeReading1]); //read code ... + if(saveLog) fprintf(logfile,strings[S_sepLine]); if(saveLog) fprintf(logfile,"%s\n",strings[S_CodeReading1]); //read code ... PrintStatusSetup(); for(i=0,j=0;i vdd before vpp // bit1=1 -> LVP programming // bit4=1 -> do not use DIA&DCI +// bit5=1 -> Bulk erase with bit field payload +// bit6=1 -> workaround for 16F152XX: turn-off/on after bulk erase // DevREV@0x8005 DevID@0x8006 // Config@0x8007-800B // Device info area @0x8100 // Device configuration info area @0x8200 -// erase: BULK_ERASE_PROGRAM_MEM (0x18) +14ms +// erase: BULK_ERASE_PROGRAM_MEM (0x18) +14ms or 20ms // EEPROM erase: idem -// write flash: LOAD_NVM (0x0/2) + BEGIN_INT_PROG (0xE0) + 2.8ms (32 word algorithm) +// write flash: LOAD_NVM (0x0/2) + BEGIN_INT_PROG (0xE0) + 2.8ms/7ms (32 word algorithm) // EEPROM write: one word, 6ms // config write: one word, 10ms // verify after write @@ -6061,6 +6181,8 @@ void Write16F18xxx(int dim,int dim2,int options) WORD devID=0x3fff,devREV=0x3fff; int k=0,k2=0,z=0,i,j,w; int useDCI=(options&0x10)==0?1:0; + int bulkEraseField=(options&0x20)?1:0; + int reboot=(options&0x40)?1:0; int rowN=32; //32 word algorithm if(FWVersion<0xB00){ PrintMessage1(strings[S_FWver2old],"0.11.0"); //"This firmware is too old. Version %s is required\r\n" @@ -6141,8 +6263,14 @@ void Write16F18xxx(int dim,int dim2,int options) bufferU[j++]=READ_NVM_INC; //DevID bufferU[j++]=SET_PARAMETER; bufferU[j++]=SET_T3; - bufferU[j++]=2800>>8; - bufferU[j++]=2800&0xff; + if(!bulkEraseField){ + bufferU[j++]=2800>>8; + bufferU[j++]=2800&0xff; + } + else{ //max delay for devices with bulk erase bit field (only 131xx require 7ms) + bufferU[j++]=7000>>8; + bufferU[j++]=7000&0xff; + } bufferU[j++]=FLUSH; for(;j>8; //5.6ms in datasheet, but requires more in practice - bufferU[j++]=10000&0xff; + bufferU[j++]=12000>>8; //some require 5.6ms, others up to 12ms + bufferU[j++]=12000&0xff; if(programID){ bufferU[j++]=ICSP8_LOAD; bufferU[j++]=LOAD_PC_ADDR; //load address @@ -6467,13 +6634,13 @@ void Write16F18xxx(int dim,int dim2,int options) bufferU[j++]=memCODE_W[i]&0xff; //LSB bufferU[j++]=ICSP8_SHORT; bufferU[j++]=BEGIN_INT_PROG; //internally timed - bufferU[j++]=WAIT_T3; //Tprogram 10ms + bufferU[j++]=WAIT_T3; //Tprogram 12ms bufferU[j++]=ICSP8_READ; bufferU[j++]=READ_NVM_INC; } bufferU[j++]=FLUSH; for(;j