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

📄 programmer.cpp

📁 用于开发Atmel的AVR系列单片机的GCC集成开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  case 2: if (ProgrammerType == PGM_PAR) ParPgm->SetSCKLen (4);
          else STK500->SetSCKLen (8);
          break;
  case 3: if (ProgrammerType == PGM_PAR) ParPgm->SetSCKLen (8);
          else STK500->SetSCKLen (16);
          break;
  case 4: if (ProgrammerType == PGM_PAR) ParPgm->SetSCKLen (20);
          else STK500->SetSCKLen (78);
          break;
  case 5: if (ProgrammerType == PGM_PAR) ParPgm->SetSCKLen (62);
          else STK500->SetSCKLen (245);
          break;
 }
}
//---------------------------------------------------------------------------
int __fastcall TPgmDlg::BSizeToWSize (int size)
{
 if (size & 0x01) size++;
 return (size / 2);
}
//---------------------------------------------------------------------------
void __fastcall TPgmDlg::ReadEEButtonClick(TObject *Sender)
{
 int i, d;
 unsigned char ch, buf[32];
 AnsiString temp;

 if (ProgrammerType == PGM_PAR)
 {
  if (!StartPGM ())
  {
   ErrorMessage ("Can't start Communication");
   StopPGM ();
   return;
  }
 }
 else
 {
  if (!STK500->CheckPresence ())
  {
   ErrorMessage ("STK500 not available");
   return;
  }
  if (!STK500->EnablePGM (&chip))
  {
   ErrorMessage ("Can't start Communication");
   STK500->DisablePGM ();
   return;
  }
 }
 DisableUIF (true);
 StatusLabel->Caption = "Reading EEProm ...";
 memset (eeprombuffer, 0xff, MAX_EEPROMBUF * sizeof(unsigned char));
 Progress->Max = chip.eepromsize;
 if (ProgrammerType == PGM_STK500) STK500->LoadAddress (0);
 for (i = 0;i < chip.eepromsize;i++)
 {
  if (ProgrammerType == PGM_PAR) ParPgm->ReadEEPROM (i, &ch);
  else if (!STK500->ReadPage (buf, 32, 'E'))
  {
   ErrorMessage ("Error reading EEPROM");
   STK500->DisablePGM ();
   DisableUIF (false);
   StatusLabel->Caption = "Ready";
   Progress->Position = 0;
   return;
  }
  if (ProgrammerType == PGM_PAR) *(eeprombuffer + i) = ch;
  else
  {
   for (d = 0;d < 32;d++) *(eeprombuffer + i + d) = buf[d];
   i += 31;
  }
  Progress->Position = i;
  Application->ProcessMessages ();
 }
 for (i = chip.eepromsize - 1;i > 0;i--)
 {
  if (*(eeprombuffer + i) != 0xff) break;
 }
 if (PrgOpt->shortenhex)
 {
  if (i != 0) eeprombufsize = i + 1;
  else eeprombufsize = 0;
 }
 else eeprombufsize = chip.eepromsize;
 if (ProgrammerType == PGM_PAR) StopPGM ();
 else STK500->DisablePGM ();
 Progress->Position = 0;
 StatusLabel->Caption = "Ready";
 temp.printf ("%X", eeprombufsize);
 EEFileSize->Caption = temp;
 DisableUIF (false);
}
//---------------------------------------------------------------------------
void __fastcall TPgmDlg::ChangeDevice (void)
{
 AnsiString temp;

 BLB01Box->Enabled = false;
 BLB02Box->Enabled = false;
 BLB11Box->Enabled = false;
 BLB12Box->Enabled = false;
 FuseLBit0->Enabled = false;
 FuseLBit1->Enabled = false;
 FuseLBit2->Enabled = false;
 FuseLBit3->Enabled = false;
 FuseLBit4->Enabled = false;
 FuseLBit5->Enabled = false;
 FuseLBit6->Enabled = false;
 FuseLBit7->Enabled = false;
 FuseHBit0->Enabled = false;
 FuseHBit1->Enabled = false;
 FuseHBit2->Enabled = false;
 FuseHBit3->Enabled = false;
 FuseHBit4->Enabled = false;
 FuseHBit5->Enabled = false;
 FuseHBit6->Enabled = false;
 FuseHBit7->Enabled = false;
 FuseEBit0->Enabled = false;
 FuseEBit1->Enabled = false;
 FuseEBit2->Enabled = false;
 FuseEBit3->Enabled = false;
 FuseEBit4->Enabled = false;
 FuseLBit0->Caption = "NA";
 FuseLBit1->Caption = "NA";
 FuseLBit2->Caption = "NA";
 FuseLBit3->Caption = "NA";
 FuseLBit4->Caption = "NA";
 FuseLBit5->Caption = "NA";
 FuseLBit6->Caption = "NA";
 FuseLBit7->Caption = "NA";
 FuseHBit0->Caption = "NA";
 FuseHBit1->Caption = "NA";
 FuseHBit2->Caption = "NA";
 FuseHBit3->Caption = "NA";
 FuseHBit4->Caption = "NA";
 FuseHBit5->Caption = "NA";
 FuseHBit6->Caption = "NA";
 FuseHBit7->Caption = "NA";
 FuseEBit0->Caption = "NA";
 FuseEBit1->Caption = "NA";
 FuseEBit2->Caption = "NA";
 FuseEBit3->Caption = "NA";
 FuseEBit4->Caption = "NA";
 Calib1->Enabled = false;
 Calib2->Enabled = false;
 Calib3->Enabled = false;
 Calib4->Enabled = false;

 ZeroMemory (&chip, sizeof (chip));
 switch (ComboBox1->ItemIndex)
 {
  case 0: // attiny11
          chip.flashsize = 1024;
          chip.paged = false;
          chip.WD_Flash = 20;
          chip.eepromsize = 64;
          chip.WD_EEPROM = 20;
          chip.signature = 0x9004;
          chip.lockbittype = 0;
          chip.fusebittype = 14;
          chip.stk500_dev = 0x11;
          chip.fusebytes = 1;
          chip.lockbytes = 1;
          chip.selftimed = 0;
          chip.progtype = CHIP_PROGHV;
          chip.hvserial = true;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit2->Caption = "CKSEL2";
          FuseLBit2->Enabled = true;
          FuseLBit3->Caption = "RSTDISBL";
          FuseLBit3->Enabled = true;
          FuseLBit4->Caption = "FSTRT";
          FuseLBit4->Enabled = true;
          break;
  case 1: // attiny12
          chip.flashsize = 1024;
          chip.paged = false;
          chip.WD_Flash = 20;
          chip.eepromsize = 64;
          chip.WD_EEPROM = 20;
          chip.signature = 0x9005;
          chip.lockbittype = 0;
          chip.calibbytes = 1;
          chip.fusebittype = 11;
          chip.stk500_dev = 0x12;
          chip.fusebytes = 1;
          chip.lockbytes = 1;
          chip.selftimed = 1;
          chip.hvserial = true;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit2->Caption = "CKSEL2";
          FuseLBit2->Enabled = true;
          FuseLBit3->Caption = "CKSEL3";
          FuseLBit3->Enabled = true;
          FuseLBit4->Caption = "RSTDISBL";
          FuseLBit4->Enabled = true;
          FuseLBit6->Caption = "BODEN";
          FuseLBit6->Enabled = true;
          FuseLBit7->Caption = "BODLEVEL";
          FuseLBit7->Enabled = true;
          if (PrgOpt->parprog)
          {
           FuseLBit5->Caption = "SPIEN";
           FuseLBit5->Enabled = true;
          }
          break;
  case 2: // attiny13
          chip.flashsize = 1024;
          chip.paged = true;
          chip.pagesize = 64;
          chip.WD_Flash = 5;
          chip.eepromsize = 64;
          chip.WD_EEPROM = 4;
          chip.signature = 0x9007;
          chip.lockbittype = 3;
          chip.fusebittype = 12;
          chip.stk500_dev = 0x14;
          chip.fusebytes = 1;
          chip.lockbytes = 1;
          chip.selftimed = 1;
          chip.hvserial = true;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit2->Caption = "SUT0";
          FuseLBit2->Enabled = true;
          FuseLBit3->Caption = "SUT1";
          FuseLBit3->Enabled = true;
          FuseLBit4->Caption = "CKDIV8";
          FuseLBit4->Enabled = true;
          FuseLBit5->Caption = "WDTON";
          FuseLBit5->Enabled = true;
          FuseLBit6->Caption = "EESAVE";
          FuseLBit6->Enabled = true;
          if (PrgOpt->parprog)
          {
           FuseLBit7->Caption = "SPIEN";
           FuseLBit7->Enabled = true;
          }
          FuseHBit0->Caption = "RSTDISBL";
          FuseHBit0->Enabled = true;
          FuseHBit1->Caption = "BODLEVEL0";
          FuseHBit1->Enabled = true;
          FuseHBit2->Caption = "BODLEVEL1";
          FuseHBit2->Enabled = true;
          FuseHBit3->Caption = "DWEN";
          FuseHBit3->Enabled = true;
          FuseHBit4->Caption = "SPMEN";
          FuseHBit4->Enabled = true;
          break;
  case 3: // attiny15
          chip.flashsize = 1024;
          chip.paged = false;
          chip.WD_Flash = 20;
          chip.eepromsize = 64;
          chip.WD_EEPROM = 20;
          chip.fusebittype = 15;
          chip.lockbittype = 0;
          chip.stk500_dev = 0x13;
          chip.fusebytes = 1;
          chip.lockbytes = 1;
          chip.selftimed = 1;
          chip.hvserial = true;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit4->Caption = "RSTDISBL";
          FuseLBit4->Enabled = true;
          if (PrgOpt->parprog)
          {
           FuseLBit5->Caption = "SPIEN";
           FuseLBit5->Enabled = true;
          }
          FuseLBit6->Caption = "BODEN";
          FuseLBit6->Enabled = true;
          FuseLBit7->Caption = "BODLEVEL";
          FuseLBit7->Enabled = true;
          break;
  case 4: // attiny22
          chip.flashsize = 2048;
          chip.paged = false;
          chip.WD_Flash = 9;
          chip.eepromsize = 128;
          chip.WD_EEPROM = 9;
          chip.signature = 0x9106;
          chip.lockbittype = 1;
          chip.fusebittype = 2;
          chip.stk500_dev = 0x20;
          chip.fusebytes = 1;
          chip.lockbytes = 1;
          chip.selftimed = 0;
          chip.hvserial = true;
          FuseLBit0->Caption = "RCEN";
          FuseLBit0->Enabled = true;
          if (PrgOpt->parprog)
          {
           FuseLBit5->Caption = "SPIEN";
           FuseLBit5->Enabled = true;
          }
          break;
  case 5: // attiny26
          chip.flashsize = 2048;
          chip.paged = true;
          chip.pagesize = 32;
          chip.WD_Flash = 20;
          chip.eepromsize = 128;
          chip.WD_EEPROM = 20;
          chip.lockbittype = 4;
          chip.fusebittype = 12;
          chip.stk500_dev = 0x21;
          chip.fusebytes = 2;
          chip.lockbytes = 1;
          chip.selftimed = 1;
          chip.parmode = 1;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit2->Caption = "CKSEL2";
          FuseLBit2->Enabled = true;
          FuseLBit3->Caption = "CKSEL3";
          FuseLBit3->Enabled = true;
          FuseLBit4->Caption = "SUT0";
          FuseLBit4->Enabled = true;
          FuseLBit5->Caption = "SUT1";
          FuseLBit5->Enabled = true;
          FuseLBit6->Caption = "CKOPT";
          FuseLBit6->Enabled = true;
          FuseLBit7->Caption = "PLLCK";
          FuseLBit7->Enabled = true;
          FuseHBit0->Caption = "BODEN";
          FuseHBit0->Enabled = true;
          FuseHBit1->Caption = "BODLEVEL";
          FuseHBit1->Enabled = true;
          FuseHBit2->Caption = "EESAVE";
          FuseHBit2->Enabled = true;
          if (PrgOpt->parprog)
          {
           FuseHBit3->Caption = "SPIEN";
           FuseHBit3->Enabled = true;
          }
          FuseHBit4->Caption = "RSTDISBL";
          FuseHBit4->Enabled = true;
          break;
  case 6: // attiny28 (just parallel programming)
          chip.flashsize = 2048;
          chip.paged = false;
          chip.WD_Flash = 9;
          chip.eepromsize = 128;
          chip.WD_EEPROM = 9;
          chip.signature = 0x9107;
          chip.fusebittype = 14;
          chip.lockbittype = 4;
          chip.calibbytes = 1;
          chip.stk500_dev = 0x22;
          chip.fusebytes = 1;
          chip.lockbytes = 1;
          chip.selftimed = 1;
          chip.progtype = CHIP_PROGHV;
          chip.parmode = 1;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit2->Caption = "CKSEL2";
          FuseLBit2->Enabled = true;
          FuseLBit3->Caption = "CKSEL3";
          FuseLBit3->Enabled = true;
          FuseLBit4->Caption = "INTCAP";
          FuseLBit3->Enabled = true;
          break;
  case 7: // attiny2313
          chip.flashsize = 2048;
          chip.paged = true;
          chip.pagesize = 128;
          chip.WD_Flash = 5;
          chip.eepromsize = 128;
          chip.WD_EEPROM = 4;
          chip.signature = 0x910A;
          chip.lockbittype = 3;
          chip.calibbytes = 1;
          chip.fusebittype = 13;
          chip.stk500_dev = 0x23;
          FuseLBit0->Caption = "CKSEL0";
          FuseLBit0->Enabled = true;
          FuseLBit1->Caption = "CKSEL1";
          FuseLBit1->Enabled = true;
          FuseLBit2->Caption = "CKSEL2";
          FuseLBit2->Enabled = true;
          FuseLBit3->Caption = "CKSEL3";
          FuseLBit3->Enabled = true;
          FuseLBit4->Caption = "SUT0";
          FuseLBit4->Enabled = true;
          FuseLBit5->Caption = "SUT1";
          FuseLBit5->Enabled = true;
          FuseLBit6->Caption = "CKOUT";
          FuseLBit6->Enabled = true;
          FuseLBit7->Caption = "CKDIV8";
          FuseLBit7->Enabled = true;
          FuseHBit0->Caption = "RSTDISBL";
          FuseHBit0->Enabled = true;
          FuseHBit1->Caption = "BODLEVEL0";
          FuseHBit1->Enabled = true;
          FuseHBit2->Caption = "BODLEVEL1";
          FuseHBit2->Enabled = true;
          FuseHBit3->Caption = "BODLEVEL2";
          FuseHBit3->Enabled = true;
          FuseHBit4->Caption = "WDTON";
          FuseHBit4->Enabled = true;
          if (PrgOpt->parprog)

⌨️ 快捷键说明

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