📄 parellelporttestdlg.cpp
字号:
// ParellelPortTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ParellelPortTest.h"
#include "ParellelPortTestDlg.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 };
CButton m_AboutBtn;
//}}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)
DDX_Control(pDX, IDOK, m_AboutBtn);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParellelPortTestDlg dialog
CParellelPortTestDlg::CParellelPortTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CParellelPortTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CParellelPortTestDlg)
m_LcdString = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CParellelPortTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CParellelPortTestDlg)
DDX_Control(pDX, IDC_LCD_EDIT, m_LcdEdit);
DDX_Control(pDX, IDC_INF_EDIT, m_ceInfWindow);
DDX_Control(pDX, IDC_OPEN_BUTTON, m_ctOpenBtn);
DDX_Text(pDX, IDC_LCD_EDIT, m_LcdString);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CParellelPortTestDlg, CDialog)
//{{AFX_MSG_MAP(CParellelPortTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN_BUTTON, OnOpenButton)
ON_BN_CLICKED(IDC_WRITE_BUTTON, OnWriteButton)
ON_BN_CLICKED(IDC_READ_BUTTON, OnReadButton)
ON_BN_CLICKED(IDC_LCD_BUTTON, OnLcdButton)
ON_BN_CLICKED(IDC_PIN_BUTTON, OnPinButton)
ON_EN_CHANGE(IDC_LCD_EDIT, OnChangeLcdEdit)
ON_BN_CLICKED(IDC_ABOUT_BUTTON, OnAboutButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParellelPortTestDlg message handlers
BOOL CParellelPortTestDlg::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
bParalleStat=0;
m_hParallelPort=INVALID_HANDLE_VALUE;
g_bFlush=1;//刷新显示标志位
m_csInfWindow=_T("");
Beep(1000,100);
Sleep(50);
Beep(1000,100);
m_csInfWindow+="0x378并口初始化完成!\r\n";
g_bFlush=1;
/*
//初始化并口
if(!EppPort.InitPort(0x378))
{
//AfxMessageBox("Invalid LPT or LPT1 is not open");
bParalleStat=FALSE;
m_csInfWindow+=_T("Invalid LPT or LPT1 is not open\r\n");
g_bFlush=1;
}
else
{
bParalleStat=TRUE;
m_csInfWindow+=_T("Init ParellelPort successfully,Addr=0x378!\r\n");
g_bFlush=1;
Beep(1000,100);
Sleep(50);
Beep(1000,100);
}
*/
CreateThread(NULL,0,RcvWindowThread,this,0,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CParellelPortTestDlg::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 CParellelPortTestDlg::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 CParellelPortTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CParellelPortTestDlg::OnOpenButton()
{
// TODO: Add your control notification handler code here
/*
BYTE IoReg=0x00;
CString csInf;
EppPort.SetPinH(PIN_BUSY);//发送状态
EppPort.WriteData(0xff);
EppPort.SetPinL(PIN_BUSY);//接收状态
IoReg=EppPort.ReadData();
EppPort.SetPinH(PIN_BUSY);//发送状态
csInf.Format("IoReg=%d\r\n",IoReg);
m_csInfWindow+=csInf;
g_bFlush=1;
*/
}
DWORD WINAPI CParellelPortTestDlg::RcvWindowThread(LPVOID lpParameter)
{
CParellelPortTestDlg* pDlg;
pDlg=(CParellelPortTestDlg*)lpParameter;
CString m_Display;
while(1)
{
//if(!g_bOpened) break;
Sleep(100);
//AfxMessageBox("here");
if(g_bFlush)
{
pDlg->m_ceInfWindow.SetWindowText(pDlg->m_csInfWindow);
pDlg->m_ceInfWindow.LineScroll(pDlg->m_ceInfWindow.GetLineCount());//随时跟踪滚动条的位置
g_bFlush=0;
}
}
return FALSE;
}
void CParellelPortTestDlg::OnWriteButton()
{
// TODO: Add your control notification handler code here
/*
EppPort.SetPinL(PIN_BUSY);//发送状态
char i;
for(i=0;i<5;i++)
{
EppPort.SetPinH(PIN_SELIN);
Sleep(30);
EppPort.SetPinL(PIN_SELIN);
Sleep(30);
}
m_csInfWindow+="Flash over!\r\n";
g_bFlush=1;
*/
}
void CParellelPortTestDlg::OnReadButton()
{
// TODO: Add your control notification handler code here
/*
CString csReadState;
BYTE ReadState=0;
BOOL PinLogic;
EppPort.SetPinL(PIN_BUSY);//接收状态
PinLogic=EppPort.GetPinLogic(PIN_D0);
ReadState=EppPort.ReadState();
csReadState.Format(_T("ReadState=%d\r\nPin2 Logic is %d\r\n"),ReadState,PinLogic);
m_csInfWindow+=csReadState;
g_bFlush=1;
*/
}
void CParellelPortTestDlg::OnLcdButton()
{
// TODO: Add your control notification handler code here
unsigned char dis1[]="HELLO WORLD! ";
unsigned char dis2[]="HELLO MY GIRL ";
unsigned char dis3[]=" ";
unsigned char dis4[]=" H";
unsigned char dis5[]=" HE";
unsigned char dis6[]=" HEL";
unsigned char dis7[]=" HELL";
unsigned char dis8[]=" HELLO";
unsigned char dis9[]=" HELLO ";
unsigned char dis10[]=" HELLO W";
unsigned char dis11[]=" HELLO WO";
unsigned char dis12[]=" HELLO WOR";
unsigned char dis13[]=" HELLO WORL";
unsigned char dis14[]=" HELLO WORLD";
unsigned char dis15[]=" HELLO WORLD!";
unsigned char dis16[]=" HELLO WORLD! ";
unsigned char dis17[]=" HELLO WORLD! ";
unsigned char dis23[]=" ";
unsigned char dis24[]="! ";
unsigned char dis25[]="D! ";
unsigned char dis26[]="LD! ";
unsigned char dis27[]="RLD! ";
unsigned char dis28[]="ORLD! ";
unsigned char dis29[]="WORLD! ";
unsigned char dis30[]=" WORLD! ";
unsigned char dis31[]="O WORLD! ";
unsigned char dis32[]="LO WORLD! ";
unsigned char dis33[]="LLO WORLD! ";
unsigned char dis34[]="ELLO WORLD! ";
unsigned char dis35[]="HELLO WORLD! ";
unsigned char dis36[]=" HELLO WORLD! ";
unsigned char dis37[]=" HELLO WORLD! ";
g_Lcd1602.lcd_init();
m_csInfWindow+="LCD1602初始化完成!\r\n";
g_bFlush=1;
g_Lcd1602.display(0x00,dis3);g_Lcd1602.display(0x40,dis23);Sleep(40);
g_Lcd1602.display(0x00,dis4);g_Lcd1602.display(0x40,dis24);Sleep(40);
g_Lcd1602.display(0x00,dis5);g_Lcd1602.display(0x40,dis25);Sleep(40);
g_Lcd1602.display(0x00,dis6);g_Lcd1602.display(0x40,dis26);Sleep(40);
g_Lcd1602.display(0x00,dis7);g_Lcd1602.display(0x40,dis27);Sleep(40);
g_Lcd1602.display(0x00,dis8);g_Lcd1602.display(0x40,dis28);Sleep(40);
g_Lcd1602.display(0x00,dis9);g_Lcd1602.display(0x40,dis29);Sleep(40);
g_Lcd1602.display(0x00,dis10);g_Lcd1602.display(0x40,dis30);Sleep(40);
g_Lcd1602.display(0x00,dis11);g_Lcd1602.display(0x40,dis31);Sleep(40);
g_Lcd1602.display(0x00,dis12);g_Lcd1602.display(0x40,dis32);Sleep(40);
g_Lcd1602.display(0x00,dis13);g_Lcd1602.display(0x40,dis33);Sleep(40);
g_Lcd1602.display(0x00,dis14);g_Lcd1602.display(0x40,dis34);Sleep(40);
g_Lcd1602.display(0x00,dis15);g_Lcd1602.display(0x40,dis35);Sleep(40);
g_Lcd1602.display(0x00,dis16);g_Lcd1602.display(0x40,dis36);Sleep(40);
g_Lcd1602.display(0x00,dis17);g_Lcd1602.display(0x40,dis37);Sleep(40);
}
void CParellelPortTestDlg::OnPinButton()
{
// TODO: Add your control notification handler code here
BOOL Logic;
Logic=g_Lcd1602.GetPinState(9);
if(Logic)
{
m_csInfWindow+="PIN_D7=1\r\n";
}
else
{
m_csInfWindow+="PIN_D7=0\r\n";
}
g_bFlush=1;
}
void CParellelPortTestDlg::OnChangeLcdEdit()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
UpdateData();
char *pLcd;
unsigned char dis1[17]=" ";
unsigned char dis2[17]=" ";
pLcd=new char[m_LcdString.GetLength()+1];
memset(pLcd,0,m_LcdString.GetLength()+1);
strcpy(pLcd,m_LcdString);
if(m_LcdString.GetLength()<17)
{
char i=0;
for(i=0;*pLcd!=0;i++)
{
dis1[i]=*pLcd;
if(i<15) dis1[i+1]='_';
pLcd++;
}
for(i=0;i<16;i++)
{
dis2[i]=' ';
}
g_Lcd1602.display(0x00,dis1);
g_Lcd1602.display(0x40,dis2);
}
else
{
if(m_LcdString.GetLength()<33)
{
char i=0;
pLcd+=16;
for(i=0;*pLcd!=0;i++)
{
dis2[i]=*pLcd;
if(i<15) dis2[i+1]='_';
pLcd++;
}
g_Lcd1602.display(0x40,dis2);
}
else
{
char ch[2]=" ";
ch[0]=*(pLcd+32);
m_LcdString=_T("");
m_LcdString+=ch[0];
m_LcdEdit.SetWindowText(m_LcdString);
m_LcdEdit.SetSel(1,1);
unsigned char distemp[17]=" ";
g_Lcd1602.display(0x40,distemp);
distemp[0]=ch[0];
distemp[1]='_';
g_Lcd1602.display(0x00,distemp);
}
}
// TODO: Add your control notification handler code here
}
void CParellelPortTestDlg::OnAboutButton()
{
// TODO: Add your control notification handler code here
// m_AboutBtn;
MessageBox("LCD1602并口驱动\r\n\r\n作者:刘伟 :)\r\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -