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

📄 m16cflshdlg.cpp

📁 M16C Flash Starter Software Ver.2.0.0.46 Source Files.zip是瑞萨的M16C系列单片机的flash烧写程序。
💻 CPP
字号:
// M16CflshDlg.cpp: an implementation file   
//
// This software can be offered for free and used as necessary to aid 
// in your program developments.
//
// RENESAS TECHNOLOGY CORPORATION, RENESAS SOLUTIONS CORPORATION,
// and related original software developers assume no responsibility 
// for any damage or infringement of any third-party's rights, originating 
// in the use of the following software.
// Please use this software under the agreement and acceptance of these conditions. 
//
// Copyright(C)1998(2003) RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION
// ALL RIGHTS RESERVED
//

#include "stdafx.h"
#include "M16Cflsh.h"
#include "M16CflshDlg.h"
#include "IDCheckDlg.h"
#include "PreEraseDlg.h"
#include "SaveIni.h"
#include "PreVdcoffDlg.h"
#include "VdcoffCmd.h"
#include "PreCEPRDlg.h"

#include	"eraseCmd.h"
#include	"TypeCmd.h"
#include	"BlankCmd.h"
#include	"ReadCmd.h"
#include	"ProgramCmd.h"
#include	"SettingCmd.h"
#include	"BPRCmd.h"
#include	"EPRCmd.h"
#include	"StatesCmd.h"
#include	"VersionCmd.h"
#include	"DownloadCmd.h"
#include	"CEPRCmd.h"

#include	"SelectDlg.h"
#include	"S_PrgDlg.h"

#include	"defining.h"

extern int  id_send_flg;
extern bool VDC_ON_OFF_STATUS;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
//The CAboutDlg dialog that is used with the version information of the application. 

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// dialog data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard makes ooverride virtual function.
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // suport of DDX/DDV
	//}}AFX_VIRTUAL

//Implementation   
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// There is not message handle.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CM16CflshDlg dialog

CM16CflshDlg::CM16CflshDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CM16CflshDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CM16CflshDlg)
	m_str_VDC = _T("");
	//}}AFX_DATA_INIT
	//Memo : LoadIcon does not demand the sub sequence of DestroyIcon of Win32.  
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_str_VDC = (VDC_ON_OFF_STATUS) ? "OFF" : "ON";
    // m_str_VDC = _T("ON");
}

void CM16CflshDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CM16CflshDlg)
	DDX_Text(pDX, IDC_EDIT_VDC, m_str_VDC);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CM16CflshDlg, CDialog)
	//{{AFX_MSG_MAP(CM16CflshDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_ERASE, OnButtonErase)
	ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
	ON_BN_CLICKED(IDC_BUTTON_BLANK, OnButtonBlank)
	ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
	ON_BN_CLICKED(IDC_BUTTON_PROGRAM, OnButtonProgram)
	ON_BN_CLICKED(IDC_BUTTON_SETTING, OnButtonSetting)
	ON_BN_CLICKED(IDC_BUTTON_BPR, OnButtonBpr)
	ON_BN_CLICKED(IDC_BUTTON_STATES, OnButtonStates)
	ON_BN_CLICKED(IDC_BUTTON_EPR, OnButtonEpr)
	ON_BN_CLICKED(IDC_BUTTON_DOWNLOAD, OnButtonDownload)
	ON_BN_CLICKED(IDC_BUTTON_VERSION, OnButtonVersion)
	ON_BN_CLICKED(IDC_BUTTON_VDC_OFF, OnButtonVdcOff)
	ON_BN_CLICKED(IDC_BUTTON_C_EPR, OnButtonCEpr)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////
//I check whether the communication is passing.  
BOOL CM16CflshDlg::checkComm(void)
{

	//Transmission the lead status command.  
	BYTE newsend = 0x70;
	GetSerialComm().CleanUp(NULL);
	GetSerialComm().Write(&newsend, 1);

	BYTE receive[2];
	if(!GetSerialComm().Read(receive, 2))
	{
		CommError();
		return FALSE;
	}
	BOOL VDC_OFF_STATUS = 1 & (receive[1] >> 0);
	m_str_VDC = (VDC_OFF_STATUS) ? "OFF" : "ON";
    UpdateData(FALSE);
	return TRUE;
}

