電子工程網(wǎng)
標(biāo)題: OK210開發(fā)板使用感想續(xù)之自己設(shè)計(jì)的紅外驅(qū)動(dòng) [打印本頁(yè)]
作者: flyday 時(shí)間: 2013-9-17 15:15
標(biāo)題: OK210開發(fā)板使用感想續(xù)之自己設(shè)計(jì)的紅外驅(qū)動(dòng)
經(jīng)過幾天的研究,終于把OK210開發(fā)板wince紅外驅(qū)動(dòng)的部分給完成了。
開發(fā)工具:vs2005,飛凌官方OK210開發(fā)板,杜邦線3根,烙鐵一把,焊錫,4.7k電阻一個(gè)。
開發(fā)軟件:Win CE 6.0
下圖是所需的開發(fā)工具
從網(wǎng)上找了好久,不是不能用,就是騙子代碼,根本不能用,最可氣的就是掛羊頭賣狗肉,標(biāo)著紅外驅(qū)動(dòng),用自己寶貴的積分,下載下來(lái)一看根本就不是,浪費(fèi)了我很多時(shí)間,最后沒辦法只能自己動(dòng)手了,這里充分體現(xiàn)了毛主席“自己動(dòng)手,豐衣足食”這句話的重要性。好了廢話不多說(shuō)吧我自己的這幾天的思路告訴大家讓大家以后少走彎路,在這里我也希望廣大網(wǎng)友能夠不吝惜自己的勞動(dòng)成果,把自己的奮斗果實(shí)奉獻(xiàn)下,這樣能讓很多網(wǎng)友少走彎路,大家慶幸之余也會(huì)非常感激”挖井人“的。首先,我是按照單片機(jī)解碼的思路,開始制作的Win CE操作系統(tǒng)的紅外驅(qū)動(dòng),可把我害苦了。我用的是中斷+定時(shí)器。思路呢和網(wǎng)上所有的都一樣,但是總是卡死在定時(shí)器上,定時(shí)器我用的是微秒級(jí)別的延時(shí),這樣已進(jìn)入系統(tǒng),總是不停地去響應(yīng)定時(shí)器的中斷,這樣就卡死在線程了。系統(tǒng)連起都起不來(lái)了,害的我倒騰了好幾天,最后沒辦法只能放棄了,改用延時(shí),網(wǎng)上有現(xiàn)成的函數(shù)。解碼的遙控器類型有很多,這里我只做了最通用的NEC遙控器,其他的只需要改一下高低電平時(shí)間就行了。NEC紅外協(xié)議,作為接收端來(lái)講,首先是引導(dǎo)碼,有9ms的低電平,然后是4.5ms的高電平,然后是32位的操作碼,對(duì)于按鍵來(lái)說(shuō)我們只需要解第三組就可以了,其他的NEC協(xié)議的知識(shí)可以從網(wǎng)上搜索下有很多的。現(xiàn)在只做紅外接收模塊,將準(zhǔn)備好的杜邦線插在紅外的三個(gè)引腳上,引腳順序,大家從網(wǎng)上搜索下,然后就是找一個(gè)直插的4.7k上拉電阻,接到hs0038的接受引腳和5v引腳中間。由于我的紅外解碼思路是中斷所以只能找中斷引腳了,但是通篇的找飛凌OK210開發(fā)板上中斷引腳真的是太難找了,(⊙o⊙)最后沒辦法只能找已經(jīng)引出的引腳了,最后發(fā)現(xiàn)按鍵上每個(gè)引腳都能用,都是中斷引腳,最后我選擇了外部中斷6,開發(fā)板的k4按鍵,將按鍵的上拉電阻去掉,然后焊接出一條引線,接到紅外接收器的接收引腳。下面是自己焊的紅外接收模塊。
好了硬件準(zhǔn)備完畢,現(xiàn)在開始寫驅(qū)動(dòng)。1.包含的頭文件:- //made in 2013-6-7 by mr wang
- #include "stdafx.h"
- #include
- #include
- #include
- #include
- #include
- #include
- #include "pmplatform.h"
- #include "Pkfuncs.h"
- #include
- #include
- #include "gpioentry_reg.h"
- #include
- typedef enum
- {
- EINT_SIGNAL_LOW_LEVEL = 0,
- EINT_SIGNAL_HIGH_LEVEL,
- EINT_SIGNAL_FALL_EDGE,
- EINT_SIGNAL_RISE_EDGE,
- EINT_SIGNAL_BOTH_EDGE
- } EINT_SIGNAL_METHOD;
- typedef enum
- {
- EINT_FILTER_DISABLE = 0,
- EINT_FILTER_DELAY,
- EINT_FILTER_DIGITAL
- } EINT_FILTER_METHOD;
- static volatile GPIO_REG * g_pGPIOReg = NULL;
- static DWORD g_dwSysIntrHS38 = SYSINTR_UNDEFINED;
- static HANDLE g_hEventHS38 = NULL;
- static HANDLE g_hEventResetBtn = NULL;
- static HANDLE g_hThreadHS38 = NULL;
- static BOOL g_bExitThread = FALSE;
- static BOOL pwstatus=TRUE;
- void Delay_us(int n);//延時(shí)us
- BOOL IRS_date(void);//判斷遙控低電平
- static void InitInterrupt(void);//中斷初始化
- void IRS_port_init(void); //引腳初始化
- void IRS_enable_interrupt(void);//使能中斷
- void IRS_disable_interrupt(void);//不使能中斷
- void IRS_clear_interrupt_pending(void);//清楚中斷屏蔽位
- BOOL IRS_set_filter_method(EINT_FILTER_METHOD eMethod, unsigned int uiFilterWidth);//選擇中斷的filter方式
- BOOL IRS_set_interrupt_method(EINT_SIGNAL_METHOD eMethod);//設(shè)置中斷方式
- 2.解碼線程:
- INT WINAPI HS38Thread(void)
- {
- int i,j;
- byte ircode[4];//四位編碼
- while(!g_bExitThread)
- {
- WaitForSingleObject(g_hEventHS38, INFINITE);
- if(g_bExitThread)
- {
- break;
- }
- IRS_disable_interrupt(); // 禁止中斷
- IRS_clear_interrupt_pending(); // 清除中斷標(biāo)志位
- InterruptDone(g_dwSysIntrHS38); //中斷完成,開始解碼
- Delay_us(8000);//延時(shí)掉ms的低電平,
- while(IRS_date());
- Delay_us(4000);//4.5ms高電平
- while(!IRS_date());
- for(j=0;j<4;j++)
- {
- for(i=0;i<8;i++)
- {
- while(IRS_date());
- Delay_us(700);
- if(IRS_date())// send 0
- {
- ircode[j]=ircode[j]>>1;
- }
- else
- {
- ircode[j]=ircode[j]|0x80;
- ircode[j]=ircode[j]>>1;
- Delay_us(1200);
- }
- }
- }
- Sleep(100);
- RETAILMSG(1,(TEXT("******* ircode[3] = %x\r\n"),ircode[3]));//打印第三組操作碼,便是按鍵的鍵碼
- IRS_enable_interrupt();
- }
- return 0;
- }
- 3.微妙延時(shí)函數(shù)
- void Delay_us(int n)
- {
- LARGE_INTEGER litmp;
- LONGLONG QPart1,QPart2;
- double dfMinus, dfFreq, dfTim;
- if(QueryPerformanceFrequency(&litmp)==FALSE)
- {
- return;
- }
- dfFreq = (double)litmp.QuadPart;
- QueryPerformanceCounter(&litmp);
- QPart1 = litmp.QuadPart;
- do
- {
- QueryPerformanceCounter(&litmp);
- QPart2=litmp.QuadPart;
- dfMinus=(double)(QPart2-QPart1);
- dfTim=dfMinus/dfFreq;
- }while(dfTim <0.000001*n);
- }
- 4.其他流驅(qū)動(dòng)接口函數(shù)
- //設(shè)置寄存器地址
- BOOL HS38_initialize_register_address(void *pGPIOReg)//,void *pHSReg)
- {
- if (pGPIOReg == NULL)
- {
- return FALSE;
- }
- else
- {
- g_pGPIOReg = (GPIO_REG *)pGPIOReg;
-
- }
- return TRUE;
- }
- //初始化
- void IRS_port_init(void)
- {
- Set_PinFunction(g_pGPIOReg, GPH06_EXT_INT_6);
- Set_PinPullUD(g_pGPIOReg, GPH06_EXT_INT_6, sgip_PULL_UP);
- }
- //使能引腳中斷
- void IRS_enable_interrupt(void)
- {
- Unmask_EXTINT(g_pGPIOReg, EXT_INT_6);
- }
- //禁止引腳中斷
- void IRS_disable_interrupt(void)
- {
- Mask_EXTINT(g_pGPIOReg, EXT_INT_6);
- }
- //清除引腳中斷
- void IRS_clear_interrupt_pending(void)
- {
- Clear_EXTINT(g_pGPIOReg, EXT_INT_6);
- }
- //設(shè)置中斷方式
- BOOL IRS_set_interrupt_method(EINT_SIGNAL_METHOD eMethod)
- {
- BOOL Ret = TRUE;
- switch(eMethod)
- {
- case EINT_SIGNAL_LOW_LEVEL:
- Set_EXTINT_TRLVL(g_pGPIOReg, EXT_INT_6, sgip_LOW_LEVEL);
- break;
- case EINT_SIGNAL_HIGH_LEVEL:
- Set_EXTINT_TRLVL(g_pGPIOReg, EXT_INT_6, sgip_HIGH_LEVEL);
- break;
- case EINT_SIGNAL_FALL_EDGE:
- Set_EXTINT_TRLVL(g_pGPIOReg, EXT_INT_6, sgip_FALLING_EDGE);
- break;
- case EINT_SIGNAL_RISE_EDGE:
- Set_EXTINT_TRLVL(g_pGPIOReg, EXT_INT_6, sgip_RISING_EDGE);
- break;
- case EINT_SIGNAL_BOTH_EDGE:
- Set_EXTINT_TRLVL(g_pGPIOReg, EXT_INT_6, sgip_BOTH_EDGE);
- break;
- default:
- Ret = FALSE;
- break;
- }
- return Ret;
- }
- //設(shè)置中斷filter方式
- BOOL IRS_set_filter_method(EINT_FILTER_METHOD eMethod, unsigned int uiFilterWidth)
- {
- BOOL Ret =TRUE;
- switch(eMethod)
- {
- case EINT_FILTER_DISABLE:
- Clr_EXTINT_FILTER(g_pGPIOReg, EXT_INT_6);
- break;
- case EINT_FILTER_DELAY:
- Set_EXTINT_FILTER(g_pGPIOReg, EXT_INT_6, sgip_DELAY_FLT, 0);
- break;
- case EINT_FILTER_DIGITAL:
- Set_EXTINT_FILTER(g_pGPIOReg, EXT_INT_6, sgip_DIGITAL_FLT, uiFilterWidth);
- break;
- default:
- Ret = FALSE;
- break;
- }
- return Ret;
- }
- //判斷遙控接收引腳低電平,返回true
- BOOL IRS_date(void)
- {
- if(Get_PinData(g_pGPIOReg,GPH06_EXT_INT_6))
- {
- return FALSE; // Low Active Switch (Pull-up switch)
- }
- else
- {
- return TRUE;
- }
- }
- static BOOL AllocResources(void)
- {
- DWORD dwIRQ;
- PHYSICAL_ADDRESS ioPhysicalBase = {0,0};
- //------------------
- // GPIO Controller SFR
- //------------------
- ioPhysicalBase.LowPart = BASE_REG_PA_GPIO;
- g_pGPIOReg = (GPIO_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(GPIO_REG), FALSE);
- if (g_pGPIOReg == NULL)
- {
- return FALSE;
- }
- dwIRQ = IRQ_EINT6;
- g_dwSysIntrHS38 = SYSINTR_UNDEFINED;
- g_hEventHS38 = NULL;
- if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwIRQ, sizeof(DWORD), &g_dwSysIntrHS38, sizeof(DWORD), NULL))
- {
- g_dwSysIntrHS38 = SYSINTR_UNDEFINED;
- return FALSE;
- }
- g_hEventHS38 = CreateEvent(NULL, FALSE, FALSE, NULL);
- if(NULL == g_hEventHS38)
- {
- return FALSE;
- }
- if (!(InterruptInitialize(g_dwSysIntrHS38, g_hEventHS38, 0, 0)))
- {
- return FALSE;
- }
- return TRUE;
- }
- static void ReleaseResources(void)
- {
- if (g_pGPIOReg != NULL)
- {
- MmUnmapIoSpace((PVOID)g_pGPIOReg, sizeof(GPIO_REG));
- g_pGPIOReg = NULL;
- }
- if (g_dwSysIntrHS38 != SYSINTR_UNDEFINED)
- {
- InterruptDisable(g_dwSysIntrHS38);
- }
- if (g_hEventHS38 != NULL)
- {
- CloseHandle(g_hEventHS38);
- }
- if (g_dwSysIntrHS38 != SYSINTR_UNDEFINED)
- {
- KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_dwSysIntrHS38, sizeof(DWORD), NULL, 0, NULL);
- }
- g_pGPIOReg = NULL;
- g_dwSysIntrHS38 = SYSINTR_UNDEFINED;
- g_hEventHS38 = NULL;
- }
- static void InitInterrupt(void)
- {
- // 禁止中斷
- IRS_disable_interrupt();
- // I初始化端口
- IRS_port_init();
- // 設(shè)置中斷模式
- IRS_set_interrupt_method(EINT_SIGNAL_BOTH_EDGE);
- IRS_set_filter_method(EINT_FILTER_DELAY, 0);
- // 清除中斷標(biāo)志位
- IRS_clear_interrupt_pending();
- // 使能中斷
- IRS_enable_interrupt();
- }
- BOOL WINAPI
- DllEntry(HANDLE hinstDLL,
- DWORD dwReason,
- LPVOID /* lpvReserved */)
- {
- switch(dwReason)
- {
- case DLL_PROCESS_ATTACH:
- DEBUGREGISTER((HINSTANCE)hinstDLL);
- return TRUE;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- break;
- #ifdef UNDER_CE
- case DLL_PROCESS_EXITING:
- break;
- case DLL_SYSTEM_STARTED:
- break;
- #endif
- }
- return TRUE;
- }
- BOOL IRS_Deinit(DWORD hDeviceContext)
- {
- g_bExitThread = TRUE;
- if (g_hThreadHS38) // Make Sure if thread is exist
- {
- IRS_disable_interrupt();
- IRS_clear_interrupt_pending();
- // Signal Thread to Finish
- SetEvent(g_hEventHS38);
- // Wait for Thread to Finish
- WaitForSingleObject(g_hThreadHS38, INFINITE);
- CloseHandle(g_hThreadHS38);
- g_hThreadHS38 = NULL;
- }
- ReleaseResources();
-
- //RETAILMSG(1,(TEXT("USERLED: IRS_Deinit\r\n")));
- return TRUE;
- }
- DWORD IRS_Init(DWORD dwContext)
- {
- RETAILMSG(1,(TEXT("Key_Gpio_Setting----\r\n")));
- if (AllocResources() == FALSE)
- {
- goto CleanUp;
- }
- HS38_initialize_register_address((void *)g_pGPIOReg);
- InitInterrupt();
-
- g_hThreadHS38 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) HS38Thread, NULL, 0, NULL);
- if (g_hThreadHS38 == NULL )
- {
- goto CleanUp;
- }
- return TRUE;
- CleanUp:
- IRS_Deinit(0);
- return FALSE;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- BOOL IRS_IOControl(DWORD hOpenContext,
- DWORD dwCode,
- PBYTE pBufIn,
- DWORD dwLenIn,
- PBYTE pBufOut,
- DWORD dwLenOut,
- PDWORD pdwActualOut)
- {
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- DWORD IRS_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_Open\r\n")));
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- BOOL IRS_Close(DWORD hOpenContext)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_Close\r\n")));
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void IRS_PowerDown(DWORD hDeviceContext)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_PowerDown\r\n")));
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void IRS_PowerUp(DWORD hDeviceContext)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_PowerUp\r\n")));
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- DWORD IRS_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_Read\r\n")));
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- DWORD IRS_Seek(DWORD hOpenContext, long Amount, DWORD Type)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_Seek\r\n")));
- return 0;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- DWORD IRS_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes)
- {
- RETAILMSG(0,(TEXT("USERLED: IRS_Write\r\n")));
- return 0;
- }
復(fù)制代碼 6.實(shí)驗(yàn)結(jié)果,當(dāng)你按下遙控器上的按鍵時(shí),dnw或超級(jí)終端上會(huì)顯示相應(yīng)的按鍵碼如下:
長(zhǎng)時(shí)間按某一個(gè)按鍵,會(huì)顯示同一個(gè)鍵值如下:
作者: moonly 時(shí)間: 2013-9-24 11:04
樓主精神可嘉 佩服 學(xué)習(xí)了
作者: liqiaw 時(shí)間: 2013-9-27 23:52
感謝分享,當(dāng)初用1602顯示遙控器的紅外碼,那時(shí)候用51的中斷解碼的,現(xiàn)在跑cortex—A9+Android,還可以可以裝ubuntu,可以加入學(xué)習(xí)交流群187587764,畢竟現(xiàn)在android相對(duì)于linux還是火很多的。。。
歡迎光臨 電子工程網(wǎng) (http://m.qingdxww.cn/) |
Powered by Discuz! X3.4 |
主站蜘蛛池模板:
日本成人免费观看|
亚洲视频在线观看免费视频|
深夜你懂的在线网址入口|
亚洲天堂男人|
国产亚洲精品在线视频|
偷拍久久国产视频免费|
自拍黄色片|
日韩一级欧美一级在线观看|
亚洲国产精品久久精品成人|
污丝瓜视频|
草莓视频免费在线观看|
日韩人妻少妇一区二区三区|
特级免费毛片|
日韩一区二区三区免费视频|
网站在线观看高清免费|
www.绿巨人|
桃花在线观看播放|
四虎激情影院|
天天躁夜夜躁狠狠躁躁|
亚洲另类在线观看|
草莓视频在线看免费高清观看
|
手伸进内衣揉捏办公室羞羞漫画|
佐佐木明希 中文 在线|
日韩精品卡1卡2三卡四卡乱码|
校园春色欧美日韩|
日韩欧美在线免费观看|
午夜视频在线观看一区二区|
国产91青青成人a在线|
色色男_免费|
四虎影库网址|
天天视频色|
色站综合|
yellow日本高清在线|
亚洲av欧美在我|
日韩欧美一区二区久久
|
四虎私人影院|
色免费网站|
亚洲视频免费在线看|
久久高清内射无套|
午夜激情网站|
天堂资源站|