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

📄 lcddlg.cpp

📁 该程序是单片机77E516的升级工具软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// LCDDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LCD.h"
#include "LCDDlg.h"

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

#define  KEY_ProgUpdata	   0x80+0x55
#define  KEY_Read64        0x00
#define  KEY_Read4         0x01
#define  KEY_Erase         0x02	
#define  KEY_Program       0x03	
#define  KEY_ExitISP       0x04

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}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)
	//}}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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLCDDlg dialog

CLCDDlg::CLCDDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLCDDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLCDDlg)
	m_port = _T("");
	m_comportsetting = _T("");
	m_RxData = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLCDDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLCDDlg)
	DDX_Control(pDX, IDC_COMBO2, m_ctrlcombo_comportsetting);
	DDX_Control(pDX, IDC_COMBO1, m_ctrlcombo_port);
	DDX_Control(pDX, IDC_BUTTON_Download, m_ctrlbtn_download);
	DDX_Control(pDX, IDC_BUTTON_openport, m_ctrlbtn_port);
	DDX_Control(pDX, IDC_PROGRESS1, m_progress1);
	DDX_Control(pDX, IDC_MSCOMM1, m_ctrlComm);
	DDX_CBString(pDX, IDC_COMBO1, m_port);
	DDX_CBString(pDX, IDC_COMBO2, m_comportsetting);
	DDX_Text(pDX, IDC_EDIT_RXDATA, m_RxData);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLCDDlg, CDialog)
//{{AFX_MSG_MAP(CLCDDlg)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_openport, OnBUTTONopenport)
ON_BN_CLICKED(IDC_BUTTON_clear, OnBUTTONclear)
ON_BN_CLICKED(IDC_BUTTON_openfile, OnBUTTONopenfile)
ON_BN_CLICKED(IDC_BUTTON_Download, OnBUTTONdownload)
ON_BN_CLICKED(IDC_BUTTON_ISP, OnBUTTONISP)
ON_BN_CLICKED(IDC_BUTTON_ExitISP, OnBUTTONExitISP)
ON_BN_CLICKED(IDC_BUTTON_Verify, OnBUTTONRead64)
ON_BN_CLICKED(IDC_BUTTON_Read4, OnBUTTONRead4)
ON_BN_CLICKED(IDC_BUTTON_Erase, OnBUTTONErase)
ON_BN_CLICKED(IDC_BUTTON_exit, OnBUTTONexit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLCDDlg message handlers

BOOL CLCDDlg::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
	
	// TODO: Add extra initialization here
    m_ctrlcombo_port.AddString("COM1");
    m_ctrlcombo_port.AddString("COM2");
    m_ctrlcombo_port.AddString("COM3");
	
	m_ctrlcombo_port.SetWindowText("COM1");
	
	m_ctrlcombo_comportsetting.AddString("1200,n,8,1");
	m_ctrlcombo_comportsetting.AddString("2400,n,8,1");
	m_ctrlcombo_comportsetting.AddString("4800,n,8,1");
	m_ctrlcombo_comportsetting.AddString("9600,n,8,1");
	m_ctrlcombo_comportsetting.AddString("19200,n,8,1");
	m_ctrlcombo_comportsetting.AddString("28800,n,8,1");
	m_ctrlcombo_comportsetting.AddString("38400,n,8,1");
	m_ctrlcombo_comportsetting.AddString("57600,n,8,1");
	m_ctrlcombo_comportsetting.AddString("115200,n,8,1");
	m_ctrlcombo_comportsetting.SetWindowText("9600,n,8,1");
    UpdateData(true); 
	
	m_strTXData="";
	UpdateData(false); 
	
	portopenflag=false;
	OpenFileName="";
    
	SetTimer(2,1000,NULL);//时间为1000毫秒	
	flag=false;
	
	GetDlgItem(IDC_BUTTON_ISP)->EnableWindow(false);	
	GetDlgItem(IDC_BUTTON_Erase)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_Download)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_Verify)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_Read4)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON_ExitISP)->EnableWindow(false);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLCDDlg::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 CLCDDlg::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 CLCDDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CLCDDlg::SendHex(unsigned char data)
{
	CByteArray hexdata;
	hexdata.SetSize(3);
	hexdata[0]='@';
	hexdata[1]='C';
	hexdata[2]=data;
	m_ctrlComm.SetOutput(COleVariant(hexdata)); 
}

BOOL CLCDDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	return CDialog::PreTranslateMessage(pMsg);
}

BEGIN_EVENTSINK_MAP(CLCDDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CLCDDlg)
ON_EVENT(CLCDDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CLCDDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
	VARIANT variant_inp;
	COleSafeArray safearray_inp;
    LONG len,k;
    CString strtemp;
    CString datumpkt;
	CHARFORMAT cf;
	CRichEditCtrl * pEditSend =(CRichEditCtrl *)GetDlgItem(IDC_EDIT_RXDATA);
	BYTE rxdata[2048]; //设置BYTE数组 An 8-bit integer that is not signed.
    cf.dwEffects=CFM_BOLD;
	
	if(m_ctrlComm.GetCommEvent()==2)        //事件值为2表示接收缓冲区内有字符
    {                                       ////////以下你可以根据自己的通信协议加入处理代码
        variant_inp=m_ctrlComm.GetInput();  //读缓冲区
		safearray_inp=variant_inp;          //VARIANT型变量转换为ColeSafeArray型变量
		//		CString str =(BSTR)variant_inp.pbstrVal;
		
        len=safearray_inp.GetOneDimSize();  //得到有效数据长度
       	for(k=0;k<len;k++)
        {
			safearray_inp.GetElement(&k,rxdata+k);//转换为BYTE型数组	
		}
		
        for(k=0;k<len;k++)                
        {
			//BYTE bt=str.GetAt(k); //字符型
			BYTE bt=*(char*)(rxdata+k); //字符型
			
			if 	(OperationType==KEY_Program)
            {
				if (bt==KEY_Program)
				{
					flag=true;
				}
			}
			
			else if 	(OperationType==KEY_Erase)
            {
				if (bt==KEY_Erase)
				{
					CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
					static1->SetWindowText("擦除完成!");
                    OperationType=0xff;	
				}
			}
			
			else if (OperationType==KEY_Read64)
			{
				if (Index%16==0)
				{
					if (Index>0)
					{
						datumpkt+="\r\n";	
					}
					strtemp.Format("%04X:",Index);
					datumpkt+=strtemp;
				}
				
				ReadBuffer[Index++]=bt;
				if (Index%1024==0)
				{
					m_progress1.SetPos(Index);
				}
				
				if (Index==65536)
				{
					CStatic *static1=(CStatic *)GetDlgItem(IDC_STATIC3);
                    OperationType=0xff;	
					m_progress1.SetPos(0);
					
					if (memcmp(LcdByte,ReadBuffer,FileLen)==0)
					{
						static1->SetWindowText("校验正确!");	
					}	
					else 
					{
						static1->SetWindowText("校验错误!");	
					}	
				}
				
			}
			
			else if (OperationType==KEY_Read4)
			{
				if (Index%16==0)
				{
					if (Index>0)
					{
						datumpkt+="\r\n";	

⌨️ 快捷键说明

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