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

📄 gjj.txt

📁 单片机编程的一款好软件
💻 TXT
字号:
procedure TForm1.FormCreate(Sender: TObject);            // 程序启动事件
begin
  comm1.StartComm;
  StringGrid1.ColWidths[0]:=45;                           //定义第一列的宽度 //if StringGrid1.Cells[1,0]='' then
  StatusBar1.Panels[1].Text:='    单元格的坐标:[0,0]';   // 初始化状态栏单元格坐标
  StatusBar1.Panels[2].Text:='    本页首地址为:[ 空  ]'; // 初始化状态栏本页首地址
end;

procedure TForm1.SpeedButton8Click(Sender: TObject);     // <退出>按钮处理事件(程序退出)
begin Application.Terminate; end;

procedure TForm1.SpeedButton7Click(Sender: TObject);     // <打开>按钮处理事件(读取数据)
var i,j,k,l,m,n:integer;
begin LL:=0;
 for i:=0 to StringGrid1.ColCount do for j:=0 to StringGrid1.RowCount do StringGrid1.Cells[i,j]:='';   // 清空所有单元
 for i:=0 to 15 do begin if i<10 then k:=i+$30 else k:=i+$37; StringGrid1.Cells[i+1,0]:=char(k) end;   // 填充行头0~F(列行)

 Memo1.Text:=''; BitBtn1.Enabled:=False;                // <仿内存格式填充数据>按钮不可用
 OpenDialog1.FilterIndex:=RadioGroup2.ItemIndex;         //取文件类型
 if OpenDialog1.Execute then begin  Memo1.Lines.LoadFromFile(opendialog1.FileName);       //读文件到 memo
  case RadioGroup2.ItemIndex of
  0:begin StringGrid1.RowCount:=MemoLines+1;   BitBtn1.Enabled:=True;    //hex文件的原型读入,只能看,不能写入。
     for j:=0 to Memo1.Lines.Count do StringGrid1.Cells[0,j+1]:=copy(Memo1.Lines[j],4,4); // 填充列头-取地址
     for i:=1 to Memo1.Lines.Count-1 do for j:=1 to strtoint('$'+copy(Memo1.Lines[i-1],2,2)) do      StringGrid1.Cells[j,i]:=copy(Memo1.Lines[i-1],8+j*2,2); //取个数  数据格式=空格+:+个数+地址+00+数据+校验
    end;
  1:begin
     StringGrid1.RowCount:=(strtoint('$'+copy(Memo1.Lines[MemoLines-2],4,4))div $10)+3;    //标准方式 取总行数
     for i:=0 to StringGrid1.RowCount do begin MDStr:=format('%x',[i*$10]); //MDStr:=inttohex(i*16); 得到地址                                                              // 生成十六进制地址
      case length(MDStr) of 2: MDStr:='00'+MDStr; 3:MDStr:='0'+MDStr;end;                 //地址前面补0
      StringGrid1.Cells[0,i+1]:=MDStr;                                                    // 填充地址
     end;
     for i:=0 to Memo1.Lines.Count-1 do begin                                             // 填充数据
      m:=strtoint('$'+copy(Memo1.Lines[i],4,4));     l:=m mod $10;                        // 取地址 取余数
      n:=strtoint('$'+copy(Memo1.Lines[i],2,2));                                          // 取本行数据的个数
      for j:=1 to n do                                                                    // 循环填充数据
       if l=0 then StringGrid1.Cells[j,(m div $10)+1]:=copy(Memo1.Lines[i],8+j*2,2)       // j 是列
       else if j<=$10-l then StringGrid1.Cells[j+l,m div $10+1]:=copy(Memo1.Lines[i],8+j*2,2)
       else StringGrid1.Cells[j-($10-l),m div $10+2]:=copy(Memo1.Lines[i],8+j*2,2);
     end;
    end;
  2:begin
     n:=length(Memo1.Text);
     StringGrid1.RowCount:=n div 32;                                       // 动态控制单元个行数
     for i:=0 to StringGrid1.RowCount do begin MDStr:=format('%x',[i*$10]); //MDStr:=inttohex(i*16) 生成十六进制地址
      case length(MDStr) of 2: MDStr:='00'+MDStr; 3:MDStr:='0'+MDStr;end;                 //地址前面补0
      StringGrid1.Cells[0,i+1]:=MDStr;                                                    // 输出列表头
     end;
     for i:=0 to (n div 32) do                      // 循环填充数据  n是字符个数
      for j:=0 to 16 do StringGrid1.Cells[j+1,i+1]:=copy(Memo1.Text,i*32+j*2+1,2);  //i,j为0时,相当于从第1个,拷两个
     end;
  3:begin
     n:=2*strtoint('$'+copy(Memo1.Text,5,4));  //取出个数  格式是首地址+数据个数  共8个字符
     memo1.Text:=copy(memo1.Text,9,n);              //n是指令字节数--占两个字符
     StringGrid1.RowCount:=n div 32;                                       // 动态控制单元个行数
     for i:=0 to StringGrid1.RowCount do begin MDStr:=format('%x',[i*$10]); //MDStr:=inttohex(i*16) 生成十六进制地址
      case length(MDStr) of 2: MDStr:='00'+MDStr; 3:MDStr:='0'+MDStr;end;                 //地址前面补0
      StringGrid1.Cells[0,i+1]:=MDStr;                                                    // 输出列表头
     end;
     for i:=0 to (n div 32) do                      // 循环填充数据  n是字符个数
      for j:=0 to 16 do StringGrid1.Cells[j+1,i+1]:=copy(Memo1.Text,i*32+j*2+1,2);  //i,j为0时,相当于从第1个,拷两个
    end;
  end;
  ScrollBar1.Position:=0;                          // 卷滚条在最上面
  case RadioGroup3.ItemIndex of 0:MDStr:=''; 1:MDStr:='00'; 2:MDStr:='FF';end;
   for i:=1 to StringGrid1.RowCount-2 do                                                   // 循环填充空白单元格
    for j:=1 to  StringGrid1.ColCount do begin LL:=LL+1;
     if StringGrid1.Cells[j,i]='' then StringGrid1.Cells[j,i]:=MDStr; end;                 // 填充空白单元格
 end;
