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

📄 ppgnewdlg.cpp

📁 烧录器的上位机控制程序代码,和下位机程序代码,包括USB通讯固件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    //{{AFX_EVENTSINK_MAP(CPPGNEWDlg)

	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CPPGNEWDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	//选择是否写加密位
		if(!m_flag_opened)
	{
		AfxMessageBox("文件还没有打开");
			m_clvr.SetCurSel(-1);
		m_cclock.SetCurSel(-1);
		m_check_protect.SetCheck(0);
		return;
	}
	CString str_temp1;
	CONFIG=CONFIG&0XDFFF;
	if(!IsDlgButtonChecked(IDC_CHECK1))
		CONFIG=CONFIG+0X2000;
	str_temp1.Format("%.4X", CONFIG);
	m_cstatic_nconfig.SetWindowText("NEW CONFIG: 0X"+str_temp1);	
}	


int CPPGNEWDlg::String2Hex(CString str, CByteArray &senddata)
{


	int hexdata,lowhexdata;
	int hexdatalen=0;
	int len=str.GetLength();
		senddata.SetSize(len/2);
	for(int i=0;i<len;)
		{
		char lstr,hstr=str[i];
		if(hstr==' ')
			{
			i++;
			continue;
			}	
		i++;
		if(i>=len)
			break;
		lstr=str[i];
		hexdata=ConvertHexChar(hstr);
		lowhexdata=ConvertHexChar(lstr);

		if((hexdata==16)||(lowhexdata==16))
			break;
		else 
			hexdata=hexdata*16+lowhexdata;
		i++;
		senddata[hexdatalen]=(char)hexdata;
		hexdatalen++;
}
senddata.SetSize(hexdatalen);
return hexdatalen;

}

char CPPGNEWDlg::ConvertHexChar(char ch)
{

	if((ch>='0')&&(ch<='9'))
		return ch-0x30;
	else if((ch>='A')&&(ch<='F'))
		return ch-'A'+10;
	else if((ch>='a')&&(ch<='f'))
		return ch-'a'+10;
	else return (-1);
}

void CPPGNEWDlg::OnButtonReadOtp() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}

	m_flag_rtx=1;
	m_progress.ShowWindow(SW_SHOW);
	m_cedit_status.SetWindowText("开始读取OTP>>>>>>>>>>>>>>");
	m_cstatic_bufchksum.SetWindowText("缓存CHECKSUM:");
	m_cstatic_bufconfig.SetWindowText("缓存CONFIG:");
	m_cedit_buf.SetWindowText(_T(""));
	str_rxhex.Empty();
	m_breadotp = 1;
	
}

void CPPGNEWDlg::OnButtonBlank() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;

	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}

		if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}
	
	m_cedit_status.SetWindowText("开始OTP_BLANK>>>>>>>>>>>>");
	m_bblank = 1;m_flag_rtx=1;
//	Initial_subpro();
	m_progress.ShowWindow(SW_SHOW);

}

void CPPGNEWDlg::OnButtonConnect() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;
	m_flag_rtx=1;
	Initial_subpro();
	m_cedit_status.SetWindowText("正在联机");
	m_ucSend1[0]= 0x01;
	DWORD Result=WritePort1(m_ucSend1,1);
	UpdateWindow();
	m_progress.ShowWindow(SW_SHOW);
	for(int i=0; i<20; i++)
	{
	m_progress.SetPos(5*i);
	Sleep(100);
	}
	m_progress.ShowWindow(SW_HIDE);
	//========================================
   if (Result==0x0)
	{
	   m_cedit_status.SetWindowText("联机成功");
	   UpdateWindow();
	}
	else
	{
		m_cedit_status.SetWindowText("联机不成功");
		UpdateWindow();
	}	
	//============================版本为2.0, 检查版本是否匹配	
	m_ucSend1[0]= 0xc1;
	WritePort1(m_ucSend1,1);
	Sleep(10);
	ReadPort1(m_ucRec1,2);
	str_gtemp.Format("%.2X", m_ucRec1[1]);
	if(m_ucRec1[1]!=0x20)
	{
	MessageBox("请确认烧录器是否为最新版本?\r\n软件版本为3.0,烧录器版本为"+str_gtemp);
	m_flag_rtx=0;
	}
	
	Buzzer_N(1);
	m_flag_rtx=0;
	
}