BOOL CM16CflshDlg::checkComm_out(void)
{
	//Transmission the lead status command. for boot loder  
	BYTE newsend;
	CSerialCommState	commState;
	GetSerialComm().GetState(&commState);
	newsend = baudrateToSendStyle(commState.m_dwBaudRate);
//	newsend = 0xb0;
	GetSerialComm().CleanUp(NULL);
	GetSerialComm().Write(&newsend, 1);


	BYTE receive[2];
	if(!GetSerialComm().Read(receive, 1))
	{
		CommError();
		return FALSE;
	}
	return TRUE;
}


	//Check whether you may push it a button.  
BOOL CM16CflshDlg::checkPush(void)
{
	//When the communication is not passing. 
	if(!GetAcceptedComm())
	{
		MessageBox(GetResString(IDS_NOTPASSCOMM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
		return FALSE;
	}
	// When the ID is not passing.
	if(!GetAcceptedID())
	{
		MessageBox(GetResString(IDS_NOTPASSID), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
		return FALSE;
	}
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CM16CflshDlg message handle

BOOL CM16CflshDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

//' Version information..     ' The menu item is added to the system menu.  

	// IDM_ABOUTBOX must be in the range of command menu.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	//Set up the icon for this dialog.  Frame work be the main of the application.
	//It does not set up it automatically when the window is not a dialog.  
	SetIcon(m_hIcon, TRUE);			// Set up a large icon.
	SetIcon(m_hIcon, FALSE);		// Set up a small icon.
	
	//TODO: Please add it to this place when to do a special initialization.  
	
	return TRUE;  //The focus that set up it to control when I return TRUE is not lost.  
}

void CM16CflshDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If a minimization button is added to the dialog box I draw the icon.   
//Cords needs to be described below. MFC application be document/view   
// This processing is processed automatically by frame work, because it is using the model.  

void CM16CflshDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // Device context for drawing

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// The center inside the rectangle range of the client   
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw icon.
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//The system calls here to display the cursor while the user is druging the minimization window.  
HCURSOR CM16CflshDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// When push Erase button.
void CM16CflshDlg::OnButtonErase() 
{
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	//It confirms whether I implement Erase.  
	CPreEraseDlg dlg;
	if(IDOK == dlg.DoModal())
	{
		CEraseCmd	cmd;

		//I implement Erase command.  
		if ( cmd.exec() )
		{
		}
		else
		{
			//Describes The processing in the time that an error broke out here.  
		}
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnCancel() 
{

	// TODO: Please add a special post-processing to this position.  

	// Retrun the baudrate to 9600bps.
	((CM16CflshApp*)AfxGetApp())->SetLastSerialState(GetSerialComm());
	 ::CloseHandle(GetMutex());
	CDialog::OnCancel();
}

void CM16CflshDlg::OnButtonLoad() 
{
	// TODO: Add the cord for control notice handle to this position.
	// When the communication is not passing.
	if(!GetAcceptedComm())
	{
		MessageBox(GetResString(IDS_NOTPASSCOMM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
		return;
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{
		if(!checkComm_out())
		{
			return;
		}
	}
	id_send_flg = FALSE;
	if (!GetFlashType())	// Flash Type = Internal Flash memory
	{
		CIDCheckDlg chkDlg;
		int nResponse = chkDlg.DoModal();
		if (nResponse == IDOK)
		{
			// TODO: Please describe the cord in the time that the dialog was put out with <OK>.  
		}

		else if (nResponse == IDCANCEL)
		{
			// TODO: Please describe the cord in the time that the dialog was put out with <Cancel>.
		}
	}
	else					// Flash Type = M16C/80 Boot loader
	{
		CSelectDlg selectDlg;
		int nResponse = selectDlg.DoModal();
		if (nResponse == IDOK)
		{
			// TODO: Please describe the cord in the time that the dialog was put out with <OK>.  
		}

		else if (nResponse == IDCANCEL)
		{
			// TODO: Please describe the cord in the time that the dialog was put out with <Cancel>.
		}
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{
		
	}
}

void CM16CflshDlg::OnButtonBlank() 
{
	// TODO: Add the code for control notice handle to this position.
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	CBlankCmd cmd;
	
	//I implement Blank command.  
	if(cmd.exec())
	{
	}
	else
	{
		// processing when error.
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonRead() 
{
	//Add the code for control notice handle to TODO: this position.
	//When ID is not passing.
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	CReadCmd cmd;
	
	//I implement Read command.  
	if(cmd.exec())
	{
	}
	else
	{
		//processing when error.  
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonProgram() 
{
	// TODO: Add the cord for control notice handle to this position.
	//When ID is not passing   
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	CProgramCmd cmd;
	
	//I implement Read command.  
	if(cmd.exec())
	{
	}
	else
	{
		// processig when error 
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonSetting() 
{
	// TODO: Add the cord for control notice handle to this position.
	//When the communication is not passing   
	if(!GetAcceptedComm())
	{
		MessageBox(GetResString(IDS_NOTPASSCOMM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
		return;
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{
		if(!checkComm_out())
		{
			return;
		}
	}

	CSettingCmd cmd;
	
	//Implement Setting command.  
	if(cmd.exec())
	{
	}
	else
	{
		// processing when erorr
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{

	}
}
	


void CM16CflshDlg::OnButtonBpr() 
{
	// TODO: Add the cord for control notice handle to this position.
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	CBPRCmd cmd;
	
	//Implement Setting command.  
	if(cmd.exec())
	{
	}
	else
	{
		// processing when erorr.
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonStates() 
{
	// TODO: Add the cord for control notice handle to this position.  
	//When the communication is not passing.
	if(!GetAcceptedComm())
	{
		MessageBox(GetResString(IDS_NOTPASSCOMM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
		return;
	}
	if(!checkComm())
	{
		return;
	}

	CStatesCmd cmd;
	//Implement Setting command.  
	if(cmd.exec())
	{
	}
	else
	{
		// processing when erorr.
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonEpr() 
{
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	//It confirms whether I implement Erase.  
	CPreEraseDlg dlg;
	if(IDOK == dlg.DoModal())
	{
		CEPRCmd	cmd;

		//I implement Erase command.  
		if ( cmd.exec() )
		{
		}
		else
		{
			//Describes The processing in the time that an error broke out here.
			return;
		}
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonDownload() 
{
	//When ID is not passing.
	if(!checkPush())
	{
		return;
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{
		if(!checkComm_out())
		{
			return;
		}
	}

	CDownloadCmd	cmd;
	if(cmd.exec())
	{
		//CDialog::OnCancel();
	}
	else
	{
		// processing when erorr
	}

	
}

void CM16CflshDlg::OnButtonVersion() 
{
	if(!GetAcceptedComm())
	{
		MessageBox(GetResString(IDS_NOTPASSCOMM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
		return;
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{
		if(!checkComm_out())
		{
			return;
		}
	}

	CVersionCmd	cmd;
	if(cmd.exec())
	{
	}
	else
	{
		// processing when erorr
	}
	if(!GetFlashType()){
		if(!checkComm())
		{
			return;
		}
	}else{
		if(!checkComm_out())
		{
			return;
		}
	}
	
}

void CM16CflshDlg::OnButtonVdcOff() 
{
	if(!checkPush())
	{
		return;
	}
	if(!checkComm())
	{
		return;
	}

	//It confirms whether I implement VDC_OFF.  
	CPreVdcoffDlg dlg;
	if(IDOK == dlg.DoModal())
	{

		CVdcoffCmd  cmd;
		//I implement VOFF command.  
		if ( cmd.exec() )
		{
		}
		else
		{
			//Describes The processing in the time that an error broke out here.  
		}
	}
	if(!checkComm())
	{
		return;
	}
}

void CM16CflshDlg::OnButtonCEpr() 
{
	if(!checkPush())
	{
		return;
	}
//	if(!checkComm())
//	{
//		return;
//	}

	//It confirms whether I implement C_EPR command .  
	CPreCEPRDlg dlg;
	if(IDOK == dlg.DoModal())
	{
		//It confirms whether I implement Erase.  
		CPreEraseDlg dlg;
		if(IDOK == dlg.DoModal())
		{

			CCEPRCmd cmd;

			//I implement C_EPR command.  
			if ( cmd.exec() )
			{
			}
			else
			{
				//Describes The processing in the time that an error broke out here.
				return;
			}
		}
	}
	if(!checkComm())
	{
		return;
	}
	
}

⌨️ 快捷键说明

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