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

📄 unit1.~pas

📁 Philips ARM lpc2000家族ISP下载源码集成了串口调试助手源码是个非常优秀的软件
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
    ComboBox14.Items.Add(filename);
  end
  else
  begin
    if Application.MessageBox('请您确认是否覆盖???', '系统提示:写入配置文件!!!', MB_YESNO) = IDNO then
      Exit;
    if Application.MessageBox('请您再次确认是否覆盖???', '系统提示:写入配置文件!!!', MB_YESNO) = IDNO then
      Exit;
  end;
  begin
    ComboBox14.Text := filename;
    AssignFile(CfgFile, FileName);
    Rewrite(CfgFile);
    try
      str := 'SN:';
      str := str + Edit5.Text;//地址
      str := str + ';';
      str := str + ComboBox13.Text;//类型
      str := str + ';';
      str := str + Edit6.Text;//系列码
      str := str + ';';
      Writeln(CfgFile, str);
      for i := 1 to StringGrid3.RowCount - 1 do
      begin
        if (StringGrid3.Cells[2, i] <> '') and (StringGrid3.Cells[3, i] <> '') and (StringGrid3.Cells[4, i] <> '') then
        begin
          str := 'FLASH:';
          str := str + StringGrid3.Cells[1, i];//名称
          str := str + ';';
          str := str + StringGrid3.Cells[2, i];//地址
          str := str + ';';
          str := str + StringGrid3.Cells[3, i];//类型
          str := str + ';';
          str := str + StringGrid3.Cells[4, i];//数值
          str := str + ';';
          Writeln(CfgFile, str);
        end;
      end;
    finally
      CloseFile(CfgFile);
    end;
  end;
end;

procedure TForm1.Button14Click(Sender: TObject);
var
  i, j, len, address: integer;
  str: string;
  Bval, Bvar: Byte;
  Wval, Wvar: Word;
  Dval, Dvar: Dword;
begin
  for i := 1 to StringGrid3.RowCount - 1 do
  begin
    if (StringGrid3.Cells[2, i] <> '') and (StringGrid3.Cells[3, i] <> '') and (StringGrid3.Cells[4, i] <> '') then
    begin
      str := StringGrid3.Cells[2, i];//地址
      if str[1] <> '0' then
        address := StrToInt(str)
      else
      begin
        Delete(str, 1, 2);
        address := StrToInt('$' + str);
      end;
      str := StringGrid3.Cells[3, i];//类型
      if str = '短整型' then
      begin
        str := StringGrid3.Cells[4, i];
        if str[1] <> '0' then
          Wvar := StrToInt(str)
        else
        begin
          Delete(str, 1, 2);
          Wvar := StrToInt('$' + str);
        end;
        Wval := GetStringGridWord(address);
        if Wval <> $ffff then
        begin
          if Wval = Wvar then
            StringGrid3.Cells[0, i] := IntToStr(i)
          else
            StringGrid3.Cells[0, i] := IntToStr(i) + '***';
        end
        else
        begin
          SetStringGridWord(address, Wvar);
          StringGrid3.Cells[0, i] := IntToStr(i);
        end;
      end
      else if str = '整型' then
      begin
        str := StringGrid3.Cells[4, i];
        if str[1] <> '0' then
          Dvar := StrToInt(str)
        else
        begin
          Delete(str, 1, 2);
          Dvar := StrToInt('$' + str);
        end;
        Dval := GetStringGridDWord(address);
        if Dval <> $ffffffff then
        begin
          if Dval = Dvar then
            StringGrid3.Cells[0, i] := IntToStr(i)
          else
            StringGrid3.Cells[0, i] := IntToStr(i) + '***'
        end
        else
        begin
          SetStringGridDWord(address, Dvar);
          StringGrid3.Cells[0, i] := IntToStr(i);
        end;
      end
      else if str = '字符型' then
      begin
        len := Length(StringGrid3.Cells[4, i]);//数值
        str := StringGrid3.Cells[4, i];
        for j := 1 to len do
        begin
          Bvar := Byte(str[j]);
          Bval := GetStringGridByte(address);
          if Bval <> $ff then
          begin
            if Bval = Bvar then
              StringGrid3.Cells[0, i] := IntToStr(i)
            else
              StringGrid3.Cells[0, i] := IntToStr(i) + '***';
          end
          else
          begin
            SetStringGridByte(address, Bvar);
            StringGrid3.Cells[0, i] := IntToStr(i);
          end;
          address := address + 1;
        end;
      end;
    end;
  end;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  SetUserIDStr();