void CPPGNEWDlg::OnButtonDownload() 
{
	// TODO: Add your control notification handler code here

	if(m_flag_rtx)
		return;

	if(!m_flag_opened)
	{
		AfxMessageBox("文件还没有打开");
		return;
	}
	
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	m_bnewflash = 1;
	m_flag_rtx=1;
	m_cedit_status.SetWindowText("开始下载FLASH>>>>>>>>>>>>>");
	m_progress.ShowWindow(SW_SHOW);
	
}

void CPPGNEWDlg::OnButtonReadFlash() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;
	m_flag_rtx=1;
	//------------------------------
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	m_progress.ShowWindow(SW_SHOW);
	m_cstatic_bufchksum.SetWindowText("缓存CHECKSUM:");
	m_cstatic_bufconfig.SetWindowText("缓存CONFIG:");
	m_cedit_buf.SetWindowText(_T(""));
	str_rxhex.Empty();
	m_breadflash =1;
	m_cedit_status.SetWindowText("开始读FLASH");
}

DWORD CPPGNEWDlg::Initial_subpro()  //???, 有待修改,
{
	m_nPos=0;
	m_progress.ShowWindow(SW_HIDE);
	m_progress.SetPos(0);

	m_ucSend1[0]= 0x00;
    DWORD result = WritePort1(m_ucSend1,1);
	Sleep(20);
	result = ReadPort1(m_ucSend1,1);
	return result;
}

void CPPGNEWDlg::OnButtonVerify_OTP_FLASH() 
{
	// TODO: Add your control notification handler code here

	if(m_flag_rtx)
		return;
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}
	m_flag_rtx=1;
	m_progress.ShowWindow(SW_SHOW);
	m_cedit_status.SetWindowText("开始校验OTP/FLASH>>>>>>>>>>>>>>");
	m_bverify_f=1;

	
}

void CPPGNEWDlg::OnButtonVerify_OTP_FILE() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;
	if(!m_flag_opened)
	{
		AfxMessageBox("文件还没有打开.");
		return;
	}
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}
	m_flag_rtx=1;
	m_progress.ShowWindow(SW_SHOW);
	m_cedit_status.SetWindowText("开始校验OTP/FILE>>>>>>>>>>>>>>>>>>");
	m_bverifyotp_file = 1;


}



void CPPGNEWDlg::OnButtonBPV() 
{
	// TODO: Add your control notification handler code here

	if(m_flag_rtx)
		return;
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}
	m_flag_rtx=1;
	m_progress.ShowWindow(SW_SHOW);

	m_bbpv = 1;



}

void CPPGNEWDlg::OnButtonWriteOtpFile() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;
	if(!m_flag_opened)
	{
		AfxMessageBox("文件还没有打开");
		return;
	}
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}

	if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}
	m_flag_rtx=1;
	m_cedit_status.SetWindowText("开始烧写(FILE)>>>>>>>>>>>>>>>>>>>>>");
	m_progress.ShowWindow(SW_SHOW);
	m_bwriteotp = 1;

	
}

