您的位置:首页 > 编程语言 > C语言/C++

【原创】公司一款IC的HEX TO BIN (C++)-----2008.07

2013-08-23 09:52 435 查看
学了C++,一直没有用到,就想起了刚刚做的软件用c++语言再写一遍,效果是一样的,呵呵,思路都差不多,毕竟都是.NET的。

最近公司新用的一款RENESAS的IC,由于其编程器价格很高,市面上的SUPER 3000U也支持,正好我公司有好多台,但是发现一个问题,就是能烧写,但是IC没有功能,原因是M34283是一个9BIT x 0x7FF的一个

程序空间,而SUPER3000u不能调用其格式,RENESAS的编程软件特殊。



这是HEX文件的一部分,我们先分析一下。

:1000000000110FB05A5B588286BF8FB084B080B0A9

从左到右开始:10 表示有16个字节

0000 表示偏移地址为0000

00 表示数据

00----B0 为16个BYTE的数据

A9 为算术和

那么对于M34283的第9位在哪里呢?编程器分开了地方。从一个新的地方开始。



此图片从1000开始都是0101的数据,这里对应前面的高位。

即1000对应0000的高位。如此类推。为了实现不浪费的精神我打算编写一个软件来转换







把生成的BIN文件,到SUPER 3000U中烧写即可!!
源码如下:

#pragma once

namespace HEXTOBINC {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(59, 22);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(298, 21);
this->textBox1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(102, 64);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"浏览";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(238, 64);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 2;
this->button2->Text = L"转换";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(31, 158);
this->textBox2->Multiline = true;
this->textBox2->Name = L"textBox2";
this->textBox2->ReadOnly = true;
this->textBox2->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->textBox2->Size = System::Drawing::Size(349, 169);
this->textBox2->TabIndex = 3;
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
this->openFileDialog1->Filter = L"HEX File|*.hex";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 25);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(47, 12);
this->label1->TabIndex = 4;
this->label1->Text = L"源文件:";
//
// label2
//
this->label2->AutoSize = true;
this->label2->ForeColor = System::Drawing::Color::Red;
this->label2->Location = System::Drawing::Point(62, 90);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(287, 36);
this->label2->TabIndex = 5;
this->label2->Text = L" 针对SUPER 3000U不能对RENESAS的M3428X烧写\r\n特编写此款软件转换9BIT数据为BIN文件烧写。仅仅限\r\n于M3428X!---更改为C"
L"++语言。";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"宋体", 9, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)),
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(134)));
this->label3->ForeColor = System::Drawing::Color::Blue;
this->label3->Location = System::Drawing::Point(141, 126);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(208, 12);
this->label3->TabIndex = 6;
this->label3->Text = L"Made by lynnlase---2008.07.29";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(403, 339);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Name = L"Form1";
this->Text = L"KIE HEX TO BIN(RENESAS)--C++";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
System::Windows::Forms::DialogResult dr;
dr=openFileDialog1->ShowDialog();

if(dr==System::Windows::Forms::DialogResult::OK)
{
textBox1->Text=openFileDialog1->FileName;
textBox2->Text=System::IO::File::ReadAllText(openFileDialog1->FileName);
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox2->Text != "")
{
try
{
cli::array<System::String ^> ^text;
text = textBox2->Lines;

//cli::array<System::Byte ^> ^enddata;
System::Byte enddata[4096];
int count=0;
int j = (text->Length - 2) / 2;
for (int i = 0; i < j; i++)
{
System::Byte tempb[32] ;

for(int y=1,x=0;y<text[i]->Length;y=y+2,x++)
tempb[x]=System::Convert::ToByte(text[i]->Substring(y, 2), 16);
System::Byte tempd[32] ;
for(int y=1,x = 0;y<text[i+j]->Length;y=y+2,x++)
tempd[x]=System::Convert::ToByte(text[i+j]->Substring(y, 2), 16);
int offseth = System::Convert::ToInt16(tempb[1]);
int offsetl = System::Convert::ToInt16(tempb[2]);
int offset = (offseth << 8) + offsetl;

while (count < offset)
{

enddata[count*2]=0xff;
enddata[count*2+1]=0xff;
count++;
}

for (int y = 0; y < tempb[0]; y++)
{
enddata[count*2]=tempb[y + 4];
enddata[count*2+1]=tempd[y + 4];
count++;
}

}
while (count < 0x800)
{
enddata[count*2]=0xff;
enddata[count*2+1]=0xff;
count++;
}
System::String ^pathend = textBox1->Text;
pathend=pathend->Remove(pathend->Length - 3);
pathend = pathend + "bin";
System::IO::FileStream ^fs = gcnew System::IO::FileStream(pathend, System::IO::FileMode::Create, System::IO::FileAccess::Write);
int x=0;
while(x<4096)
{
fs->WriteByte(enddata[x]);
x++;
}
fs->Close();
// throw 1;
}
catch(int &)
{
System::Windows::Forms::MessageBox::Show("请检查源文件");
}

System::Windows::Forms::MessageBox::Show("转换成功!");
}else
{
System::Windows::Forms::MessageBox::Show("请选择一个HEX文件,仅限于M3428X");
}
}
};
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: