⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 Philips ARM lpc2000家族ISP下载源码集成了串口调试助手源码是个非常优秀的软件
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
  begin
    Memo3.Lines.Add(buff);
    StatusBar1.Panels[1].Text := '编程操作成功!!!';
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  CfgDirStr, str: string;
  SearchRec: TsearchRec;
  FindResult: integer;
begin
  if OpenDialog3.Execute then
  begin

    ComboBox14.Items.Clear;
    CfgDirStr := ExtractFileDir(OpenDialog3.FileName) + '\';
    FindResult := FindFirst(CfgDirStr + '*.CFG', faAnyFile, SearchRec);
    if FindResult = 0 then
    begin
      ComboBox14.Text := CfgDirStr + SearchRec.Name;
      Button12Click(Sender);
      Repeat
        ComboBox14.Items.Add(CfgDirStr + SearchRec.Name);
      Until (FindNext(SearchRec) <> 0);
    end;
{
    while FindResult = 0 do
    begin
      ComboBox14.Items.Add(CfgDirStr + SearchRec.Name);
      FindResult := FindNext(SearchRec);
    end;
}
    FindClose(SearchRec);
    Edit3.Text := OpenDialog3.FileName;
    WriteRegistryString('hexfile', OpenDialog3.FileName);
    PageControl2.ActivePage := TabSheet5;
    LoadHexFile(Edit3.Text);
    SetCodeStr();
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  str, buff: string;
begin
  if Edit2.Text <> '' then
  begin
    Memo3.Lines.Clear;
    PageControl2.ActivePage := TabSheet4;
    str := Edit2.Text + GetIspStartStr() + GetIspCtrlStr();
    str := str + GetIspEraseStr();
    str := str + GetIspTimeoutsStr();
    if WinExecAndWait32(str, ShowModeSele, buff) <> 0 then
    begin
      StatusBar1.Panels[1].Text := '擦除操作失败!!!';
    end
    else
    begin
      Memo3.Lines.Add(buff);
      StatusBar1.Panels[1].Text := '擦除操作成功!!!';
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  StringGrid1.ColCount := 17;
  StringGrid1.RowCount := 2;
  StringGrid1.Row := 1;
  StringGrid1.Col := 1;
  StringGrid1.Cells[0, 0] := '地  址';
  StringGrid1.Cells[0, 1] := '0x' + IntToHex(0, 4);
  for i := 0 to 15 do
  begin
    StringGrid1.Cells[i + 1, 0] := IntToHex(i, 2);
  end;
  StringGrid1.ColWidths[0] := Trunc(Length(StringGrid1.Cells[0, 1]) * 7.2);
  for i := 1 to StringGrid1.ColCount - 1 do
  begin
    StringGrid1.ColWidths[i] := Trunc(2.8 * 7.2);
  end;

  StringGrid2.ColCount := 6;
  StringGrid2.RowCount := 2;
  StringGrid2.Row := 1;
  StringGrid2.Col := 1;
  StringGrid2.Cells[0, 0] := '块号';
  StringGrid2.Cells[1, 0] := '起始地址';
  StringGrid2.Cells[2, 0] := '终止地址';
  StringGrid2.Cells[3, 0] := '代码';
  StringGrid2.Cells[4, 0] := '空白';
  StringGrid2.Cells[5, 0] := '编程';
  StringGrid2.Cells[0, 1] := IntToStr(0);
  StringGrid2.ColWidths[0] := Trunc(5 * 7.2);
  StringGrid2.ColWidths[1] := Trunc(10 * 7.2);
  StringGrid2.ColWidths[2] := Trunc(10 * 7.2);
  StringGrid2.ColWidths[3] := Trunc(5 * 7.2);
  StringGrid2.ColWidths[4] := Trunc(5 * 7.2);
  StringGrid2.ColWidths[5] := Trunc(5 * 7.2);

  StringGrid3.ColCount := 5;
  StringGrid3.RowCount := 2;
  StringGrid3.Row := 1;
  StringGrid3.Col := 1;
  StringGrid3.Cells[0, 0] := '序号';
  StringGrid3.Cells[1, 0] := '常量名称';
  StringGrid3.Cells[2, 0] := 'FLASH地址';
  StringGrid3.Cells[3, 0] := '类型';
  StringGrid3.Cells[4, 0] := '数值';
  StringGrid3.Cells[0, 1] := IntToStr(1);
  StringGrid3.ColWidths[0] := Trunc(8 * 7.2);
  StringGrid3.ColWidths[1] := Trunc(10 * 7.2);
  StringGrid3.ColWidths[2] := Trunc(10 * 7.2);
  StringGrid3.ColWidths[3] := Trunc(7 * 7.2);
  StringGrid3.ColWidths[4] := Trunc(10 * 7.2);

  StringGrid4.ColCount := 17;
  StringGrid4.RowCount := 2;
  StringGrid4.Row := 1;
  StringGrid4.Col := 1;
  StringGrid4.Cells[0, 0] := '    地  址';
  StringGrid4.Cells[0, 1] := '0x' + IntToHex($40000000, 8);
  for i := 0 to 15 do
  begin
    StringGrid4.Cells[i + 1, 0] := IntToHex(i, 2);
  end;
  StringGrid4.ColWidths[0] := Trunc(Length(StringGrid4.Cells[0, 1]) * 7.2);
  for i := 1 to StringGrid4.ColCount - 1 do
  begin
    StringGrid4.ColWidths[i] := Trunc(2.8 * 7.2);
  end;
  FMShellSetup();