end;


procedure TForm1.RadioButton1Click(Sender: TObject);
begin
  if RadioButton1.Checked then
  begin
    Comm1.CommPort := StrToInt(Copy(ComboBox1.Text, 4, 1));
    Comm1.BaudRate := StrToInt(ComboBox2.Text);
    Comm1.PortOpen := True;
    if Comm1.PortOpen then
    begin
      StatusBar1.Panels[1].Text := '       串口已被打开';
    end
    else
    begin
      StatusBar1.Panels[1].Text := '无此串口或该串口已被打开';
      RadioButton1.Checked := False;
      RadioButton2.Checked := True;
    end;
  end
  else
  begin
    Comm1.PortOpen := False;
    StatusBar1.Panels[1].Text := '       串口已被关闭';
  end;
  RxBuffers := '';
  RxBufferCount := 0;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
    Comm1.DtrControl := DtrEnable
  else
    Comm1.DtrControl := DtrDisable;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked then
    Comm1.RtsControl := RtsEnable
  else
    Comm1.RtsControl := RtsDisable;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  if Comm1.PortOpen then
  begin
    RadioButton2.Checked := True;
    RadioButton1.Checked := True;
  end;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  RxCount := 0;
  Edit7.Text := IntToStr(RxCount);
end;

procedure TForm1.Button19Click(Sender: TObject);
var
  str, s: string;
  i, j: Integer;
begin
  for i := 0 to Memo2.Lines.Count - 1 do
  begin
    str := Memo2.Lines.Strings[i];//取1行数据
    if CheckBox17.Checked then//16进制显示
    begin
      if str <> '' then
      begin
        s := '';
        for j := 1 to Length(str) do
        begin
          if str[j] > ' ' then
          begin
            s := s + str[j];
            if (j = Length(str)) and (Length(s) = 2) then
            begin
              Comm1.Output := Char(StrToInt('$' + s));
              TxCount := TxCount + 1;
              Edit8.Text := IntToStr(TxCount);
              s := '';
            end;
          end
          else
          begin
            if Length(s) = 2 then
            begin
              Comm1.Output := Char(StrToInt('$' + s));
              TxCount := TxCount + 1;
              Edit8.Text := IntToStr(TxCount);
            end;
            s := '';
          end;
        end;
      end;
    end
    else//ascii码或汉字
    begin
      if CheckBox18.Checked then str := str +#$0d;
      if CheckBox19.Checked then str := str +#$0a;
      Comm1.Output := str;
      TxCount := TxCount + Length(str);
      Edit8.Text := IntToStr(TxCount);
    end;
  end;
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
  Memo2.Lines.Clear;
  TxCount := 0;
  Edit8.Text := IntToStr(TxCount);
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: PAnsiChar;
  BufferLength: Word);
var
  ch: Char;
  i, k: integer;
  str: String;
begin
  RxCount := RxCount + BufferLength;
  Edit7.Text := IntToStr(RxCount);
  if CheckBox15.Checked then Exit;//暂停显示
  if CheckBox16.Checked then//16进制显示
  begin
    for i := 0 to BufferLength - 1 do
    begin
      ch := Buffer[i];//取1个数据
      RxBuffers := RxBuffers + ch;
      RxBufferCount := RxBufferCount + 1;
      if RxBufferCount = 16 then
      begin
        str := '';
        for k := 1 to 16 do
        begin
          str := str + IntToHex(Byte(RxBuffers[k]), 2);
          if k < 16 then str := str + ' ';
        end;
        Memo1.Lines.Add(str);
        RxBuffers := '';
        RxBufferCount := 0;
      end;
    end;
  end
  else
  begin
    for i := 0 to BufferLength - 1 do
    begin
      ch := Buffer[i];//取1个数据
      if ch >= ' ' then
      begin
        RxBuffers := RxBuffers + ch;
      end
      else if ch = #$0a then
      begin
        Memo1.Lines.Add(RxBuffers);
        RxBuffers := '';
        RxBufferCount := 0;
      end;
    end;
  end;
end;

function TForm1.ReadIspStatus(FileName: string): string;
var
  str, buff: string;
begin
  str := FileName
       + GetIspStartStr()
       + GetIspCtrlStr()
       + GetIspReadSecurityStr()
       + GetIspTimeoutsStr();
  if WinExecAndWait32(str, ShowModeSele, buff) <> 0 then
    Result := ''
  else
    Result := buff;
