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

📄 gpiobeepdlg.cpp

📁 本例程介绍了S3C2410微控制器GPIO驱动的使用方法,通过实验已经实现了控制试验箱上蜂鸣器的蜂鸣
💻 CPP
字号:
// GPIOBeepDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPIOBeep.h"
#include "GPIOBeepDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGPIOBeepDlg dialog

CGPIOBeepDlg::CGPIOBeepDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGPIOBeepDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGPIOBeepDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGPIOBeepDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGPIOBeepDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGPIOBeepDlg, CDialog)
	//{{AFX_MSG_MAP(CGPIOBeepDlg)
	ON_WM_HELPINFO()
	ON_BN_CLICKED(IDC_OPEN_PIO1, OnOpenPio1)
	ON_BN_CLICKED(IDC_CLOSE_PIO1, OnClosePio1)
	ON_BN_CLICKED(IDC_BEEP_ON, OnBeepOn)
	ON_BN_CLICKED(IDC_BEEP_OFF, OnBeepOff)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPIOBeepDlg message handlers

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

	// 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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGPIOBeepDlg::OnHelpInfo()
{
	// TODO: implement help here
	MessageBox(_T("Help"));
}

#include "gpio.h"
HANDLE hFile=INVALID_HANDLE_VALUE;

void CGPIOBeepDlg::OnOpenPio1() 
{
	// TODO: Add your control notification handler code here
	BOOL ret;
	BYTE pinnum=10;

	hFile=CreateFile(TEXT("PIO1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
	if(hFile==INVALID_HANDLE_VALUE)
	{
		MessageBox(_T("打开GPIO驱动失败!"));
		return;
	}
	else
		MessageBox(_T("打开GPIO驱动成功!"));
	ret=::DeviceIoControl(hFile,IOCTL_GPH_SET_PIN_OUT,&pinnum,1,NULL,0,NULL,NULL);
	if(ret!=TRUE)
	{
		OnClosePio1();
		MessageBox(_T("设置GPH10引脚输出失败!"));
		return;
	}
	CButton*pOpenButton=(CButton*)GetDlgItem(IDC_OPEN_PIO1);
	CButton*pCloseButton=(CButton*)GetDlgItem(IDC_CLOSE_PIO1);
    pOpenButton->EnableWindow(FALSE);
	pCloseButton->EnableWindow(TRUE);
	
}

void CGPIOBeepDlg::OnClosePio1() 
{
	// TODO: Add your control notification handler code here
	if(hFile!=INVALID_HANDLE_VALUE)
	{
		CloseHandle(hFile);
		hFile=INVALID_HANDLE_VALUE;
	}

	CButton*pOpenButton=(CButton*)GetDlgItem(IDC_OPEN_PIO1);
	CButton*pCloseButton=(CButton*)GetDlgItem(IDC_CLOSE_PIO1);
    pOpenButton->EnableWindow(FALSE);
	pCloseButton->EnableWindow(TRUE);
	
}

void CGPIOBeepDlg::OnBeepOn() 
{
	// TODO: Add your control notification handler code here
	BOOL ret;
	BYTE pinnum=10;
	ret=::DeviceIoControl(hFile,IOCTL_GPH_CLR_PIN,&pinnum,1,NULL,0,NULL,NULL);
	if(ret!=TRUE)
		MessageBox(_T("设置GPH10低电平失败!"));
	
}

void CGPIOBeepDlg::OnBeepOff() 
{
	// TODO: Add your control notification handler code here
	BOOL ret;
	BYTE pinnum=10;
	ret=::DeviceIoControl(hFile,IOCTL_GPH_SET_PIN,&pinnum,1,NULL,0,NULL,NULL);
	if(ret!=TRUE)
    MessageBox(_T("设置GPH10高电平失败!"));
	
}

⌨️ 快捷键说明

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