void CPPGNEWDlg::OnButtonSave() 
{
	// TODO: Add your control notification handler code here
	if(str_rxhex.GetLength()<1024*RomSize*4 )
	{
	MessageBox("缓冲区还没有数据");
	return;
	}

	CFileDialog fileDlg(FALSE);
	fileDlg.m_ofn.lpstrTitle="保存缓冲区为HEX文件";
	fileDlg.m_ofn.lpstrFilter="Hex Files(*.hex)\0*.hex\0\0";
	fileDlg.m_ofn.lpstrDefExt="hex";   //默认的文件扩展名

	str_gtemp1.Empty();
	str_gtemp2.Empty();
	for(int i=0; i<RomSize*1024+1; i++)
	{
		str_gtemp.Empty();
		if(i==RomSize*1024)				//保存缓冲区的CONFIG
		{
			str_gtemp1.Format("%.4X", 0x2000);
			str_gtemp=":02"+str_gtemp1+"00"+str_rxhex.Mid(i*4+2, 2)+str_rxhex.Mid(i*4, 2);
			//----------------------------------------------------------------------------------------
			String2Hex(str_gtemp.Mid(1, 12), hexdata);
			BYTE chksum=(0xff ^ (hexdata[0]+hexdata[1]+hexdata[2]+hexdata[3]+hexdata[4]+hexdata[5]))+1;
			str_gtemp1.Format("%.2X", chksum);
			//-------------------------------
			str_gtemp=str_gtemp+str_gtemp1+"\r\n";
			str_gtemp2=str_gtemp2+str_gtemp;
			str_gtemp2=str_gtemp2+":00000001FF";
			break;
		}
		
		if("3FFF"!=str_rxhex.Mid(i*4, 4) )	//保存缓存的代码区,忽略"3FFF"
		{
			str_gtemp1.Format("%.4X", i);
			str_gtemp=":02"+str_gtemp1+"00"+str_rxhex.Mid(i*4+2, 2)+str_rxhex.Mid(i*4, 2);
			//----------------------------------------------------------------------------------------
			String2Hex(str_gtemp.Mid(1, 12), hexdata);
			BYTE chksum=(0xff ^ (hexdata[0]+hexdata[1]+hexdata[2]+hexdata[3]+hexdata[4]+hexdata[5]))+1;
			str_gtemp1.Format("%.2X", chksum);
			//-------------------------------
			str_gtemp=str_gtemp+str_gtemp1+"\r\n";
			str_gtemp2=str_gtemp2+str_gtemp;
		}
	}	


	if(IDOK==fileDlg.DoModal())
	{
		CFile file(fileDlg.GetFileName(),CFile::modeCreate | CFile::modeWrite);
		file.Write(str_gtemp2,strlen(str_gtemp2));
		file.Close();
		m_cedit_status.SetWindowText("存储文件到:"+fileDlg.GetPathName());
	}
	
		
}




void CPPGNEWDlg::OnButtonWrtConfig() //烧写和校验CONFIG
{
	// TODO: Add your control notification handler code here

	if(m_flag_rtx)
		return;

	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");
		return;
	}
	if( !MyPinTest() )
	{
		MessageBox("IC放置位置不对,或没有放IC");
		return;
	}
	m_flag_rtx=1;
	m_cedit_status.SetWindowText("开始CONFIG烧写和校验(FILE)>>>>>>>>>>>>>>>>>>>>>");
	
	BYTE config_h, config_l;
	config_h=CONFIG/0x100;
	config_l=CONFIG%0X100;

	m_cedit_status.SetWindowText("正在读写和校验CONFIG");
	m_ucSend1[0]= 0xA4;
	m_ucSend1[1]= config_h;
	m_ucSend1[2]= config_l;
	
	WritePort1(m_ucSend1,3);
    Sleep(50);
	ReadPort1(m_ucRec1,3);
	if (m_ucRec1[0]==0xA4 && m_ucRec1[1]==config_h && m_ucRec1[2]==config_l)
	{
		m_cedit_status.SetWindowText("CONFIG烧写和校验成功");
		Buzzer_N(1);
	}
	else
	{	
		str_gtemp.Format("%.2X%.2X", m_ucRec1[1], m_ucRec1[2]);
		m_cedit_status.SetWindowText("CONFIG烧写和校验不成功, CONFIG为:0X"+str_gtemp);
		Buzzer_N(3);
	}
	Initial_subpro();
    m_flag_rtx =0;	
}


void CPPGNEWDlg::OnBtnReadconfig() 
{
	// TODO: Add your control notification handler code here
	if(m_flag_rtx)
		return;
	if (Initial_subpro()!=0)
	{
		m_flag_rtx=0;
		m_cedit_status.SetWindowText("联机不成功!!!");
		AfxMessageBox("联机不成功!!!");

⌨️ 快捷键说明

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