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

📄 c8051jtagdlg.cpp

📁 C8051JTAG下载线制作原代码及线路图.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(false);
	
	TRACE("写入大小:%d",m_File.GetLength());

	strTemp.Format("写入大小:%d",m_File.GetLength());
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
	
	strTemp = time.Format( "%H:%M:%S->" )+strTemp;
	pList->AddString(strTemp);
	m_ctrlProcess.SetRange(0,1000);
	k = m_File.GetLength();
	uiStartAdd = c_hex2bin.atih(m_strSadd);
	m_strSadd.Format("%04X",uiStartAdd);

//	c_jtag.JTAG_Reset();
	//写入操作
	m_File.Seek(0,CFile::begin);
	for (i=0;i<m_File.GetLength();i++)
	{
		//擦除该页
		if (((i+uiStartAdd)%512)==0)
		{
			iRet = c_jtag.FLASH_PageErase (i+uiStartAdd);						// erase page prior to writing...
			if (!iRet)
			{
				strTemp.Format("擦除失败!!!");
				GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
				CTime time=CTime::GetCurrentTime();
				strTemp = time.Format( "%H:%M:%S->" )+strTemp;
				pList->AddString(strTemp);
				TRACE("擦除失败!!!");
				break;
			}												// handle Write Lock condition
			else
			{
				TRACE("擦除成功!!!");
			}
		}
		//写入
		m_File.Read(&ucWrite,1);
		iRet = c_jtag.FLASH_ByteWrite (i+uiStartAdd, ucWrite); 
		if (!iRet)
		{
			strTemp.Format("写入失败!!!地址:0x%04X",i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			TRACE(strTemp);
			break;
		}
		else
		{
			m_ctrlProcess.SetPos(i*1000/k);
			strTemp.Format("写入%0.2f%%,%04X",(float)i/k*100,i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			
			TRACE(strTemp);
		}
	}
	strTemp.Format("写入成功,开始校验...");
	time = CTime::GetCurrentTime();
	strTemp = time.Format( "%H:%M:%S->" )+strTemp;
	pList->AddString(strTemp);

	Beep(400,70);
	//读取校验操作
	m_File.Seek(0,CFile::begin);
	for (i=0;i<m_File.GetLength();i++)
	{
		iRet = c_jtag.FLASH_ByteRead(i+uiStartAdd, &ucTemp); 
		if (!iRet)
		{

			strTemp.Format("读取失败!!!地址:0x%04X",i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			TRACE(strTemp);
			break;
		};
		m_File.Read(&ucVery,1);
		if (ucTemp!=ucVery)
		{
			strTemp.Format("校验失败!!!地址:0x%04X",i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			TRACE(strTemp);
			break;
		}
		else
		{
			m_ctrlProcess.SetPos(i*1000/k);
			strTemp.Format("验证%0.2f%%,%04X",(float)i/k*100,i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			TRACE(strTemp);
		}
	}
	if (i==m_File.GetLength())
	{
		strTemp.Format("写入&&校验成功!!!写入字节=%d",i);
	}
	else
	{
		strTemp.Format("写入&&校验失败!!!错误字节=%d",i);
	}
	
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
	time = CTime::GetCurrentTime();
	strTemp = time.Format( "%H:%M:%S->" )+strTemp;
	pList->AddString(strTemp);
	TRACE(strTemp);
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(true);
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(true);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(true);
	Beep(400,80);
	return 0;
}

int CC8051JTAGDlg::fnRead()
{
	// TODO: Add your control notification handler code here
	CFileDialog filediag(TRUE,NULL,"Read.bin",OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT,"Bin file (*.bin)|*.bin|",NULL);
	if(filediag.DoModal()==IDOK)
	{
			m_strMsg.Format("文件保存于:%s!",filediag.GetPathName());
	}
	else
		return 2;



	unsigned char *pFwrite,*pFwHead;
	unsigned int pass;
	unsigned long i,ulSadd,ulEadd;
	CString strTemp;

	CListBox *pList;
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);

	GetDlgItem(IDC_EDIT_RSADD)->GetWindowText(strTemp);
	ulSadd = c_hex2bin.atih(strTemp);
	strTemp.Format("%04X",ulSadd);

	GetDlgItem(IDC_EDIT_READD)->GetWindowText(strTemp);
	ulEadd = c_hex2bin.atih(strTemp);
	strTemp.Format("%04X",ulEadd);

	if (ulEadd<ulSadd)
	{
		MessageBox("地址错误!!!重新输入!");
		return 1;
	}
	
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(false);

	pFwHead = (unsigned char *)malloc(ulEadd-ulSadd+1);
	pFwrite = pFwHead;
	m_ctrlProcess.SetRange(0,1000);
	for (i=0;i<ulEadd-ulSadd+1;i++)
	{
		pass = c_jtag.FLASH_ByteRead (i+ulSadd, pFwrite);
		pFwrite++;
		m_ctrlProcess.SetPos(i*1000/(ulEadd-ulSadd));
		strTemp.Format("%0.2f%%,%04X",(float)i/(ulEadd-ulSadd)*100,i);
		GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
		TRACE(strTemp);
		if(!pass)
		{
			strTemp.Format("读取出错!超出地址?当前地址:0x%04X",i);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			TRACE("读取出错!超出地址?当前地址:0x%04X",i);
			break;
		}
	}
	if(i ==(ulEadd-ulSadd+1) )
	{
		//保存文件
		CFile m_File2W;
		CFileException fileException;
		if ( !m_File2W.Open( filediag.GetPathName(), CFile::modeCreate|CFile::modeReadWrite, &fileException) )
		{
			TRACE( "Can't open file %s, error = %u\n",
			   filediag.GetPathName(), fileException.m_cause );
		}
		else
		{
			strTemp.Format("读取&&保存成功!文件路径:%s",filediag.GetPathName());
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			m_File2W.Write(pFwHead,i);
			m_File2W.Close();
		}
	}
	else
	{
			strTemp.Format("读取&&保存失败!文件路径:%s",filediag.GetPathName());
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);

	}
	free(pFwHead);

	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(true);
	Beep(400,100);
	return 0;
}

int CC8051JTAGDlg::fnVerify()
{
	unsigned long i,k;
	unsigned char ucTemp,ucVery;
	int iRet;
	CString strTemp;
	CFile m_File;
	CFileException fileException;

	CListBox *pList;
	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);

	if (strFileWPath == "")
	{
		MessageBox(_T("请先选择文件!!!"),NULL,MB_OK);
		return 1;
	}

	if (strFileWPath.Right(3) == "hex")
	{
		c_hex2bin.SetFile(&strFileWPath,TRUE);
	}


	if ( !m_File.Open( strFileWPath, CFile::modeRead, &fileException) )
	{
		TRACE( "Can't open file %s, error = %u\n",
		   strFileWPath, fileException.m_cause );
		return 2;
	}
	


	TRACE("验证的文件大小:%d",m_File.GetLength());
	m_ctrlProcess.SetRange(0,1000);
	k = m_File.GetLength();
	
	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(false);

	// TODO: Add your control notification handler code here
	//读取校验操作
	m_File.Seek(0,CFile::begin);
	for (i=0;i<m_File.GetLength();i++)
	{
		iRet = c_jtag.FLASH_ByteRead(i, &ucTemp); 
		if (!iRet)
		{
			strTemp.Format("读取失败!!!地址:0x%04X",i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			TRACE(strTemp);
			break;
		};
		m_File.Read(&ucVery,1);
		if (ucTemp!=ucVery)
		{
			strTemp.Format("校验失败!!!地址:0x%04X",i);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
			CTime time=CTime::GetCurrentTime();
			strTemp = time.Format( "%H:%M:%S->" )+strTemp;
			pList->AddString(strTemp);
			TRACE(strTemp);
			break;
		}
		m_ctrlProcess.SetPos(i*1000/k);
		strTemp.Format("验证%0.2f%%,%04X",(float)i/k*100,i);
		GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
	}
	if (i == m_File.GetLength())
	{
		strTemp.Format("校验成功!!!字节=%d",i);
	}
	else
	{
		strTemp.Format("校验失败!!!字节=%d",i);
	}

	
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
	CTime time=CTime::GetCurrentTime();
	strTemp = time.Format( "%H:%M:%S->" )+strTemp;
	pList->AddString(strTemp);
	TRACE(strTemp);


	GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_WV)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(TRUE);
	Beep(400,100);
	return 0;

}

void CC8051JTAGDlg::OnButtonAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlg;
//	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}
}

void CAboutDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void CAboutDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData(true);
	if (m_blValue)
	{
		CDialog::OnOK();
	}
	CDialog::OnTimer(nIDEvent);
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetTimer(1,2000,NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CC8051JTAGDlg::OnDblclkListMsg() 
{
	// TODO: Add your control notification handler code here
//	int index;
//	CListBox *pList;
//	CString strTemp;
//	pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);
//	index = pList->GetCurSel();
//	pList->GetText(index,strTemp);
//	::SetClipboardData(1,&strTemp);
}

void CC8051JTAGDlg::OnCheckHigh() 
{
	// TODO: Add your control notification handler code here
	int i=IsDlgButtonChecked(IDC_CHECK_HIGH);
	if (i)
	{
		c_jtag.ucFCONBIT7 = 0x80;
	}
	else
	{
		c_jtag.ucFCONBIT7 = 0x00;
	}
}

void CC8051JTAGDlg::OnSelchangeComboCputype() 
{
	// TODO: Add your control notification handler code here
	CComboBox *cbp;
	int i;
	cbp = (CComboBox *)GetDlgItem(IDC_COMBO_CPUTYPE);
	i = cbp->GetCurSel();
	switch(i)
	{
		case 0:
			{
				c_jtag.SelectCPU(C8051F020);
			}break;
		case 1:
			{
				c_jtag.SelectCPU(C8051F120);
			}break;

	}
}

⌨️ 快捷键说明

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