public void ClearTestMemory() { for (int i = 0; i < TestMemory.Length; i++) { TestMemory[i] = Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue; } }
private void buttonBack_Click(object sender, EventArgs e) { if (panelSetup.Visible) { panelIntro.Visible = true; panelSetup.Visible = false; buttonBack.Enabled = false; setupClearButtons(); } else if (panelCal.Visible) { Pk2.VddOff(); panelSetup.Visible = true; panelCal.Visible = false; } else if (panelUnitID.Visible) { panelUnitID.Visible = false; panelCal.Visible = true; buttonCalibrate.Enabled = false; labelGoodCal.Visible = false; labelBadCal.Visible = false; textBoxVDD.Text = "-"; buttonNext.Enabled = true; buttonCancel.Text = "Cancel"; } }
private void buttonBack_Click(object sender, EventArgs e) { if (panelStep1VDDExt.Visible || panelStep1VDDTest.Visible) { // Shut off VDD Pk2.VddOff(); panelIntro.Visible = true; buttonBack.Enabled = false; panelStep1VDDTest.Visible = false; panelStep1VDDExt.Visible = false; } else if (panelCautionVDD.Visible || panelStep2VPP.Visible) { panelCautionVDD.Visible = false; panelStep2VPP.Visible = false; testVDD(); } else if (panelPGCPGD.Visible) { panelPGCPGD.Visible = false; panelStep2VPP.Visible = true; buttonNext.Enabled = true; testVPP_Enter(); } }
public DialogCalibrate() { InitializeComponent(); Pk2.VddOff(); Pk2.ForcePICkitPowered(); setupClearButtons(); }
private void buttonClearUnitID_Click(object sender, EventArgs e) { Pk2.UnitIDWrite(""); buttonClearUnitID.Enabled = false; buttonClearUnitID.Text = "No Assigned ID"; unitIDChanged = true; }
// ###################### VPP TEST ########################## private void testVPP_Enter() { Pk2.VddOff(); byte[] pinscript = new byte[2]; pinscript[0] = KONST._SET_ICSP_PINS; pinscript[1] = 0x03; // set both pins to inputs. Pk2.SendScript(pinscript); timerPGxToggle.Enabled = false; buttonCancel.Text = "Cancel"; if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].Vpp < 1) { labelStep2FamilyVPP.Text = "1) VPP for this family: " + string.Format("{0:0.0}V (=VDD)", numericUpDown1.Value); } else { labelStep2FamilyVPP.Text = "1) VPP for this family: " + string.Format("{0:0.0} Volts.", Pk2.DevFile.Families[Pk2.GetActiveFamily()].Vpp); } labelReadVPP.Text = ""; labelVPPLow.Visible = false; labelVPPMCLR.Visible = false; labelVPPMCLROff.Visible = false; labelVPPPass.Visible = false; labelVPPShort.Visible = false; labelVPPVDDShort.Visible = false; }
private void radioButtonPGCHigh_CheckedChanged(object sender, EventArgs e) { byte[] pgcscript = new byte[2]; if (radioButtonPGDToggle.Checked || radioButtonPGCToggle.Checked) { return; // don't do anything } else { // ensure timer is off and set pin states! timerPGxToggle.Enabled = false; pgcscript[0] = KONST._SET_ICSP_PINS; if (radioButtonPGCHigh.Checked && radioButtonPGDHigh.Checked) { pgcscript[1] = 0x0C; } else if (radioButtonPGCHigh.Checked) { pgcscript[1] = 0x04; } else if (radioButtonPGDHigh.Checked) { pgcscript[1] = 0x08; } else { pgcscript[1] = 0x00; } Pk2.SendScript(pgcscript); } }
private void buttonSetUnitID_Click(object sender, EventArgs e) { if (Pk2.UnitIDWrite(textBoxUnitID.Text)) { labelAssignedID.Visible = true; buttonSetUnitID.Enabled = false; } }
private void downloadGO() { panelDownload.Visible = false; panelDownloading.Visible = true; buttonHelp.Enabled = false; buttonBack.Enabled = false; buttonNext.Enabled = false; buttonCancel.Enabled = false; buttonCancel.Text = "Exit"; this.Update(); if (radioButtonSelfPower.Checked) { Pk2.ForceTargetPowered(); } else { Pk2.ForcePICkitPowered(); } if (ptgMemory <= 5) { Pk2.EnterLearnMode(ptgMemory); // set memory size to use } else { Pk2.EnterLearnMode(0); // default to 128K on illegal value } if (fastProgramming) { Pk2.SetProgrammingSpeed(0); } else { Pk2.SetProgrammingSpeed(icspSpeedSlow); } PICkit2WriteGo(true); Pk2.ExitLearnMode(); if (ptgMemory <= 5) { Pk2.EnablePK2GoMode(ptgMemory); // set memory size to use } else { Pk2.EnablePK2GoMode(0); // default to 128K on illegal value. } Pk2.DisconnectPICkit2Unit(); panelDownloading.Visible = false; panelDownloadDone.Visible = true; buttonHelp.Enabled = true; buttonNext.Enabled = true; buttonNext.Text = "Next >"; buttonCancel.Enabled = true; timerBlink.Enabled = true; }
public DialogTroubleshoot() { InitializeComponent(); Pk2.VddOff(); byte[] pinscript = new byte[2]; pinscript[0] = KONST._SET_ICSP_PINS; pinscript[1] = 0x03; // set both pins to inputs. Pk2.SendScript(pinscript); }
private void buttonClearUnitID_PK3_Click(object sender, EventArgs e) { Pk2.UnitIDWrite(""); labelAssignedID.Text = "No Unit ID Assigned to this PICkit 3."; labelAssignedID.Visible = true; buttonClearUnitID_PK3.Enabled = false; buttonClearUnitID_PK3.Text = "No Assigned ID"; buttonCancel.Text = "Finished"; textBoxUnitID.Text = ""; textBoxUnitID.Enabled = false; unitIDChanged = true; }
private void setupClearButtons() { if (Pk2.isPK3) // PICkit 3 { buttonBack.Enabled = false; buttonBack.Visible = false; buttonNext.Enabled = false; buttonNext.Visible = false; if (Pk2.UnitIDRead().Length > 0) { buttonClearUnitID_PK3.Enabled = true; buttonClearUnitID_PK3.Visible = true; buttonSetUnitID.Enabled = false; buttonSetUnitID.Visible = false; } else { buttonClearUnitID_PK3.Enabled = false; buttonClearUnitID_PK3.Visible = false; buttonSetUnitID.Enabled = true; buttonSetUnitID.Visible = true; } } else // PICkit 2 { buttonClearUnitID_PK3.Enabled = false; buttonClearUnitID_PK3.Visible = false; buttonClearUnitID_PK3.Text = ""; if (Pk2.isCalibrated()) { buttonClearCal.Enabled = true; buttonClearCal.Text = "Clear Calibration"; } else { buttonClearCal.Enabled = false; buttonClearCal.Text = "Unit Not Calibrated"; } if (Pk2.UnitIDRead().Length > 0) { buttonClearUnitID.Enabled = true; buttonClearUnitID.Text = "Clear Unit ID"; } else { buttonClearUnitID.Enabled = false; buttonClearUnitID.Text = "No Assigned ID"; } } }
private int getTestMemAddress() { if (Pk2.GetActiveFamily() == 2) { // baseline return((int)Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem); } else { return((int)(Pk2.DevFile.Families[Pk2.GetActiveFamily()].TestMemoryStart / Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemHexBytes)); } }
public DialogUnitSelect() { InitializeComponent(); this.Size = new Size(this.Size.Width, (int)(FormPICkit2.ScalefactH * this.Size.Height)); // Find up to 8 PICkit 2 Units. for (ushort i = 0; i < 8; i++) { KONST.PICkit2USB detRes = Pk2.DetectPICkit2Device(i, false); if (detRes != KONST.PICkit2USB.notFound) { // found something /*if (detRes == KONST.PICkit2USB.bootloader) * { * listBoxUnits.Items.Add(" " + i.ToString() + " <Bootloader>"); * } * else if (detRes == Constants.PICkit2USB.firmwareInvalid) * { // min FW for UnitID is 2.10 * if ((Pk2.FirmwareVersion[0] == '2') && (ushort.Parse(Pk2.FirmwareVersion.Substring(2,2)) >= 10)) * { * string unitID = Pk2.UnitIDRead(); * if (unitID == "") * unitID = "-"; * listBoxUnits.Items.Add(" " + i.ToString() + " " + unitID); * } * else * { * listBoxUnits.Items.Add(" " + i.ToString() + " <FW v" + Pk2.FirmwareVersion + ">"); * } * * } * else * { * string unitID = Pk2.UnitIDRead(); * if (unitID == "") * unitID = "-"; * listBoxUnits.Items.Add(" " + i.ToString() + " " + unitID); * }*/ string unitID = Pk2.GetSerialUnitID(); if (unitID == "PIC18F2550") { unitID = "<bootloader>"; } listBoxUnits.Items.Add(" " + i.ToString() + " " + unitID); } else { break; } } }
private void buttonCancel_Click(object sender, EventArgs e) { Pk2.VddOff(); if (unitIDChanged) { // reset PICkit 2 so it re-enumerates with new ID. Pk2.ResetPICkit2(); Thread.Sleep(1000); MessageBox.Show("Resetting PICkit 2.\n\nPlease wait for USB enumeration\nto complete before clicking OK...", "Reset PICkit 2"); Thread.Sleep(1000); } this.Close(); }
private void textBox1_15_Click(object sender, EventArgs e) { int boxNum = (int)((TextBox)sender).Tag; int configNum = boxNum / 16; boxNum = boxNum % 16; uint bitMask = 1; bitMask <<= boxNum; //update box value if (configWords[configNum].bits[boxNum].Text == "1") {// change to 0 configWords[configNum].bits[boxNum].Text = "0"; Pk2.DeviceBuffers.ConfigWords[configNum] &= ~bitMask; } else { // change to 1 configWords[configNum].bits[boxNum].Text = "1"; Pk2.DeviceBuffers.ConfigWords[configNum] |= bitMask; } if (configWords[configNum].bits[boxNum].ForeColor == Color.Crimson) // red means edited { configWords[configNum].bits[boxNum].ForeColor = System.Drawing.SystemColors.WindowText; } else { configWords[configNum].bits[boxNum].ForeColor = Color.Crimson; } // update value column ushort cword = (ushort)Pk2.DeviceBuffers.ConfigWords[configNum]; if (displayMask == 0) { cword &= (ushort)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[configNum]; } else if (displayMask == 1) { cword |= (ushort)~Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[configNum]; } cword &= (ushort)Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue; configWords[configNum].value.Text = string.Format("{0:X4}", cword); configWords[configNum].value.ForeColor = System.Drawing.SystemColors.ActiveCaption; // default blue for (int b = 0; b < 16; b++) // look for any edited bits in the word { if (configWords[configNum].bits[b].ForeColor == Color.Crimson) { configWords[configNum].value.ForeColor = Color.Crimson; // red means edited break; } } }
private void dataGridTestMemory_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex; int col = e.ColumnIndex; string editText = "0x" + dataGridTestMemory[col, row].FormattedValue.ToString(); int value = UTIL.Convert_Value_To_Int(editText); int numColumns = dataGridTestMemory.ColumnCount - 1; int testMemAddress = (row * numColumns) + col - 1; int testMemStart = getTestMemAddress() * Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemHexBytes; int userIDAddr = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDAddr; if (Pk2.GetActiveFamily() == 2) { // baseline userIDAddr = testMemStart; } TestMemory[testMemAddress] = (uint)(value & Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue); if ((Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDWords > 0) && (userIDAddr >= testMemStart) && (userIDAddr < (testMemStart + FormPICkit2.TestMemoryWords))) { // if user IDs are in test memory int userIDIndex = (int)(userIDAddr - testMemStart) / Pk2.DevFile.Families[Pk2.GetActiveFamily()].BytesPerLocation; if ((testMemAddress >= userIDIndex) && (testMemAddress < (userIDIndex + Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDWords))) { Pk2.DeviceBuffers.UserIDs[testMemAddress - userIDIndex] = (uint)(value & Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue); if (Pk2.GetActiveFamily() == 3) { // 18F Pk2.DeviceBuffers.UserIDs[testMemAddress - userIDIndex] &= 0xFF; } } } if ((Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords > 0) && (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr >= testMemStart) && (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr < (testMemStart + FormPICkit2.TestMemoryWords))) { // if config words are in test memory int cfgWordsIndex = (int)(Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr - testMemStart) / Pk2.DevFile.Families[Pk2.GetActiveFamily()].BytesPerLocation; if ((testMemAddress >= cfgWordsIndex) && (testMemAddress < (cfgWordsIndex + Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords))) { Pk2.DeviceBuffers.ConfigWords[testMemAddress - cfgWordsIndex] = (uint)(value & Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[testMemAddress - cfgWordsIndex]); } } testMemJustEdited = true; UpdateMainFormGUI(); }
public void UpdateMultiWinProgMem(string dataSource) { if ((lastPart != Pk2.ActivePart) || (lastFam != Pk2.GetActiveFamily())) { lastPart = Pk2.ActivePart; lastFam = Pk2.GetActiveFamily(); ReCalcMultiWinProgMem(); } else { updateDisplay(); } displayDataSource.Text = dataSource; }
public void ReadTestMemory() { byte[] upload_buffer = new byte[KONST.UploadBufferSize]; Pk2.RunScript(KONST.PROG_ENTRY, 1); int bytesPerWord = Pk2.DevFile.Families[Pk2.GetActiveFamily()].BytesPerLocation; int scriptRunsToFillUpload = KONST.UploadBufferSize / (Pk2.DevFile.PartsList[Pk2.ActivePart].TestMemoryRdWords * bytesPerWord); int wordsPerLoop = scriptRunsToFillUpload * Pk2.DevFile.PartsList[Pk2.ActivePart].TestMemoryRdWords; int wordsRead = 0; prepTestMem(); do { //Pk2.RunScriptUploadNoLen2(KONST.TESTMEM_RD, scriptRunsToFillUpload); Pk2.RunScriptUploadNoLen(KONST.TESTMEM_RD, scriptRunsToFillUpload); Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, 0, KONST.USB_REPORTLENGTH); //Pk2.GetUpload(); Pk2.UploadDataNoLen(); Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, KONST.USB_REPORTLENGTH, KONST.USB_REPORTLENGTH); int uploadIndex = 0; for (int word = 0; word < wordsPerLoop; word++) { int bite = 0; uint memWord = (uint)upload_buffer[uploadIndex + bite++]; if (bite < bytesPerWord) { memWord |= (uint)upload_buffer[uploadIndex + bite++] << 8; } if (bite < bytesPerWord) { memWord |= (uint)upload_buffer[uploadIndex + bite++] << 16; } if (bite < bytesPerWord) { memWord |= (uint)upload_buffer[uploadIndex + bite++] << 24; } uploadIndex += bite; // shift if necessary if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemShift > 0) { memWord = (memWord >> 1) & Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue; } TestMemory[wordsRead++] = memWord; } } while (wordsRead < FormPICkit2.TestMemoryWords); Pk2.RunScript(KONST.PROG_EXIT, 1); }
private void PGxToggle() { timerPGxToggle.Enabled = false; byte pgxvaluehigh = 0x0; byte pgxvaluelow = 0x0; if (radioButtonPGDToggle.Checked) { pgxvaluehigh |= 0x8; } if (radioButtonPGCToggle.Checked) { pgxvaluehigh |= 0x4; } if (radioButtonPGCHigh.Checked) { pgxvaluehigh |= 0x4; pgxvaluelow |= 0x4; } if (radioButtonPGDHigh.Checked) { pgxvaluehigh |= 0x8; pgxvaluelow |= 0x8; } // 30kHz square wave - 500ms @ 30k^-1 * 256 * 59 byte[] pgdscript = new byte[17]; pgdscript[0] = KONST._CONST_WRITE_DL; pgdscript[1] = 59; pgdscript[2] = KONST._CONST_WRITE_DL; pgdscript[3] = 0; pgdscript[4] = KONST._SET_ICSP_PINS; pgdscript[5] = pgxvaluehigh; pgdscript[6] = KONST._BUSY_LED_ON; // a NOP to stretch the high pulse time. pgdscript[7] = KONST._BUSY_LED_ON; // a NOP pgdscript[8] = KONST._SET_ICSP_PINS; pgdscript[9] = pgxvaluelow; pgdscript[10] = KONST._BUSY_LED_ON; // a NOP pgdscript[11] = KONST._LOOP; pgdscript[12] = 7; pgdscript[13] = 0; //256 pgdscript[14] = KONST._LOOPBUFFER; pgdscript[15] = 10; pgdscript[16] = KONST._BUSY_LED_OFF; Pk2.SendScript(pgdscript); timerPGxToggle.Enabled = true; }
private void buttonVDDOn_Click(object sender, EventArgs e) { float vdd = 0; float vpp = 0; labelGood.Visible = false; labelVDDShort.Visible = false; labelVDDLow.Visible = false; labelReadVDD.Text = ""; // set VDD with a low threshold float voltage = (float)numericUpDown1.Value; if (Pk2.SetVDDVoltage(voltage, 0.45F)) { // turn on VDD Pk2.ForcePICkitPowered(); if (Pk2.VddOn()) { // check status first for shorts if (Pk2.PowerStatus() != KONST.PICkit2PWR.vdd_on) { //short! labelVDDShort.Visible = true; labelReadVDD.Text = "Short!"; } else {// status OK, read VDD voltage if (Pk2.ReadPICkitVoltages(ref vdd, ref vpp)) { labelReadVDD.Text = string.Format("{0:0.0} V", vdd); float expectedVDD = (float)numericUpDown1.Value; if (expectedVDD > 4.6F) { expectedVDD = 4.6F; // There is a typical drop for VDD > 4.6V // don't count that } if ((expectedVDD - vdd) > 0.2F) { labelVDDLow.Visible = true; } else { labelGood.Visible = true; } } } } } }
private void trblshtingFormClosing(object sender, FormClosingEventArgs e) { // clean up - shut down everything timerPGxToggle.Enabled = false; byte[] closescript = new byte[5]; closescript[0] = KONST._VPP_OFF; closescript[1] = KONST._MCLR_GND_OFF; closescript[2] = KONST._VPP_PWM_OFF; closescript[3] = KONST._SET_ICSP_PINS; closescript[4] = 0x03; // inputs Pk2.SendScript(closescript); Pk2.VddOff(); }
static public KONST.PICkit2USB WriteProgrammerOs(string ApHexFile, uint Command) { //TODO There is a "Magic Key" in APs and RS that we should check. uint StartAddr = 0; int NumBytes = 0; byte[] Ap; NumBytes = ImportHexFileAsBytes(out Ap, ApHexFile, out StartAddr); NumBytes = AdjustHexFileDataForSend(ref Ap); // Adjust the start address for the programmer StartAddr = StartAddr / 2; // dsPIC has 2 bytes per program word byte[] memObj = new byte[8]; // MemObj start address memObj[0] = Convert.ToByte(StartAddr & 0xFF); memObj[1] = Convert.ToByte((StartAddr >> 8) & 0xFF); memObj[2] = Convert.ToByte((StartAddr >> 16) & 0xFF); memObj[3] = Convert.ToByte((StartAddr >> 24) & 0xFF); // MemObj length in bytes uint RangeInBytes = (uint)Ap.Length; memObj[4] = Convert.ToByte(RangeInBytes & 0xFF); memObj[5] = Convert.ToByte((RangeInBytes >> 8) & 0xFF); memObj[6] = Convert.ToByte((RangeInBytes >> 16) & 0xFF); memObj[7] = Convert.ToByte((RangeInBytes >> 24) & 0xFF); SendCommandWithData(Command, memObj); SendBulkData(Ap); // The programmer will restart now, so we need to reinit comms Thread.Sleep(2000); KONST.PICkit2USB res = KONST.PICkit2USB.notFound; while (res == KONST.PICkit2USB.notFound) { res = Pk3.DetectPICkit2Device(FormPICkit2.pk2number, true); Thread.Sleep(500); // Delay a bit so we don't hammer the programmer } //Initialize(); return(res); }
private void buttonWriteCalWords_Click(object sender, EventArgs e) { uint[] cals = new uint[Pk2.DevFile.PartsList[Pk2.ActivePart].CalibrationWords]; int testMemStart = getTestMemAddress() * Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemHexBytes; int cfgWordsIndex = (int)(Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr - testMemStart) / Pk2.DevFile.Families[Pk2.GetActiveFamily()].BytesPerLocation; int calWordsIndex = cfgWordsIndex + Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords; for (int i = 0; i < cals.Length; i++) { cals[i] = TestMemory[calWordsIndex + i]; } CallMainFormEraseWrCal(cals); }
private void buttonSetUnitID_Click(object sender, EventArgs e) { if (Pk2.UnitIDWrite(textBoxUnitID.Text)) { if (Pk2.isPK3) // PICkit 3 { labelAssignedID.Text = "Unit ID Assigned to this PICkit 3."; buttonCancel.Text = "Finished"; textBoxUnitID.Enabled = false; } labelAssignedID.Visible = true; buttonSetUnitID.Enabled = false; unitIDChanged = true; } }