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

📄 uautocode.pas

📁 单片机
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      setcbbErr(cbbBootStart);
      Exit;
    end;

    //Cala baudrate error
    t := StrToInt(cbbFCPU.Text) / (StrToInt(cbbBaudRate.Text) * 16);
    i := Round(t);
    if (100 * abs(t - i) / t) > 2 then
    begin
      Application.MessageBox(PChar(lang.msgError + ': BaudRate error = [' + FloatToStrF(100 * abs(t - i) / t, ffFixed, 1, 1) + '%] > 2%   '), PChar(lang.msgError), MB_OK + MB_ICONSTOP);
      setcbbErr(cbbBaudRate);
      Exit;
    end;

    //Write to file
    dlgSave.Title := frmMain.mnSave.Caption + '         ';
    if dlgSave.Execute then
    begin
      try
        if CompareText(cfg.language, 'CHINESE') = 0 then
          b := True
        else
          b := False;
        AssignFile(f, dlgSave.FileName);
        Rewrite(f);
        Writeln(f, '/*');
        Writeln(f, '');
        Writeln(f, '                           e Y8b    Y8b YV3.58P888 88e');
        Writeln(f, '                          d8b Y8b    Y8b Y888P 888 888D');
        Writeln(f, '                         d888b Y8b    Y8b Y8P  888 88"');
        Writeln(f, '                        d8WuHan888b    Y8b Y   888 b,');
        Writeln(f, '                       d8888888b Y8b    Y8P    888 88b,');
        Writeln(f, '           8888 8888       ,e,                                  888');
        Writeln(f, '           8888 888820088e  " Y8b Y888P ,e e, 888,8, dP"Y ,"Y88b888');
        Writeln(f, '           8888 8888888 88b888 Y8b Y8P d88 88b888 " C88b "8" 888888');
        Writeln(f, '           8888 8888888 888888  Y8b "  888   ,888    Y88D,ee 888888');
        Writeln(f, '           ''Y88 88P''888 888888   Y8P    "YeeP"888   d,dP "88 888888');
        Writeln(f, '   888 88b,                    d8  888                     888');
        Writeln(f, '   888 88P'' e88 88e  e88 88e  d88  888 e88 88e  ,"Y88b e88 888 ,e e, 888,8,');
        Writeln(f, '   888 8K  d888 888bd888 8Shaoziyang88d888 888b"8" 888d888 888d88 88b888 "');
        Writeln(f, '   888 88b,Y888 888PY888 888P 888  888Y888 888P,ee 888Y888 888888   ,888');
        Writeln(f, '   888 88P'' "88 88"  "88 88"  888  888 "88 88" "88 888 "88 888 "YeeP"888');
        Writeln(f, '');
        Writeln(f, '');
        if b then
          Writeln(f, '  Project:       AVR 通用 BootLoader')
        else
          Writeln(f, '  Project:       AVR Universal BootLoader');
        Writeln(f, '  File:          bootcfg.h');
        if b then
          Writeln(f, '                 用户配置参数,请根据你系统的实际情况进行设置')
        else
          Writeln(f, '                 user''s configuration.');
        Writeln(f, '  Version:       3.5');
        Writeln(f, '');
        Writeln(f, '  Compiler:      GCC 4.2.2 + AVR Studio 4.13sp2 b571');
        Writeln(f, '');
        Writeln(f, '  Author:        Shaoziyang');
        Writeln(f, '                 Shaoziyang@gmail.com');
        Writeln(f, '                 http://avrubd.googlepages.com');
        Writeln(f, '                 ');
        Writeln(f, '  Date:          2008.3');
        Writeln(f, '  Made by:       AVRUBD autocode, ' + DateTimeToStr(now));
        Writeln(f, '');
        Writeln(f, '  See readme.htm to get more information.');
        Writeln(f, '');
        Writeln(f, '*/');
        Writeln(f, '');
        Writeln(f, '#ifndef _BOOTCFG_H_');
        Writeln(f, '#define _BOOTCFG_H_        1');
        Writeln(f, '');
        if b then
          Writeln(f, '//定义串口接收缓冲区长度')
        else
          Writeln(f, '//define uart buffer''s length');
        Writeln(f, '#define BUFFERSIZE         ', cbbBufferSize.Text);
        Writeln(f, '');
        if b then
          Writeln(f, '//系统时钟(Hz)')
        else
          Writeln(f, '//system clock(Hz)');
        Writeln(f, '#ifndef F_CPU');
        Writeln(f, '#define F_CPU              ', cbbFCPU.Text, 'UL');
        Writeln(f, '#endif');
        Writeln(f, '');
        if b then
          Writeln(f, '//波特率')
        else
          Writeln(f, '//baudrate');
        Writeln(f, '#define BAUDRATE           ', cbbBaudRate.Text);
        Writeln(f, '');
        if b then
        begin
          Writeln(f, '//Boot区起始地址: 按字节计算');
          Writeln(f, '//如果定义为0或不定义BootStart,可以节约空间');
        end
        else
        begin
          Writeln(f, '//Boot section start address(byte)');
          Writeln(f, '//define BootStart to 0 will disable this function');
        end;
        if cbbByteWord.ItemIndex = 0 then
          Writeln(f, '#define BootStart          ', cbbBootStart.Text)
        else
          Writeln(f, '#define BootStart          ', cbbBootStart.Text + ' * 2');
        Writeln(f, '');
        if b then
        begin
          Writeln(f, '//下载过程中进行数据校验');
          Writeln(f, '//ChipCheck和BootStart必须联合使用,校验才有效');
        end
        else
        begin
          Writeln(f, '//verify flash''s data while write');
          Writeln(f, '//ChipCheck will only take effect while BootStart enable also');
        end;
        if chkChipCheck.Checked then
          i := 1
        else
          i := 0;
        Writeln(f, '#define ChipCheck          ', i);
        Writeln(f, '');
        if b then
          Writeln(f, '//Bootloader触发模式  0:串口  1:电平')
        else
          Writeln(f, '//Bootloader launch  0:comport password  1:port level');
        Writeln(f, '#define LEVELMODE          ', cbbBootMode.ItemIndex);
        Writeln(f, '');
        Writeln(f, '#define LEVELPORT          ', cbbPortLevel.Text);
        Writeln(f, '#define LEVELPIN           P', cbbPortLevel.Text, cbbPINLevel.Text);
        if b then
          Writeln(f, '//触发电平 1:高  0:低')
        else
          Writeln(f, '//port level  1:High  0:Low');
        Writeln(f, '#define PINLEVEL           ', cbbBootLevel.ItemIndex);
        Writeln(f, '');
        if b then
        begin
          Writeln(f, '//等待密码的超时时间 = TimeOutCnt * timeclk');
          Writeln(f, '//超时次数');
        end
        else
        begin
          Writeln(f, '//max wait password time = TimeOutCnt * timeclk');
          Writeln(f, '//timeout count');
        end;
        Writeln(f, '#define TimeOutCnt         ', cbbBootCnt.Text);
        Writeln(f, '');
        if CompareText(cfg.language, 'CHINESE') = 0 then
          Writeln(f, '//同步时间间隔(ms)')
        else
          Writeln(f, '//basic timer interval(ms)');
        Writeln(f, '#define timeclk            ', cbbTimeClk.Text);
        Writeln(f, '');
        if b then
        begin
          Writeln(f, '//等待文件的超时时间 = TimeOutCntC * timeclk');
          Writeln(f, '//发送''C''的最大次数');
        end
        else
        begin
          Writeln(f, '//max wait data time = TimeOutCntC * timeclk');
          Writeln(f, '//send ''C'' command count');
        end;
        Writeln(f, '#define TimeOutCntC        ', cbbFileCnt.Text);
        Writeln(f, '');
        if b then
          Writeln(f, '//同步密码长度')
        else
          Writeln(f, '//password length');
        edtKeyHEX.Text := FormatHexStr(edtKeyHEX.Text, buf);
        Writeln(f, '#define CONNECTCNT         ', (Length(edtKeyHEX.Text) + 2) div 3);
        Writeln(f, '');
        if b then
          Writeln(f, '//同步密码')
        else
          Writeln(f, '//password');
        Writeln(f, '#if LEVELMODE == 0');
        Write(f, 'unsigned char KEY[] = {');
        for i := 1 to ((Length(edtKeyHEX.Text) + 2) div 3) - 1 do
          Write(f, '0x', edtKeyHEX.Text[i * 3 - 2], edtKeyHEX.Text[i * 3 - 1], ', ');
        i := (Length(edtKeyHEX.Text) + 2) div 3;
        Write(f, '0x', edtKeyHEX.Text[i * 3 - 2], edtKeyHEX.Text[i * 3 - 1], '};');
        Writeln(f, '');
        Writeln(f, '#endif');
        Writeln(f, '');
        if b then
          Writeln(f, '//串口号: 0/1/2..')
        else
          Writeln(f, '//comport number: 0/1/2..');
        Writeln(f, '#define COMPORTNo          ', cbbComPortNo.Text);
        Writeln(f, '');
        if b then
          Writeln(f, '//看门狗使能')
        else
          Writeln(f, '//enable watchdog');
        if chkWDG.Checked then
          i := 1
        else
          i := 0;
        Writeln(f, '#define WDGEn              ', i);
        Writeln(f, '');
        if b then
          Writeln(f, '//使用RS485模式')
        else
          Writeln(f, '//enable RS485/RS422 mode');
        if chkRS485En.Checked then
          i := 1
        else
          i := 0;
        Writeln(f, '#define RS485              ', i);
        if b then
          Writeln(f, '//RS485/RS422控制端口和引脚')
        else
          Writeln(f, '//RS485/RS422 send control port');
        Writeln(f, '#define RS485PORT          ', cbbPortRS485.Text);
        Writeln(f, '#define RS485TXEn          P', cbbPortRS485.Text, cbbPINRS485.Text);
        Writeln(f, '');
        if b then
          Writeln(f, '//使用LED指示状态')
        else
          Writeln(f, '//enable LED indication');
        if chkLED.Checked then
          i := 1
        else
          i := 0;
        Writeln(f, '#define LEDEn              ', i);
        if b then
          Writeln(f, '//LED控制端口和引脚')
        else
          Writeln(f, '//LED control port');
        Writeln(f, '#define LEDPORT            ', cbbPortLED.Text);
        Writeln(f, '#define LEDPORTNo          P', cbbPortLED.Text, cbbPINLED.Text);
        Writeln(f, '');
        if b then
          Writeln(f, '//某些型号的单片机在初始化后需要延时')
        else
          Writeln(f, '//some kind of AVR need special delay after comport initialization');
        Writeln(f, '#define InitDelay          ', cbbInitDelay.Text);
        Writeln(f, '');
        if b then
          Writeln(f, '//校验方法  0:CRC16  1:累加和')
        else
          Writeln(f, '//communication checksum method   0:CRC16  1:add up');
        Writeln(f, '#define CRCMODE            ', cbbCRC.ItemIndex);
        Writeln(f, '');
        if b then
          Writeln(f, '//提示模式: 显示更多交互提示信息,不用可以节省空间')
        else
          Writeln(f, '//Verbose mode: display more prompt message');
        if chkVerbose.Checked then
          i := 1
        else
          i := 0;
        Writeln(f, '#define VERBOSE            ', i);
        Writeln(f, '');
        Writeln(f, '#endif');
        Writeln(f, '');
        Writeln(f, '//End of file: bootcfg.h');
      finally
        CloseFile(f);
      end;

      try
        AssignFile(f, ExtractFilePath(dlgSave.FileName) + 'avrub.bat');
        Rewrite(f);
        Writeln(f, '@rem auto create by AVRUBD at ' + DateTimeToStr(now));
        Writeln(f, 'avr-gcc.exe  -mmcu=' + lowercase(cbbMCU.Text) + ' -Wall -gdwarf-2  -Os -fsigned-char -MD -MP  -c  bootldr.c');
        if cbbByteWord.ItemIndex = 0 then
          i := StrToInt(cbbBootStart.Text)
        else
          i := StrToInt(cbbBootStart.Text)*2;
        Writeln(f, 'avr-gcc.exe -mmcu=' + lowercase(cbbMCU.Text) + '  -Wl,-section-start=.text=0x' + IntToHex(i,4) + ' bootldr.o     -o Bootldr.elf');
        Writeln(f, 'avr-objcopy -O ihex -R .eeprom  Bootldr.elf Bootldr.hex');
        Writeln(f,'@pause');
      finally
        CloseFile(f);
      end;

      if b then
        msg := '成功创建参数配置文件. 立即编译 bootloader 吗?   ' + #13#10#13#10 + '你可以在任何时候运行 "avrub.bat" 进行编译.' + #13#10
      else
        msg := 'Create configuration file success. Compile bootloader right now?   ' + #13#10#13#10 + 'You may run "avrub.bat" to complie bootloader at any time.' + #13#10;
      if Application.MessageBox(PChar(msg), '?', MB_YESNO + MB_ICONQUESTION) = IDYES then
      begin
        ShellExecute(handle, nil, PChar('"'+ExtractFilePath(dlgSave.FileName) + 'avrub.bat"'), nil, nil, SW_SHOW);
      end;

    end;
    Close;
  finally
    Idle := True;
    HWD := handle;
  end;
end;

procedure TfrmAutoCode.tmrErrTimer(Sender: TObject);
begin
  if tmrErr.Tag > 0 then
  begin
    if (tmrErr.Tag mod 2) = 0 then
    begin
      if edtErr <> nil then
        edtErr.Color := clWindow;
      if cbbErr <> nil then
        cbbErr.Color := clWindow;
    end
    else
    begin
      if edtErr <> nil then
        edtErr.Color := clRed;
      if cbbErr <> nil then
        cbbErr.Color := clRed;
    end;
    tmrErr.Tag := tmrErr.Tag - 1;
  end
  else
  begin
    if edtErr <> nil then
    begin
      edtErr.Color := clWindow;
      edtErr := nil;
    end;
    if cbbErr <> nil then
    begin
      cbbErr.Color := clWindow;
      cbbErr := nil;
    end;
    tmrErr.Enabled := False;
  end;
end;

⌨️ 快捷键说明

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