private void btnReadHex_Click(object sender, EventArgs e) { var f = File.Open( @"C:\microchip\testStepper\output\testStepper.hex", FileMode.Open, FileAccess.Read); var h = new HexParser(f); byte[] code = new byte[0x1000]; byte[] uid = new byte[8]; byte[] data = new byte[0x80]; byte[] conf = new byte[2]; long addr = -1; while (h.Address <= code.Length * 2) { addr = h.Address; code[addr] = h.Value; h.nextAddress(); } Array.Resize <byte>(ref code, (int)addr + 1); addr = -1; while (h.Address <= 0x2004 * 2) { addr = h.Address - 0x2000 * 2; uid[addr] = h.Value; h.nextAddress(); } Array.Resize <byte>(ref uid, (int)addr + 1); addr = -1; while (h.Address <= (0x2007 * 2) + 1) { addr = h.Address - 0x2007 * 2; conf[addr] = h.Value; h.nextAddress(); } Array.Resize <byte>(ref conf, (int)addr + 1); addr = -1; while (h.Address < (0x2100 + 0x80) * 2) { addr = h.Address - 0x2100 * 2; data[addr] = h.Value; h.nextAddress(); } Array.Resize <byte>(ref data, (int)addr + 1); pp.bulkErase(); pp.writeConfig(0x2000, uid, 0, uid.Length); if (conf.Length < 2) { conf = new byte[] { 0x10, 0x3f }; } pp.writeConfig(0x2007, conf, 0, conf.Length); pp.writeCode(0x0000, code, 0, code.Length); pp.writeData(0x0000, data, 0, data.Length); var confRead = new byte[16]; pp.readCode(0x2000, confRead, 0, confRead.Length); txtOut.AppendText("\r\n"); for (int i = 0; i < confRead.Length; i += 2) { txtOut.AppendText(String.Format("{0} {1}\r\n" , (i / 2 + 0x2000).ToString("X4") , (confRead[i] | (confRead[i + 1] << 8)).ToString("X4"))); } f.Close(); }