end;

procedure TForm1.Button20Click(Sender: TObject);
var
  str, buff: string;
begin
  Memo3.Lines.Clear;
  PageControl2.ActivePage := TabSheet4;
  str := Edit2.Text
   + GetIspStartStr()
   + GetIspCtrlStr()
   + GetIspReadSecurityStr()
   + ' READSTATUSBIT'//112//2.11????
   + ' INTERFACE(NXPICPBRIDGE)'
   + 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.Button21Click(Sender: TObject);
var
  str, buff: string;
begin
  Memo3.Lines.Clear;
  PageControl2.ActivePage := TabSheet4;
  str := Edit2.Text + GetIspStartStr() + GetIspCtrlStr();
  str := str + ' READADDLSECURITY';//112
  str := str + GetIspTimeoutsStr();
  if WinExecAndWait32(str, ShowModeSele, buff) <> 0 then
  begin
    StatusBar1.Panels[1].Text := '读RAM操作失败!!!';
  end
  else
  begin
    Memo3.Lines.Add(buff);
    StatusBar1.Panels[1].Text := '读RAM操作成功!!!';
  end;
end;

function TForm1.ReadRegistryString(RegString: String): String;
var
  Reg: TRegistry;
  str: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey:=HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Embedded Systems Academy\FlashMagic', True) then
    begin
      str := Reg.ReadString(RegString);
    end;
  finally
    Reg.Free;
    inherited;
  end;
  Result := str;
end;

procedure TForm1.WriteRegistryString(RegString, str: String);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey:=HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Embedded Systems Academy\FlashMagic', True) then
    begin
      Reg.WriteString(RegString, str);
    end;
  finally
    Reg.Free;
    inherited;
  end;
end;

function TForm1.FMExecSystemRegistry: string;
var
  Reg: TRegistry;
  str: string;
//Keil注册表
  Mag0: string;//DEVICE(LPC2138, 11.0592) COM(1,28800) HARDWARE(BOOTEXEC, 25, 250) ERASE(DEVICE, PROTECTISP) HEXFILE(#H, NOCHECKSUMS, NOFILL, NOPROTECTISP, CODEREADPROTECTION) VERIFY(#H, NOCHECKSUMS)
  Mex0: string;//D:\Program Files\Flash Magic\FM.EXE
//flashmagic注册表
  hexfile: string;
  exefile: string;
begin
  Reg := TRegistry.Create;
  try
    Mag0 := '';
    Mex0 := '';
    Reg.RootKey:=HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Keil\μVision3\ToolM', False) then
    begin
      Mag0 := Reg.ReadString('Mag0');
      Mex0 := Reg.ReadString('Mex0');
    end;

    hexfile := '';
    Reg.RootKey:=HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Embedded Systems Academy\FlashMagic', False) then
    begin
      hexfile := Reg.ReadString('hexfile');
    end;

    Reg.RootKey:=HKEY_CLASSES_ROOT;
    if Reg.OpenKey('\Applications\flashmagic.exe\shell\open\command', False) then
    begin
      exefile := Reg.ReadString('');//默认
      if exefile <> '' then
      begin
        if Reg.OpenKey('\Applications\flashmagic.exe\shell\console\command', True) then
        begin
          str := Reg.ReadString('');
          if str = '' then
          begin
            str := ExtractFilePath(exefile);
            str := str + 'FM.EXE"';
            Reg.WriteString('', str);
          end;
        end;
      end;
    end;
{
    Reg.RootKey:=HKEY_CLASSES_ROOT;
    if Reg.OpenKey('\FlashMagicSettings\shell\open\command', False) then
    begin
      Close;
    end;
}
    Reg.RootKey:=HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\HotPower\FMExec\Settings', True) then
    begin
      if Mag0 <> '' then
        if Reg.ReadString('Mag0') = '' then
          Reg.WriteString('Mag0', Mag0);
      if Mex0 <> '' then
        if Reg.ReadString('Mex0') = '' then
          Reg.WriteString('Mex0', Mex0);
      if hexfile <> '' then
        if Reg.ReadString('hexfile') = '' then
          Reg.WriteString('hexfile', hexfile);
    end;
  finally
    Reg.Free;
    inherited;
  end;
  Result := str;
end;

end.

⌨️ 快捷键说明

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