end;

procedure TForm1.FMShellSetup;
begin
  CheckBox9Click(Sender);
  ComboBox5Change(Sender);
  Edit2.Text := FMExecSystemRegistry;
  PageControl1.ActivePage := TabSheet1;
  if Edit2.Text = '' then
    PageControl3.ActivePage := TabSheet7
  else begin
    Edit2.Enabled := False;
    Button1.Enabled := False;
    Button1.Visible := True;
    Edit2.Text := Copy(Edit2.Text, 2, Length(Edit2.Text) - 2);
    Edit3.Text := ReadRegistryString('hexfile');
    PageControl3.ActivePage := TabSheet8;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  str, buff: string;
  i, m, n: Integer;
begin
  if Edit2.Text <> '' then
  begin
    Memo3.Lines.Clear;
    PageControl2.ActivePage := TabSheet4;
    str := Edit2.Text + GetIspStartStr()
         + GetIspCtrlStr() + GetIspReadSecurityStr();
    if ComboBox12.Text = '指定扇区' then
    begin
      m := StrToInt(ComboBox10.Text);
      n := StrToInt(ComboBox11.Text);
    end
    else
    begin
      m := 0;//全部扇区,'文件扇区'
      n := StrToInt(ComboBox9.Text);
    end;
    for i := m to n do
    begin
      str := str + GetIspBlankCheckStr(i);
    end;
    str := str + GetIspTimeoutsStr();
    if WinExecAndWait32(str, ShowModeSele, buff) <> 0 then
    begin
      StatusBar1.Panels[1].Text := '查空操作失败!!!';
    end
    else
    begin
      LoadDosMessage(buff);
      Memo3.Lines.Add(buff);
      StatusBar1.Panels[1].Text := '查空操作成功!!!';
    end;
  end;
end;

procedure TForm1.CheckBox9Click(Sender: TObject);
begin
  if CheckBox9.Checked then
    ShowModeSele := SW_SHOWNORMAL
  else
    ShowModeSele := SW_HIDE;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  StatusBar1.Panels[3].Text := DateTimeToStr(Now);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  str, buff: string;
