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

📄 unit1.pas

📁 单片机编程的一款好软件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Grids, Buttons,
  Menus, ComCtrls, ToolWin, ImgList, SPComm,inifiles;
type
  TForm1 = class(TForm) Bevel1: TBevel; BitBtn2: TBitBtn;
    RadioGroup1: TRadioGroup;
    RadioButton2: TRadioButton;
    RadioButton1: TRadioButton;
    ToolBar1: TToolBar;       StatusBar1: TStatusBar;   ProgressBar1: TProgressBar;
    ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton;
    ToolButton4: TToolButton; ToolButton5: TToolButton; ToolButton19: TToolButton;   ToolButton31: TToolButton;
    Label1: TLabel;       Label2: TLabel;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton6: TSpeedButton; SpeedButton7: TSpeedButton; SpeedButton8: TSpeedButton;
    StringGrid1: TStringGrid; Edit1: TEdit; RadioGroup2: TRadioGroup;
    Comm1: TComm;
    comm11: TMenuItem;
    comm21: TMenuItem;
    H1: TMenuItem;
    A1: TMenuItem;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    ToolButton6: TToolButton;
    SpeedButton5: TSpeedButton;
    procedure SpeedButton8Click(Sender: TObject);     procedure FormCreate(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);     procedure BitBtn2Click(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
    procedure SpeedButton3Click(Sender: TObject);
    procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;  BufferLength: Word);
