驱动开发6X6矩阵键盘驱动.doc

上传人:仙人指路1688 文档编号:4150821 上传时间:2023-04-07 格式:DOC 页数:38 大小:179KB
返回 下载 相关 举报
驱动开发6X6矩阵键盘驱动.doc_第1页
第1页 / 共38页
驱动开发6X6矩阵键盘驱动.doc_第2页
第2页 / 共38页
驱动开发6X6矩阵键盘驱动.doc_第3页
第3页 / 共38页
驱动开发6X6矩阵键盘驱动.doc_第4页
第4页 / 共38页
驱动开发6X6矩阵键盘驱动.doc_第5页
第5页 / 共38页
点击查看更多>>
资源描述

《驱动开发6X6矩阵键盘驱动.doc》由会员分享,可在线阅读,更多相关《驱动开发6X6矩阵键盘驱动.doc(38页珍藏版)》请在三一办公上搜索。

1、AT91SAM9263 WINCE 6.0 R2驱动开发-6X6矩阵键盘驱动 1.原理图2.代码view plaincopy to clipboardprint?01.#include 02.#include 03.#include 04.#include 05.#include 06.#include 07.#include 08.#include 09.#include matrixkey.h 10.#include Oal_timer.h 11.#include at91_pio.h 12./ Controller includes 13.#include at91sam9263_gpi

2、o.h 14.#include AT91SAM9263_oal_intr.h 15.#include atmel_oal_ioctl.h 16.static HANDLE m_hMute; 17. 18.static BYTE Virtualkey0=VK_NUMPAD0; 19.static HANDLE m_hevInterrupt0; 20.static HANDLE gintThread0; 21.static DWORD g_dwSysIntrToIrq0 = SYSINTR_UNDEFINED; 22. 23.static BYTE Virtualkey1=VK_NUMPAD0;

3、24.static HANDLE m_hevInterrupt1; 25.static HANDLE gintThread1; 26.static DWORD g_dwSysIntrToIrq1 = SYSINTR_UNDEFINED; 27. 28.static BYTE Virtualkey2=VK_NUMPAD0; 29.static HANDLE m_hevInterrupt2; 30.static HANDLE gintThread2; 31.static DWORD g_dwSysIntrToIrq2 = SYSINTR_UNDEFINED; 32. 33.static BYTE

4、Virtualkey3=VK_NUMPAD0; 34.static HANDLE m_hevInterrupt3; 35.static HANDLE gintThread3; 36.static DWORD g_dwSysIntrToIrq3 = SYSINTR_UNDEFINED; 37. 38.static BYTE Virtualkey4=VK_NUMPAD0; 39.static HANDLE m_hevInterrupt4; 40.static HANDLE gintThread4; 41.static DWORD g_dwSysIntrToIrq4 = SYSINTR_UNDEFI

5、NED; 42. 43.static BYTE Virtualkey5=VK_NUMPAD0; 44.static HANDLE m_hevInterrupt5; 45.static HANDLE gintThread5; 46.static DWORD g_dwSysIntrToIrq5 = SYSINTR_UNDEFINED; 47./ 48. 49.static BYTE int9keyup=0; 50. 51.static void loopn(UINT32 wCount) 52. 53.volatile unsigned int i, k,j=0; 54. for (k=0; kwC

6、ount; k+) 55. for(i=0;i 100; i+) j+; /400n 56. 57. 58.static DWORD KeyPadLock() 59. 60. DWORD dwStatus; 61. 62. dwStatus = WaitForSingleObject(m_hMute, INFINITE); 63. if(dwStatus = WAIT_OBJECT_0) 64. dwStatus = ERROR_SUCCESS; 65. else 66. dwStatus = GetLastError(); 67. 68. 69. return dwStatus; 70. 7

7、1. 72.static DWORD KeyPadUnLock() 73. 74. DWORD dwStatus = ERROR_SUCCESS; 75. BOOL fOk; 76. 77. fOk = ReleaseMutex(m_hMute); 78. if(!fOk) 79. dwStatus = GetLastError(); 80. 81. 82. return dwStatus; 83. 84. 85./ 中断脚输入为低则返回TRUE,否则返回FALSE 86.static BOOL IsIntPortLow(unsigned IrqNumber) 87. 88. int resu

8、lt; 89. result=pio_get_value(IrqNumber); 90. if(result) 91. return FALSE; 92. else 93. return TRUE; 94. 95./ 中断脚输入是否稳定,稳定则返回TRUE,否则返回FALSE 96.static BOOL IsIntPortStable(unsigned IrqNumber) 97. 98. int i; 99. int pre,now; 100. KeyPadLock(); 101. pre=pio_get_value(IrqNumber); 102. for(i=0;i3;i+) 103.