begin
  if not FileExists(Edit3.Text) then
  begin
    StatusBar1.Panels[1].Text := '请选择正确的Hex文件!!!';
    Exit;
  end;
  Memo3.Lines.Clear;
  PageControl2.ActivePage := TabSheet4;
  str := Edit2.Text + GetIspStartStr()
       + GetIspCtrlStr() + GetIspReadSecurityStr();
  str := str + GetIspVerifyStr(Edit3.Text);
  str := str + GetIspTimeoutsStr();
  if WinExecAndWait32(str, ShowModeSele, buff) <> 0 then
  begin
    StatusBar1.Panels[1].Text := '校验操作失败!!!';
  end
  else
  begin
    Memo3.Lines.Add(buff);
    StatusBar1.Panels[1].Text := '校验操作成功!!!';
  end;
end;

procedure TForm1.ComboBox5Change(Sender: TObject);
var
  i, Sector: Integer;
begin
  Sector := GetDeviceFlashSize(ComboBox5.Text);
  if Sector > 0 then
  begin
    ComboBox9.Items.Clear;
    ComboBox10.Items.Clear;
    ComboBox11.Items.Clear;
    for i := 0 to Sector do
    begin
      ComboBox9.Items.Add(IntToStr(i));
      ComboBox10.Items.Add(IntToStr(i));
      ComboBox11.Items.Add(IntToStr(i));
      StringGrid2.RowCount := i + 2;
      StringGrid2.Cells[0, i + 1] := IntToStr(i);
      StringGrid2.Cells[1, i + 1] := '0x' + IntToHex(GetSectorTop(i), 8);
      StringGrid2.Cells[2, i + 1] := '0x' + IntToHex(GetSectorBottom(i), 8);
    end;
    ComboBox9.Text := IntToStr(Sector);
    ComboBox10.Text := '0';
    ComboBox11.Text := IntToStr(Sector);
  end;
end;

procedure TForm1.CheckBox8Click(Sender: TObject);
var
  val: DWord;
begin
  val := GetStringGridDWord($1fc);
  if val = $87654321 then CheckBox8.Checked := True
  else if val <> $ffffffff then  CheckBox8.Checked := False;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := false;
  if Application.MessageBox('请您确认是否退出???', '系统提示:退出将会丢失数据!!!', MB_YESNO) = IDYES then begin
    if Application.MessageBox('请您再次确认是否退出???', '系统提示:退出将会丢失数据!!!', MB_YESNO) = IDYES then begin
      Comm1.PortOpen := false;
      MediaPlayer1.Close;
      CanClose := true;
    end;
  end
end;

procedure TForm1.ComboBox12Change(Sender: TObject);
begin
  if ComboBox12.Text = '全部扇区' then
  begin
    ComboBox9.Text := ComboBox9.Items.Strings[ComboBox9.Items.Count - 1];
    ComboBox9.Enabled := True;
    ComboBox10.Enabled := False;
    ComboBox11.Enabled := False;
  end
  else if ComboBox12.Text = '文件扇区' then
  begin
    if Edit4.Text = '' then
    begin
      StatusBar1.Panels[1].Text := '请选择一个合法的Hex文件!!!';
    end
    else
    begin
      ComboBox9.Text := IntToStr(GetSectorNumber(StrToInt(Edit4.Text) - 1));
      ComboBox9.Enabled := True;
      ComboBox10.Enabled := False;
      ComboBox11.Enabled := False;
    end;
  end
  else
  begin//指定扇区
    ComboBox9.Enabled := False;
    ComboBox10.Enabled := True;
    ComboBox11.Enabled := True;
  end;
end;

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
  Key := #0;
end;

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if not ((Key >= '0') and (Key <= '9') or (Key >= 'A') and (Key <= 'F') or (Key >= 'a') and (Key <= 'f')) then
    Key := #0;
end;

procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol,
  ARow: Integer; var Value: String);
var
  Address: Integer;
  hexval: Integer;
  ch: Char;
begin
  if Value <> '' then
  begin
    Value := IntToHex(StrToInt('$' + Value), 2);
    Address := (ARow - 1) * 16 + (ACol - 1);
    hexval := StrToInt('$' + Value);
    if (hexval >= $1f) and (hexval < $7f) then ch := Char(hexval)
    else ch := '.';
    StatusBar1.Panels[1].Text := '地址:0x' +  IntToHex(Address, 8)
                        + ' 数值:(B:' + ch + ' ' + IntToStr(StrToInt('$' + Value))
                             + ', W:' + IntToStr(GetStringGridWord(Address))
                             + ', D:' + IntToStr(GetStringGridDWord(Address)) + ')';
  end;
