private void buttonCalibrate_Click(object sender, EventArgs e) { float vdd = 0f; float vpp = 0f; float num = 0f; bool flag = true; try { num = float.Parse(textBoxVDD.Text); } catch { MessageBox.Show("Invalid 'volts measured' value."); return; } PICkitFunctions.ReadPICkitVoltages(ref vdd, ref vpp); num /= vdd; if (num > 1.25f) { num = 1.25f; flag = false; } if (num < 0.75f) { num = 0.75f; flag = false; } float num2 = 256f * num; PICkitFunctions.SetVoltageCals((ushort)num2, 0, 128); float num3 = 0f; float num4 = 0f; float num5 = 0f; PICkitFunctions.SetVDDVoltage(3f, 2f); Thread.Sleep(150); PICkitFunctions.ReadPICkitVoltages(ref vdd, ref vpp); num5 = vdd; PICkitFunctions.SetVDDVoltage(4f, 2.7f); Thread.Sleep(150); PICkitFunctions.ReadPICkitVoltages(ref vdd, ref vpp); num3 = (3f - 4f * num5 / vdd) * (float)(PICkitFunctions.CalculateVddCPP(4f) >> 6); if (num3 > 127f) { num3 = 127f; flag = false; } if (num3 < -128f) { num3 = -128f; flag = false; } num4 = 1f / (vdd - num5) * 128f; if (num4 > 173f) { num4 = 173f; flag = false; } if (num4 < 83f) { num4 = 83f; flag = false; } if (flag) { labelGoodCal.Visible = true; labelBadCal.Visible = false; PICkitFunctions.SetVoltageCals((ushort)num2, (byte)num3, (byte)((double)num4 + 0.5)); } else { labelGoodCal.Visible = false; labelBadCal.Visible = true; PICkitFunctions.SetVoltageCals(256, 0, 128); } buttonCalibrate.Enabled = false; PICkitFunctions.VddOff(); }