9、 104. Sleep(3); 105. now=pio_get_value(IrqNumber); 106. if(pre!=now) 107. 108. KeyPadUnLock(); 109. return FALSE; 110. 111. 112. KeyPadUnLock(); 113. return TRUE; 114. 115./所有输出管脚输出高电平 116.void alloutpinhigh(void) 117. 118. pio_set_value(AT91C_PIN_PB(22), 1); 119. pio_set_value(AT91C_PIN_PB(23), 1);

10、 120. pio_set_value(AT91C_PIN_PB(24), 1); 121. pio_set_value(AT91C_PIN_PB(25), 1); 122. pio_set_value(AT91C_PIN_PB(26), 1); 123. pio_set_value(AT91C_PIN_PB(27), 1); 124. 125./所有输出管脚输出低电平 126.void alloutpinlow(void) 127. 128. pio_set_value(AT91C_PIN_PB(22), 0); 129. pio_set_value(AT91C_PIN_PB(23), 0)

11、; 130. pio_set_value(AT91C_PIN_PB(24), 0); 131. pio_set_value(AT91C_PIN_PB(25), 0); 132. pio_set_value(AT91C_PIN_PB(26), 0); 133. pio_set_value(AT91C_PIN_PB(27), 0); 134. 135.#define ENTRY_POWEROFF 0x2 136.#define ENTRY_NULL 0x0 137.#define poweroff_counter 1300 138.#define wait_cnt 100 139. 140. 14

12、1.INT WINAPI Int0_Thread(void) 142. 143. DWORD result; 144. BYTE i; 145. static int count=0; 146. while(1) 147. 148. 149. result=WaitForSingleObject(m_hevInterrupt0, INFINITE); 150. switch(result) 151. 152. case WAIT_OBJECT_0: 153. const struct pio_desc hw_pio = 154. INT0, AT91C_PIN_PB(6), 0, PIO_PU