end;

procedure TForm1.CheckBox11Click(Sender: TObject);
begin
  StringGrid1.EditorMode := CheckBox11.Checked;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  PageControl2.ActivePage := TabSheet5;
  LoadHexFile(Edit3.Text);
  SetCodeStr();
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  StringGrid3.RowCount := StringGrid3.RowCount + 1;
  StringGrid3.Cells[0, StringGrid3.RowCount - 1] := IntToStr(StringGrid3.RowCount - 1);

end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  StringGrid3.RowCount := 2;
  StringGrid3.Cells[0, 1] := IntToStr(1);
  StringGrid3.Cells[1, 1] := '';
  StringGrid3.Cells[2, 1] := '';
  StringGrid3.Cells[3, 1] := '';
  StringGrid3.Cells[4, 1] := '';
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
//  StringGrid3.
  StringGrid3.RowCount := StringGrid3.RowCount - 1;
end;

procedure TForm1.Button12Click(Sender: TObject);
var
  filename, str, s: string;
  i, len, state, count: Integer;
  CfgFile: TextFile;
begin
  filename := ComboBox14.Text;
  if not FileExists(filename) then
    StatusBar1.Panels[1].Text := '文件不存在,请选择一个文件!!!'
  else
  begin
    Button11Click(Sender);//清空
    state := 0;
    count := 0;
    AssignFile(CfgFile, FileName);
    Reset(CfgFile);
    try
      while not Eof(CfgFile) do
      begin
        Readln(CfgFile, str);
        len := Length(str);
        s := '';
        for i := 1 to len do
        begin
          if state = 0 then
          begin
            if str[i] <> ':' then
              s := s + str[i]
            else
            begin
              if s = 'SN' then
                state := 1
              else if s = 'FLASH' then
                state := 2;
              count := 0;
              s := '';
            end;
          end
          else
          begin
            if str[i] <> ';' then
              s := s + str[i]
            else
            begin
              count := count + 1;
              if state = 1 then//SN
              begin
                case count of
                  1: Edit5.Text := s;
                  2: ComboBox13.Text := s;
                  3: begin
                      Edit6.Text := s;
                      state := 0;
                      count := 0;
                     end;
                end;
              end
              else if state = 2 then//FLASH
              begin
                case count of
                  1: begin
                       if StringGrid3.Cells[2, StringGrid3.RowCount - 1] <> '' then
                         StringGrid3.RowCount := StringGrid3.RowCount + 1;
                       StringGrid3.Cells[0, StringGrid3.RowCount - 1] := IntToStr(StringGrid3.RowCount - 1);
                       StringGrid3.Cells[1, StringGrid3.RowCount - 1] := s;
                     end;
                  2: begin
                       StringGrid3.Cells[2, StringGrid3.RowCount - 1] := s;
                     end;
                  3: begin
                       StringGrid3.Cells[3, StringGrid3.RowCount - 1] := s;
                     end;
                  4: begin
                       StringGrid3.Cells[4, StringGrid3.RowCount - 1] := s;
                       count := 0;
                       state := 0;
                     end;
                end;
              end
              else state := 0;
              s := '';
            end;
          end
        end;
      end;
    finally
      CloseFile(CfgFile);
    end;
  end;
end;

procedure TForm1.Button13Click(Sender: TObject);
var
  filename, str, s: string;
  i, len, count: Integer;
  CfgFile: TextFile;
begin
  if Edit3.Text = '' then
  begin
    StatusBar1.Panels[1].Text := '请选择一个Hex文件!!!';
    Exit;
  end;
  len := Length(Edit3.Text);
  filename := Copy(Edit3.Text, 1, len - 4) + '_' + Edit6.Text + '.CFG';
  if Not FileExists(filename) then
  begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -