?? c8051jtagdlg.cpp
字號:
// C8051JTAGDlg.cpp : implementation file
//
#include "stdafx.h"
#include "C8051JTAG.h"
#include "C8051JTAGDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
BOOL m_blValue;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual void OnOK();
afx_msg void OnTimer(UINT nIDEvent);
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
m_blValue = TRUE;
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Check(pDX, IDC_CHECK_AUTOCLS, m_blValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CC8051JTAGDlg dialog
CC8051JTAGDlg::CC8051JTAGDlg(CWnd* pParent /*=NULL*/)
: CDialog(CC8051JTAGDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CC8051JTAGDlg)
m_strMsg = _T("");
m_strSadd = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CC8051JTAGDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CC8051JTAGDlg)
DDX_Control(pDX, IDC_LIST_MSG, m_ctrlList);
DDX_Control(pDX, IDC_COMBO_CPUTYPE, m_ccCpuType);
DDX_Control(pDX, IDC_COMBO_CABTYPE, m_ccCabType);
DDX_Control(pDX, IDC_PROGRESS_PROC, m_ctrlProcess);
DDX_Text(pDX, IDC_STATIC_MSG, m_strMsg);
DDX_Text(pDX, IDC_EDIT_SADD, m_strSadd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CC8051JTAGDlg, CDialog)
//{{AFX_MSG_MAP(CC8051JTAGDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON_FILERD, OnButtonFilerd)
ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
ON_BN_CLICKED(IDC_BUTTON_WV, OnButtonWv)
ON_CBN_SELCHANGE(IDC_COMBO_CABTYPE, OnSelchangeComboCabtype)
ON_EN_UPDATE(IDC_EDIT_SADD, OnUpdateEditSadd)
ON_BN_CLICKED(IDC_BUTTON_VERY, OnButtonVery)
ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
ON_LBN_DBLCLK(IDC_LIST_MSG, OnDblclkListMsg)
ON_BN_CLICKED(IDC_CHECK_HIGH, OnCheckHigh)
ON_CBN_SELCHANGE(IDC_COMBO_CPUTYPE, OnSelchangeComboCputype)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CC8051JTAGDlg message handlers
BOOL CC8051JTAGDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
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 the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CListBox *pList;
pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);
CString strTemp;
// TODO: Add extra initialization here
m_strSadd = "0000";
m_ccCabType.SetCurSel(0);
// m_ccCpuType.SetCurSel(0);
iXXX = 99999;
if(!InitializeWinIo())
{
strTemp.Format("WinIO庫初始化失敗!請重新打開軟件.");
MessageBox("Winio Init fail!");
}
else
{
if(c_jtag.CableSetup(ALTERABLASTER))
{
strTemp.Format("BYTEBLASTER連接失敗!!系統(tǒng)檢測DB25-7---DB25-10腳是否連接.");
MessageBox("ByteBlaster連接檢測失敗!檢查并口連接,確認電源已經(jīng)打開!");
}
else
{
unsigned long ulTemp;
ulTemp = c_jtag.JtagGetIDCode();
strTemp.Format("連接成功,ID=0x%08X",ulTemp);
m_strMsg.Format("Get Chip ID = 0x%08X",ulTemp);
UpdateData(false);
TRACE(m_strMsg);
}
}
pList->SetSel(0);
CTime time=CTime::GetCurrentTime();
strTemp = time.Format( "%H:%M:%S->" )+strTemp;
pList->AddString(strTemp);
GetDlgItem(IDC_EDIT_RSADD)->SetWindowText("0000");
GetDlgItem(IDC_EDIT_READD)->SetWindowText("FE00");
//////////////////////////////////////////////////////////////////////////
//加入判斷系統(tǒng)參數(shù)
strTemp=GetCommandLine();
TRACE(strTemp);
// int j=strcspn(sMainPara," -");
CAboutDlg 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
}
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CC8051JTAGDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CC8051JTAGDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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 the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CC8051JTAGDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CC8051JTAGDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
ShutdownWinIo();
CDialog::OnClose();
}
void CC8051JTAGDlg::OnOK()
{
c_jtag.ResetCpu();
}
void CC8051JTAGDlg::OnButtonFilerd()
{
// TODO: Add your control notification handler code here
CString strTemp;
CListBox *pList;
pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);
CFileDialog filediag(TRUE,NULL,NULL,OFN_READONLY,"Hex Files (*.hex)|*.hex|Bin file (*.bin)|*.bin|All Files (*.*)|*.*|",NULL);
if(filediag.DoModal()==IDOK)
{
strFileWPath = filediag.GetPathName();
strTemp.Format("打開文件%s成功!",filediag.GetPathName());
CTime time=CTime::GetCurrentTime();
strTemp = time.Format( "%H:%M:%S->" )+strTemp;
pList->AddString(strTemp);
GetDlgItem(IDC_STATIC_MSG)->SetWindowText(strTemp);
strTemp.Format("文件路徑 %s",filediag.GetPathName());
GetDlgItem(IDC_STATIC_FILEPATH)->SetWindowText(strTemp);
GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_WV)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDC_BUTTON_VERY)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_WV)->EnableWindow(false);
}
}
void CC8051JTAGDlg::OnButtonRead()
{
pProgThread=(ProgThreah *)AfxBeginThread(RUNTIME_CLASS(ProgThreah));
pProgThread->PostThreadMessage(WM_BEGINREAD,(WPARAM)(this),0);
}
void CC8051JTAGDlg::OnButtonWv()
{
// TODO: Add your control notification handler code here
pProgThread=(ProgThreah *)AfxBeginThread(RUNTIME_CLASS(ProgThreah));
pProgThread->PostThreadMessage(WM_BEGINWRITE,(WPARAM)(this),0);
}
void CC8051JTAGDlg::OnSelchangeComboCabtype()
{
// TODO: Add your control notification handler code here
int i=c_jtag.CableSetup(m_ccCabType.GetCurSel());
CString strTemp;
CListBox *pList;
pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);
strTemp.Format("Get Chip ID = 0x%08X",c_jtag.JtagGetIDCode());
m_strMsg = strTemp;
UpdateData(false);
TRACE(m_strMsg);
CTime time=CTime::GetCurrentTime();
strTemp = time.Format( "%H:%M:%S->" )+strTemp;
pList->AddString(strTemp);
if (i)
{
CString strTemp;
strTemp.Format("連接失敗!");
CTime time=CTime::GetCurrentTime();
strTemp = time.Format( "%H:%M:%S->" )+strTemp;
pList->AddString(strTemp);
MessageBox("連接失敗!!!請檢查電纜!");
}
}
void CC8051JTAGDlg::OnUpdateEditSadd()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
unsigned long ulTemp;
CString strTemp;
UpdateData(TRUE);
ulTemp = c_hex2bin.atih(m_strSadd);
if (ulTemp>0xFFFF)
{
ulTemp = 0xFFFF;
strTemp.Format("%X",ulTemp);
GetDlgItem(IDC_EDIT_SADD)->SetWindowText(strTemp);
}
if (ulTemp==0)
{
m_strSadd = "0000";
}
else
{
}
// TODO: Add your control notification handler code here
UpdateData(false);
}
void CC8051JTAGDlg::OnButtonVery()
{
pProgThread=(ProgThreah *)AfxBeginThread(RUNTIME_CLASS(ProgThreah));
pProgThread->PostThreadMessage(WM_BEGINVERY,(WPARAM)(this),0);
}
int CC8051JTAGDlg::fnWriteVery()
{
unsigned long i,k;
unsigned char ucTemp,ucWrite,ucVery;
int iRet;
CString strTemp;
CFile m_File;
CFileException fileException;
unsigned int uiStartAdd;
CTime time=CTime::GetCurrentTime();
CListBox *pList;
pList = (CListBox *)GetDlgItem(IDC_LIST_MSG);
if (strFileWPath == "")
{
MessageBox(_T("請先選擇文件!!!"),NULL,MB_OK);
return 1;
}
strTemp=strFileWPath.Right(3);
strTemp.MakeLower();
if ( strTemp== "hex")
{
c_hex2bin.SetFile(&strFileWPath,TRUE);
strTemp.Format(".bin文件保存在:%s",strFileWPath);
strTemp = time.Format( "%H:%M:%S->" )+strTemp;
pList->AddString(strTemp);
}
if ( !m_File.Open( strFileWPath, CFile::modeRead, &fileException) )
{
TRACE( "Can't open file %s, error = %u\n",
strFileWPath, fileException.m_cause );
return 2;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -