打印

ARM11 6410 初探:LED程序

[复制链接]
1950|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
群龙舞十方|  楼主 | 2010-4-20 10:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
现在S3C6410的程序代码比较少,资料也不多。原本想整理一个完整的资料集再帖出来,发现比较困难,就把已经整理好的发一下吧。希望对大家有帮助!

先发一个GPIO的操作程序:
// gpioDlg.cpp : implementation file
//
#include "stdafx.h"
#include "gpio.h"
#include "gpioDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define IOCTL_LED_LED1_OPEN             0x04001060
#define IOCTL_LED_LED1_CLOSE           0x04001061
#define IOCTL_LED_LED2_OPEN             0x04001070
#define IOCTL_LED_LED2_CLOSE           0x04001071
#define IOCTL_LED_LED3_OPEN             0x04001080
#define IOCTL_LED_LED3_CLOSE           0x04001081
#define IOCTL_LED_LED4_OPEN             0x04001090
#define IOCTL_LED_LED4_CLOSE           0x04001091
// CgpioDlg dialog

HANDLE hLED = 0;
CgpioDlg::CgpioDlg(CWnd* pParent /*=NULL*/)
: CDialog(CgpioDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CgpioDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CgpioDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CgpioDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_RADIO1, &CgpioDlg::OnBnClickedRadio1)
ON_BN_CLICKED(IDC_RADIO2, &CgpioDlg::OnBnClickedRadio2)
ON_BN_CLICKED(IDC_RADIO3, &CgpioDlg::OnBnClickedRadio3)
ON_BN_CLICKED(IDC_RADIO4, &CgpioDlg::OnBnClickedRadio4)
END_MESSAGE_MAP()

// CgpioDlg message handlers
BOOL CgpioDlg::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
// TODO: Add extra initialization here
TCHAR szPortName[] = TEXT("LED1:");
szPortName[5] = 0;
// open general purpose stream driver
hLED = CreateFile(szPortName,
          GENERIC_READ|GENERIC_WRITE,
          0,   // devices must be opened w/exclusive-access
          NULL,  // no security attrs
          OPEN_EXISTING, // devices must use OPEN_EXISTING
          FILE_ATTRIBUTE_NORMAL,
          NULL); // hTemplate must be NULL for comm devices
         
if (hLED == INVALID_HANDLE_VALUE) {
  AfxMessageBox(TEXT("error"),0,0);
  }

return TRUE;  // return TRUE  unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CgpioDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
  DRA::RelayoutDialog(
   AfxGetResourceHandle(),
   this->m_hWnd,
   DRA::GetDisplayMode() != DRA::Portrait ?
   MAKEINTRESOURCE(IDD_GPIO_DIALOG_WIDE) :
   MAKEINTRESOURCE(IDD_GPIO_DIALOG));
}
}
#endif

void CgpioDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here

}
void CgpioDlg::OnBnClickedRadio1()
{
// TODO: Add your control notification handler code here
DWORD dwReturn = 0;
DWORD dwControlCode;
DWORD dwOutputValue;
static DWORD stt=0;
if (stt) {               // high
  dwControlCode = IOCTL_LED_LED1_OPEN;
  stt = 0;
} else {                // low
  dwControlCode = IOCTL_LED_LED1_CLOSE;
  stt = 1;
}
dwOutputValue = stt;
DeviceIoControl(hLED,
         dwControlCode,
         (LPVOID)&dwOutputValue,
         sizeof(DWORD),
         NULL,
         0,
         &dwReturn,
         NULL);
}
void CgpioDlg::OnBnClickedRadio2()
{
// TODO: Add your control notification handler code here
DWORD dwReturn = 0;
DWORD dwControlCode;
DWORD dwOutputValue;
static DWORD stt=0;
if (stt) {               // high
  dwControlCode = IOCTL_LED_LED2_OPEN;
  stt = 0;
} else {                // low
  dwControlCode = IOCTL_LED_LED2_CLOSE;
  stt = 1;
}
dwOutputValue = stt;
DeviceIoControl(hLED,
         dwControlCode,
         (LPVOID)&dwOutputValue,
         sizeof(DWORD),
         NULL,
         0,
         &dwReturn,
         NULL);
}
void CgpioDlg::OnBnClickedRadio3()
{
// TODO: Add your control notification handler code here
DWORD dwReturn = 0;
DWORD dwControlCode;
DWORD dwOutputValue;
static DWORD stt=0;
if (stt) {               // high
  dwControlCode = IOCTL_LED_LED3_OPEN;
  stt = 0;
} else {                // low
  dwControlCode = IOCTL_LED_LED3_CLOSE;
  stt = 1;
}
dwOutputValue = stt;
DeviceIoControl(hLED,
         dwControlCode,
         (LPVOID)&dwOutputValue,
         sizeof(DWORD),
         NULL,
         0,
         &dwReturn,
         NULL);
}
void CgpioDlg::OnBnClickedRadio4()
{
// TODO: Add your control notification handler code here
DWORD dwReturn = 0;
DWORD dwControlCode;
DWORD dwOutputValue;
static DWORD stt=0;
if (stt) {               // high
  dwControlCode = IOCTL_LED_LED4_OPEN;
  stt = 0;
} else {                // low
  dwControlCode = IOCTL_LED_LED4_CLOSE;
  stt = 1;
}
dwOutputValue = stt;
DeviceIoControl(hLED,
         dwControlCode,
         (LPVOID)&dwOutputValue,
         sizeof(DWORD),
         NULL,
         0,
         &dwReturn,
         NULL);
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

77

主题

460

帖子

2

粉丝