版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、GPIO驅(qū)動(dòng)程序,主要是GIO_Control:BOOL GIO_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)switch(dwCode)case IO_CTL_GPIO_A_CON:
2、v_pIOPregs->GPACON= *(DWORD*)pBufIn;/GPACON SETbreak; case IO_CTL_GPIO_A_DAT_OUTPUT:v_pIOPregs->GPADAT= *(DWORD*)pBufIn; /GPADAT SET (OUTPUT) also for Functional Pinbreak; case IO_CTL_GPIO_B_CON: v_pIOPregs->GPBCON= *(DWORD*)p
3、BufIn;/GPBCON SETbreak;case IO_CTL_GPIO_B_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPBDAT; /GPBDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_B_DAT_OUTPUT:v_pIOPregs->GPBDAT= *(DWORD*)pBufIn; /GPBDAT SET (OUTPUT) also for Funct
4、ional Pinbreak;case IO_CTL_GPIO_B_UP: v_pIOPregs->GPBUP= *(DWORD*)pBufIn;/GPBUP SETbreak; case IO_CTL_GPIO_C_CON: v_pIOPregs->GPCCON= *(DWORD*)pBufIn;/GPCCON SETbreak;case IO_CTL_GPIO_C_DAT_INPUT: *(DWORD
5、*)pBufOut=v_pIOPregs->GPCDAT; /GPCDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_C_DAT_OUTPUT:v_pIOPregs->GPCDAT= *(DWORD*)pBufIn; /GPCDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_C_UP: v_pIOPregs->GPCUP= *(DWORD*)pBufIn;/GPCUP SETbr
6、eak; case IO_CTL_GPIO_D_CON: v_pIOPregs->GPDCON= *(DWORD*)pBufIn;/GPDCON SETbreak;case IO_CTL_GPIO_D_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPDDAT; /GPDDAT SET (INPUT) also for Functional Pinbreak; cas
7、e IO_CTL_GPIO_D_DAT_OUTPUT:v_pIOPregs->GPDDAT= *(DWORD*)pBufIn; /GPDDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_D_UP: v_pIOPregs->GPDUP= *(DWORD*)pBufIn;/GPDUP SETbreak; case IO_CTL_GPIO_E_CON: v_pIOPregs->GPECON= *
8、(DWORD*)pBufIn;/GPECON SETbreak;case IO_CTL_GPIO_E_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPEDAT; /GPEDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_E_DAT_OUTPUT:v_pIOPregs->GPEDAT= *(DWORD*)pBufIn; /GPEDAT SET (OUTPUT) also
9、for Functional Pinbreak;case IO_CTL_GPIO_E_UP: v_pIOPregs->GPEUP= *(DWORD*)pBufIn;/GPEUP SETbreak;case IO_CTL_GPIO_F_CON: v_pIOPregs->GPFCON= *(DWORD*)pBufIn;/GPFCON SETbreak;case IO_CTL_GPIO_F_DAT_INPUT: *(DWORD*)pBufOut=v
10、_pIOPregs->GPFDAT; /GPFDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_F_DAT_OUTPUT:v_pIOPregs->GPFDAT= *(DWORD*)pBufIn; /GPFDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_F_UP: v_pIOPregs->GPFUP= *(DWORD*)pBufIn;/GPFUP SETbreak;
11、 case IO_CTL_GPIO_G_CON: v_pIOPregs->GPGCON= *(DWORD*)pBufIn;/GPGCON SETbreak;case IO_CTL_GPIO_G_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPGDAT; /GPGDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_G
12、PIO_G_DAT_OUTPUT:v_pIOPregs->GPGDAT= *(DWORD*)pBufIn; /GPGDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_G_UP: v_pIOPregs->GPGUP= *(DWORD*)pBufIn;/GPGUP SETbreak; case IO_CTL_GPIO_H_CON: v_pIOPregs->
13、;GPHCON= *(DWORD*)pBufIn;/GPHCON SETbreak;case IO_CTL_GPIO_H_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPHDAT; /GPHDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_H_DAT_OUTPUT:v_pIOPregs->GPHDAT= *(DWORD*)pBufIn; /GPHDAT SET (OUT
14、PUT) also for Functional Pinbreak;case IO_CTL_GPIO_H_UP: v_pIOPregs->GPHUP= *(DWORD*)pBufIn;/GPHUP SETbreak; case IO_CTL_GPIO_J_CON: v_pIOPregs->GPJCON= *(DWORD*)pBufIn;/GPJCON SETbreak;case IO_CTL_GPIO_J_DAT_INPUT:
15、 *(DWORD*)pBufOut=v_pIOPregs->GPJDAT; /GPJDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_J_DAT_OUTPUT:v_pIOPregs->GPJDAT= *(DWORD*)pBufIn; /GPJDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_J_UP: v_pIOPregs->GPJUP= *(DWORD*)pBufI
16、n;/GPJUP SETbreak; default:break; RETAILMSG(0,(TEXT("GPIO_Control:Ioctl code = 0x%xrn"), dwCode);return TRUE; 測(cè)試程序,封裝了2個(gè)輸入輸出GPIO函數(shù),調(diào)用十分方便:#include "stdafx.h"#include "Relay2.h"#include "Relay2Dlg.h"#include "GPIO_D
17、river.h"#ifdef _DEBUG#define new DEBUG_NEW#endif DWORD RData,BUFCON,BUFOUT,BUFIN; struct GPIO DWORD GPIOCON; DWORD GPIOIN;DWORD GPIOOUT; struct GPIO GPA=g
18、pacon,NULL,gpaout , GPB=gpbcon,gpbin,gpbout , GPC=gpccon,gpcin,gpcout , GPD=gpdcon,gpdin,gpdout , GPE=gpecon,gpein,gpeout , GPF=gpfcon,gpfin,gpfout , GPG=gpgcon,gpgin,gpgout , GPH=gphcon,gphin,gphout , GP
19、J=gpjcon,gpjin,gpjout ; /define and choose GPIO / CRelay2Dlg 對(duì)話框CRelay2Dlg:CRelay2Dlg(CWnd* pParent /*=NULL*/): CDialog(CRelay2Dlg:IDD, pParent)m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);void CRelay2Dlg:DoDataExchange(CDataExchange* pDX)CDia
20、log:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CRelay2Dlg, CDialog)#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)ON_WM_SIZE()#endif/AFX_MSG_MAPON_BN_CLICKED(IDC_BUTTON1, &CRelay2Dlg:OnBnClickedButton1)ON_BN_CLICKED(IDC_BUTTON2, &CRelay2Dlg:OnBnClickedButton2)END_ME
21、SSAGE_MAP()/ CRelay2Dlg 消息處理程序BOOL CRelay2Dlg:OnInitDialog()CDialog:OnInitDialog();/ 設(shè)置此對(duì)話框的圖標(biāo)。當(dāng)應(yīng)用程序主窗口不是對(duì)話框時(shí),框架將自動(dòng)/ 執(zhí)行此操作SetIcon(m_hIcon, TRUE);/ 設(shè)置大圖標(biāo)SetIcon(m_hIcon, FALSE);/ 設(shè)置小圖標(biāo)/ TODO: 在此添加額外的初始化代碼gpiodriver=CreateFile(L"GIO1:",GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING
22、,0,NULL );/gpiodriver initif(!gpiodriver)MessageBox(L"打開(kāi)GPIO設(shè)備失敗!");return TRUE; / 除非將焦點(diǎn)設(shè)置到控件,否則返回 TRUE#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)void CRelay2Dlg:OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)if (AfxIsDRAEnabled()DRA:RelayoutDialog(A
23、fxGetResourceHandle(), this->m_hWnd, DRA:GetDisplayMode() != DRA:Portrait ? MAKEINTRESOURCE(IDD_RELAY2_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_RELAY2_DIALOG);#endif DWORD CRelay2Dlg:GPIOINPUT(DWORD GPIOCON,DWORD GPIOIN,DWORD BUFCON,DWORD BUFOUT ) /the function is used f
24、or GPIO INPUT DWORD RData; DeviceIoControl(gpiodriver,GPIOCON,&BUFCON,4,NULL,0,NULL,NULL); DeviceIoControl(gpiodriver,GPIOIN,NULL,0,&BUFOUT,4,NULL,NULL); memcpy(&RData,&BUFOUT,4);return RData; DWORD CRelay2Dlg:GPIOINPUT1(struct G
25、PIO GP,USHORT NUM ) /the function is used for GPIO INPUT BETTER BUFCON &=(3<<(2*NUM); DeviceIoControl(gpiodriver,GP.GPIOCON,&BUFCON,4,NULL,0,NULL,NULL); DeviceIoControl(gpiodriver,GP.GPIOIN,NULL,0,&BUFOUT,4
26、,NULL,NULL); memcpy(&RData,&BUFOUT,4);return RData; VOID CRelay2Dlg:GPIOOUTPUT(DWORD GPIOCON,DWORD GPIOOUT,DWORD BUFCON,DWORD BUFIN ) /the function is used for GPIO OUTPUT DeviceIoControl(gpiodriver,GPIOCON,&BUFCON,4,NULL,0,NULL,N
27、ULL); DeviceIoControl(gpiodriver,GPIOOUT,&BUFIN,4,NULL,0,NULL,0); VOID CRelay2Dlg:GPIOOUTPUT1(struct GPIO GP,USHORT NUM,BYTE PINSTATE ) /the function is used for GPIO OUTPUT better if(GP.GPIOIN!=NULL) BUFCON=(BUFCON &(3<<(2*NUM)|(1<<(2*NUM);else B
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年銷(xiāo)售經(jīng)理區(qū)域市場(chǎng)拓展聘用合同模板2篇
- 2025年項(xiàng)目工程中介協(xié)議書(shū)模板(含設(shè)計(jì)、施工、驗(yàn)收)3篇
- 2025年私人房產(chǎn)買(mǎi)賣(mài)合同文本與合同解除條件3篇
- 民政局2025版離婚協(xié)議書(shū)婚姻糾紛調(diào)解服務(wù)協(xié)議2篇
- 二零二五版美容院美容院連鎖加盟管理合同4篇
- 墻面裝飾板施工方案
- 窮人續(xù)寫(xiě)200字6篇
- 2024年中級(jí)經(jīng)濟(jì)師考試題庫(kù)(典型題)
- 2025年消防系統(tǒng)智能化改造與安全評(píng)估合同協(xié)議3篇
- 2024年園區(qū)綠化管理制度
- 二零二五年度無(wú)人駕駛車(chē)輛測(cè)試合同免責(zé)協(xié)議書(shū)
- 北京市海淀區(qū)2024-2025學(xué)年高一上學(xué)期期末考試歷史試題(含答案)
- 常用口服藥品的正確使用方法
- 2025年湖北華中科技大學(xué)招聘實(shí)驗(yàn)技術(shù)人員52名歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2024年鉆探工程勞務(wù)協(xié)作協(xié)議樣式版B版
- 《心肺復(fù)蘇機(jī)救治院內(nèi)心搏驟?;颊咦o(hù)理專(zhuān)家共識(shí)》解讀
- 計(jì)算機(jī)二級(jí)WPS考試試題
- 智聯(lián)招聘行測(cè)題庫(kù)及答案
- 前程無(wú)憂(yōu)測(cè)評(píng)題庫(kù)及答案
- 2023中華護(hù)理學(xué)會(huì)團(tuán)體標(biāo)準(zhǔn)-注射相關(guān)感染預(yù)防與控制
- 超潔凈管道(CL-PVC)施工技術(shù)
評(píng)論
0/150
提交評(píng)論