//    function hex(c:char): integer;
   procedure  rdic(Sender:TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
  private { Private declarations }
  public  { Public declarations }
end;

var Form1: TForm1;  s,sz:string; ia,ja,LL,w:integer; file1,file2:tfilestream;
    buf:array[1..65536]of char;  read,comp:bool;     myini:tinifile;       //buf从0开始可以与字符串相容
implementation

uses Unit2;  {$R *.dfm}


//function Tform1.hex(c:char): integer;
//begin if c<'A' then result:=word(c)-$30 else result:=word(c)-$37; end;
procedure TFORM1.rdic(Sender: TObject);
begin
 read:=true; ja:=1; ia:=1;
 case RadioGroup1.ItemIndex of
  0: begin s:=char($07); sz:='0800' end;    //2051
  1: begin s:=char($05); sz:='1000' end;    //89c51  if checkbox1.Checked then sz:='1fff' else sz:='0fff' end
  2: begin s:=char($06); sz:='2000' end;    //89c52
  3: begin s:=char($05); sz:='1000' end;    //89s51
  4: begin s:=char($06); sz:='2000' end;    //89s52
  5: begin s:=char($08); sz:='4000' end;    //89s53
  6: begin s:=char($01); sz:='2000' end;    //2764
  7: begin s:=char($01); sz:='2000' end;    //2864
 end; LL:= strtoint('$'+sz);  w:=LL;
 comm1.WriteCommData(pchar(s),1);          //发出控制码
 progressbar1.Min :=0;                     //最小值
 progressbar1.Max :=LL;                    //最大值
 progressbar1.step:=256;                   //步进  progressbar1.StepIt;

end;

procedure TForm1.FormCreate(Sender: TObject);                // 程序启动事件
var i,k:integer;   adr:string;
begin read:=false; comp:=false;
   myini:=tinifile.Create('write.ini');
   radiogroup1.ItemIndex:=myini.Readinteger('芯片选择','型号',1);
   radiogroup2.ItemIndex:=myini.Readinteger('文件格式','类型',1);  //默认
//  comm1.DtrControl:=dtrenable;
//  comm1.RtsControl:=rtsdisable;
  comm1.IgnoreNullChar:=false;
  comm1.Inx_XonXoffFlow:=false;    //true: when point=xoff send xoff and when point=xon send xon ; false:nothing;
  comm1.Outx_XonXoffFlow:=false;   //true: get xoff stop and get xon start; false:nothing;
  comm1.CommName:='com1';
  comm1.TxContinueOnXoff:=true;    //true: when stop;  false:when start
  comm1.StartComm;   s:='0000';
  StringGrid1.ColWidths[0]:=45;    //定义第一列的宽度 //if StringGrid1.Cells[1,0]='' then
  stringgrid1.RowCount:=$201;      //8k:=1FFFh 这里是行数,所以是高3位。
  progressbar1.Visible:=true;                  //进度尺
  progressbar1.step:=1;                        //步进  progressbar1.StepIt;
  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(列行)
  for i:=0 to stringgrid1.RowCount do begin  adr:=format('%x',[i*$10]);  //d:10进制 x:16进制
   StringGrid1.Cells[0,i+1]:=copy(s,1,4-length(adr))+adr;                //填充地址
  end;
  StringGrid1.Cells[0,0]:='地址';
  form1.Caption :='  欢迎使用 一点通编程器';
end;

procedure TForm1.SpeedButton7Click(Sender: TObject);           //打开文件读
var i,j,m,n,nk,x,y,yi,xa:integer;
begin   speedbutton3.Enabled :=true;                           //写按扭
 for i:=1 to  StringGrid1.RowCount do for j:=1 to 17 do if radiobutton1.Checked then StringGrid1.Cells[j,i]:='FF' else StringGrid1.Cells[j,i]:='00';   //先清空格子
 OpenDialog1.FilterIndex:=RadioGroup2.ItemIndex+1;             //取文件类型 一个从0开始,一个从1开始
 if OpenDialog1.Execute then begin  LL:=0; y:=0;
  file1:=tfilestream.Create(opendialog1.FileName,fmopenread);  // setlength(buf,file1.size);
  file1.read(buf,file1.size);    n:=1; nk:=0; x:=0;            //n:字符指针
  form1.Caption :='当前读入文件是:'+opendialog1.FileName;             //显示读入的文件名
  case RadioGroup2.ItemIndex of                                //读入文件类型
  1:begin                                                      //标准hex
     while n<file1.Size do begin
      if buf[n]=':'then if buf[n+1]='1' then nk:=16 else nk:=strtoint('$'+(buf[n+2]));   //取个数
      x:=strtoint('$'+buf[n+3]+buf[n+4]+buf[n+5]); y:=strtoint('$'+(buf[n+6]));  n:=n+9; //取地址:xy (行列)
      xa:=x;
      for i:=0 to nk-1 do begin         // if y+1+i<17 then stringGrid1.Cells[y+1+i,x+1]:=buf[n+2*i]+buf[n+2*i+1] else stringGrid1.Cells[y+1+i-16,x+1+1]:=buf[n+2*i]+buf[n+2*i+1];  //取数据  如果列=17令其为1  并且行+1
       yi:=y+i; if yi+1>16 then begin yi:=yi-16; xa:=x+1; end; stringGrid1.Cells[yi+1,xa+1]:=buf[n+2*i]+buf[n+2*i+1];// else stringGrid1.Cells[y+1+i-16,x+1+1]:=buf[n+2*i]+buf[n+2*i+1];  //取数据  如果列=17令其为1  并且行+1
      end;
      n:=n+2*nk+4;   if buf[n+1]+buf[n+2]='00' then break;                               //+4:校验码+回车换行
     end;
     stringgrid1.RowCount :=xa+2;
    end ;
  0:begin x:=0; y:=0 ;  speedbutton3.Enabled :=false ;      //直接hex (文件照搬:一般不用)
     while n<file1.Size do begin
      if buf[n]=':'then if buf[n+1]='1' then nk:=16 else nk:=strtoint('$'+(buf[n+2]));   //取个数
      x:=x+1; stringgrid1.Cells[0,x]:=buf[n+3]+buf[n+4]+buf[n+5]+buf[n+6];   n:=n+9;
      for i:=0 to nk-1 do stringGrid1.Cells[y+1+i,x]:=buf[n+2*i]+buf[n+2*i+1] ;
      n:=n+2*nk+4;                                                                        //4=校验码+回车换行
     end;
     stringgrid1.RowCount :=x+2;
    end;                                                  //x 是行数
  2:begin  x:=0;                                          //读芯片映象文件二进制文件
     while n<file1.Size do begin                          //n 是文件指针 nk是每行的字节数
      x:=x+1; nk:=15; if file1.Size-n<15 then nk:=file1.Size-n ;      //最后一行就不是16个了
      for i:=0 to nk do stringGrid1.Cells[i+1,x]:=inttohex(word(buf[n+i]),2); //+buf[n+2*i+1] ;  //读
      n:=n+16;
     end;
     stringgrid1.RowCount :=x+1;
    end;
  3:begin  x:=0;                                         //读芯片映象文件  (保存的文本)
     while n<file1.Size do begin ;                       // if file1.Size-n<17 then nk:=file1.Size-n-2 else nk:=15  ;
      x:=x+1; nk:=15; if file1.Size-n<15 then nk:=file1.Size-n ;
      for i:=0 to nk do stringGrid1.Cells[i+1,x]:=buf[n+2*i]+buf[n+2*i+1] ; //读
      n:=n+32;
     end;
     stringgrid1.RowCount :=x+1;
    end;
  4:begin                                                              //MCS51生成的OBJ文件,前面4个字符的首地址+4个字符的代码字节数
     x:=strtoint('$'+buf[1]+buf[2]+buf[3]); y:=strtoint('$'+(buf[4])); //取地址:xy (行列)
     m:=strtoint('$'+buf[5]+buf[6]+buf[7]+buf[8]);                     //代码字节数
     for i:=1 to 2*m do buf[i]:=buf[i+8];     // x:=0; m:=file1.Size-8;  向前移动
     while n<m do begin ;
      x:=x+1; nk:=15; if m-n<15 then nk:=m-n  ;
      for i:=0 to nk do stringGrid1.Cells[i+1,x]:=buf[n+2*i]+buf[n+2*i+1] ;
      n:=n+32;

⌨️ 快捷键说明

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