end;
//     StringGrid1.Cells[0,StringGrid1.RowCount-1]:='0000';                                // 数据表末行补'0000'结束标志

procedure TForm1.BitBtn1Click(Sender: TObject);          // <仿内存格式填充数据>按钮处理事件
var i,j,m,n,l:integer;
begin                                                    // 填充数据前的准备
  StringGrid1.RowCount:=strtoint('$'+copy(Memo1.Lines[MemoLines-2],4,4)) div $10+3;                   //的行数
  for i:=0 to StringGrid1.ColCount do for j:=0 to StringGrid1.RowCount do StringGrid1.Cells[i,j]:=''; // 清空列表
  for i:=0 to StringGrid1.RowCount do begin                                                           // 生成列表头
   MDStr:=format('%x',[i*$10+$10-$10]);                                                               // 生成十六进
   if length(MDstr)<2 then MDStr:='000'+MDStr                                                         // 地址补零
   else if length(MDstr)<3 then MDStr:='00'+MDStr                                                     // 地址补零
   else if length(MDstr)<4 then MDStr:='0'+MDStr;                                                     // 地址补零
   StringGrid1.Cells[0,i+1]:=MDStr;                                                                   // 输出列表头
  end;                                                                                              // 开始填充数据
  for i:=0 to Memo1.Lines.Count-1 do begin                                                            // 循环填充数据
    m:=strtoint('$'+copy(Memo1.Lines[i],4,4));                                                        // 取地址
    n:=strtoint('$'+copy(Memo1.Lines[i],2,2));                                                        // 取数据的个数
    l:=m mod $10;
    for j:=1 to n do                                                                                  // 循环填充数据
     if l=0 then StringGrid1.Cells[j,m div $10+1]:=copy(Memo1.Lines[i],8+j*2,2)
     else if j<=$10-l then StringGrid1.Cells[j+l,m div $10+1]:=copy(Memo1.Lines[i],8+j*2,2)
     else StringGrid1.Cells[j-($10-l),m div $10+2]:=copy(Memo1.Lines[i],8+j*2,2);
  end;
  StringGrid1.Cells[0,StringGrid1.RowCount-1]:='0000';                                                //'0000'标志
  BitBtn1.Enabled:=False;                                                     // <仿内存格式填充数据>按钮不可用
end;

procedure TForm1.Memo1Change(Sender: TObject);                      // Memo 中文本变化时,自动保存文本行数
begin  MemoLines:=Memo1.Lines.Count; end;

procedure TForm1.SpeedButton6Click(Sender: TObject);                // <保存>按钮处理事件
var i,j:integer;                                                    // 定义循环变量
begin                                                               // 读取纯数据
  Memo1.Text:='';                                                   // 清空Memo
  MDStr:='';                                                        // 清空字符串中间变量
  for i:=1 to StringGrid1.RowCount do                              // 双层循环保存纯数据(包括单元格)
   for j:=1 to StringGrid1.ColCount-1 do
    if StringGrid1.Cells[j,i]='' then MDStr:=MDStr+'  '             // 如果单元格为空补'空格'符
    else MDStr:=MDStr+StringGrid1.Cells[j,i];                       // 如果单元格为非空则存取数据
  Memo1.Text:=MDStr;                                                // 保存数据到Memo中
                                                                    // 保存数据到文件
  if SaveDialog1.Execute then begin                                 // 保存数据到文件
    MDStr:=SaveDialog1.Filename;
    Memo1.Lines.SaveToFile(MDStr);
  end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);          // <立即清空数据单元格>按钮处理事件
var i,j:integer;                                                   // 定义循环变量
begin
  StringGrid1.RowCount:=50;                                        // 动态更新数据表的行数
  for i:=0 to StringGrid1.ColCount do                              // 循环清空列表
   for j:=0 to StringGrid1.RowCount do
    StringGrid1.Cells[i,j]:='';
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);      // 卷滚条滚动处理事件
begin
 ScrollBar1.Max:=StringGrid1.RowCount-18;                          // 卷滚条赋初值
 StringGrid1.TopRow:=ScrollBar1.Position+1;                        // 卷滚条滚动时拖动单元格页面变化
 if ScrollBar1.Position>0 then SpeedButton5.Enabled:=True;          // <上一页>按钮可用
 if ScrollBar1.Position<ScrollBar1.Max then SpeedButton2.Enabled:=True;                   // <下一页>按钮不用
 StatusBar1.Panels[2].Text:='    本页首地址为:'+StringGrid1.Cells[0,StringGrid1.TopRow]; // 状态栏显示本页首地址
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);               // <上一页>按钮处理事件
begin
  if ScrollBar1.Position<=ScrollBar1.Max then ScrollBar1.Position:=ScrollBar1.Position-17;    // 向上翻页
  if ScrollBar1.Position=0 then SpeedButton5.Enabled:=False;                                  // <上一页>按钮不可用
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);             // <下一页>按钮处理事件
begin                                                                                        // 向下翻页
  if ScrollBar1.Position>=0 then ScrollBar1.Position:=ScrollBar1.Position+17;                // <下一页>按钮不可用
  if ScrollBar1.Position=ScrollBar1.Max then SpeedButton2.Enabled:=False;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
begin
 if StringGrid1.Cells[1,0]='' then StatusBar1.Panels[1].Text:=format(' 单元格的坐标:[%d,%d]',[ARow-1,ACol-1]) // 状态栏
 else StatusBar1.Panels[1].Text:=format(' 单元格的地址坐标:[%s,%x]',[StringGrid1.Cells[0, ARow], ACol-1]);
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
var s:string;
begin
  progressbar1.Visible :=true;                         //进度尺
  progressbar1.Min :=0;                                //最小值
  progressbar1.Max :=100;                              //最大值
  progressbar1.step:=1;                                //步进
  progressbar1.StepIt;                                 //进度尺
  s:=char($15);
  comm1.WriteCommData(pchar(s),1);
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word);
var i:integer; s,y:string;
begin  s:='';
 setlength(s,bufferlength);
 move(buffer^,pchar(s)^,bufferlength);      //只要有就移 ^是取数据,@是取地址
  if byte(s[1])=$5A then  begin
   edit1.Text :='ok';
   comm1.WriteCommData(pchar(y),length(y));
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin COMM1.StopComm; end;

end.

⌨️ 快捷键说明

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