13、LLUP, PIO_INPUT, 155. NULL, 156. ; 157. pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc); 158. / 消除按键抖动 159. if(!IsIntPortStable(AT91C_PIN_PB(6) 160. 161. InterruptDone(g_dwSysIntrToIrq0); 162. break; 163. 164. 165. / 中断输入是高电平,说明按键弹起 166. if(pio_get_value(AT91C_PIN_PB(6) 167. 168. keybd_even

14、t(Virtualkey0,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); 169. RETAILMSG(1,(TEXT(Virtualkey0=%d uprn),Virtualkey0); 170. 171. / 否则,轮询输出低电平, 172. else 173. 174. / 输出管脚全部输出高 175. alloutpinhigh(); 176. for(i=0;i6;i+) 177. 178. pio_set_value(AT91C_PIN_PB(22)+i, 0); 179. Sleep(3); 180. while(!pio_get_v

15、alue(AT91C_PIN_PB(6) ) 181. 182. Sleep(10); 183. /按键为A,B,C,D,E,F.0x41,0x42,0x43,0x44,0x45,0x46. Virtualkey0=0x41+i; 184. if(count=0) 185. 186. Virtualkey0=0x41+i; 187. keybd_event(Virtualkey0 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); 188. RETAILMSG(1,(TEXT(Virtualkey0=%d downrn),Virtualkey0); 189. count+; 19

16、0. 191. 192. count=0; 193. pio_set_value(AT91C_PIN_PB(22)+i, 1); 194. 195. alloutpinlow(); 196. 197. InterruptDone(g_dwSysIntrToIrq0); 198. break; 199. 200. 201. 202. 203.INT WINAPI Int1_Thread(void) 204. 205. DWORD result; 206. BYTE i; 207. static int count=0; 208. while(1) 209. 210. 211. result=Wa

17、itForSingleObject(m_hevInterrupt1, INFINITE); 212. switch(result) 213. 214. case WAIT_OBJECT_0: 215. const struct pio_desc hw_pio = 216. INT0, AT91C_PIN_PB(7), 0, PIO_PULLUP, PIO_INPUT, 217. NULL, 218. ; 219. pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc); 220. / 消除按键抖动 221. if(!IsIntPortS

18、table(AT91C_PIN_PB(7) 222. 223. InterruptDone(g_dwSysIntrToIrq1); 224. break; 225. 226. 227. / 中断输入是高电平,说明按键弹起 228. if(pio_get_value(AT91C_PIN_PB(7) 229. 230. keybd_event(Virtualkey1,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); 231. RETAILMSG(1,(TEXT(Virtualkey0=%d uprn),Virtualkey1); 232. 233. / 否

19、则,轮询输出低电平, 234. else 235. 236. / 输出管脚全部输出高 237. alloutpinhigh(); 238. for(i=0;i6;i+) 239. 240. pio_set_value(AT91C_PIN_PB(22)+i, 0); 241. Sleep(3); 242. while(!pio_get_value(AT91C_PIN_PB(7) ) 243. 244. if(count=0) 245. 246. Sleep(10); 247. /按键为G,H,I,J,K,L.0x47,0x48,0x49,0x4A,0x4B,0x4C. 248. Virtualk

20、ey1=0x47+i; 249. keybd_event(Virtualkey1 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); 250. RETAILMSG(1,(TEXT(Virtualkey0=%d downrn),Virtualkey1); 251. count+; 252. 253. 254. count=0; 255. pio_set_value(AT91C_PIN_PB(22)+i, 1); 256. 257. alloutpinlow(); 258. 259. InterruptDone(g_dwSysIntrToIrq1); 260. break; 261.

21、 262. 263. 264. 265.INT WINAPI Int2_Thread(void) 266. 267. DWORD result; 268. BYTE i; 269. static int count=0; 270. while(1) 271. 272. 273. result=WaitForSingleObject(m_hevInterrupt2, INFINITE); 274. switch(result) 275. 276. case WAIT_OBJECT_0: 277. const struct pio_desc hw_pio = 278. INT0, AT91C_PI

22、N_PB(11), 0, PIO_PULLUP, PIO_INPUT, 279. NULL, 280. ; 281. pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc); 282. / 消除按键抖动 283. if(!IsIntPortStable(AT91C_PIN_PB(11) 284. 285. InterruptDone(g_dwSysIntrToIrq2); 286. break; 287. 288. 289. / 中断输入是高电平,说明按键弹起 290. if(pio_get_value(AT91C_PIN_PB(11)

23、 291. 292. keybd_event(Virtualkey2,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); 293. RETAILMSG(1,(TEXT(Virtualkey0=%d uprn),Virtualkey2); 294. 295. / 否则,轮询输出低电平, 296. else 297. 298. / 输出管脚全部输出高 299. alloutpinhigh(); 300. for(i=0;i6;i+) 301. 302. pio_set_value(AT91C_PIN_PB(22)+i, 0); 303. Sleep(3);

24、304. while(!pio_get_value(AT91C_PIN_PB(11) ) 305. 306. if(count=0) 307. 308. Sleep(10); 309. /按键为M,N,O,P,Q,R.0x4D,0x4E,0x4F,0x50,0x51,0x52. 310. Virtualkey2=0x4D+i; 311. keybd_event(Virtualkey2 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); 312. RETAILMSG(1,(TEXT(Virtualkey0=%d downrn),Virtualkey2); 313. count+;

25、314. 315. 316. count=0; 317. pio_set_value(AT91C_PIN_PB(22)+i, 1); 318. 319. alloutpinlow(); 320. 321. InterruptDone(g_dwSysIntrToIrq2); 322. break; 323. 324. 325. 326. 327.INT WINAPI Int3_Thread(void) 328. 329. DWORD result; 330. BYTE i; 331. static int count=0; 332. while(1) 333. 334. 335. result=

26、WaitForSingleObject(m_hevInterrupt3, INFINITE); 336. switch(result) 337. 338. case WAIT_OBJECT_0: 339. const struct pio_desc hw_pio = 340. INT0, AT91C_PIN_PB(19), 0, PIO_PULLUP, PIO_INPUT, 341. NULL, 342. ; 343. pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc); 344. / 消除按键抖动 345. if(!IsIntPo

27、rtStable(AT91C_PIN_PB(19) 346. 347. InterruptDone(g_dwSysIntrToIrq3); 348. break; 349. 350. 351. / 中断输入是高电平,说明按键弹起 352. if(pio_get_value(AT91C_PIN_PB(19) 353. 354. keybd_event(Virtualkey3,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); 355. RETAILMSG(1,(TEXT(Virtualkey0=%d uprn),Virtualkey3); 356. 357

28、. / 否则,轮询输出低电平, 358. else 359. 360. / 输出管脚全部输出高 361. alloutpinhigh(); 362. for(i=0;i6;i+) 363. 364. pio_set_value(AT91C_PIN_PB(22)+i, 0); 365. Sleep(3); 366. while(!pio_get_value(AT91C_PIN_PB(19) ) 367. 368. if(count=0) 369. 370. Sleep(10); 371. /按键为S,T,U,V,W,X.0x53,0x54,0x55,0x56,0x57,0x58. 372. Virtualkey3=0x53+i; 373. keybd_event(Virtualkey3 ,0, KEYEVENTF_EXTENDEDKEY|0, 0); 374.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号