cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 2465|回复: 0

[转帖]ARM11 6410 初探:LED程序

[复制链接]
发表于 2010-4-20 11:05:13 | 显示全部楼层 |阅读模式
现在S3C6410的程序代码比较少,资料也不多。原本想整理一个完整的资料集再帖出来,发现比较困难,就把已经整理好的发一下吧。希望对大家有帮助!
PS:在此感谢一下飞凌的小菲,提供了一个LED的原理图,虽然不是太清楚,呵呵。

(原文件名ED.gif) 引用图片


(原文件名ED电路.jpg) 引用图片
先发一个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 CgpioDlgDataExchange(CDataExchange* pDX)
{
CDialogDataExchange(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() != DRArtrait ?  
   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);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-4-3 06:48 , Processed in 0.706192 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表