已阅读5页,还剩33页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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_gpio.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; 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 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_undefined; 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; kwcount; 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. 71. 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 result; 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. 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); 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); 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. 141.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_pullup, 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_event(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_value(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+; 190. 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=waitforsingleobject(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(!isintportstable(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. / 否则,轮询输出低电平, 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. virtualkey1=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. 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_pin_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) 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); 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+; 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=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(!isintportstable(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. / 否则,轮询输出低电平, 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. retailmsg(1,(text(virtualkey0=%d downrn),virtualkey3); 375. count+; 376. 377. 378. count=0; 379. pio_set_value(at91c_pin_pb(22)+i, 1); 380. 381. alloutpinlow(); 382. 383. interruptdone(g_dwsysintrtoirq3); 384. break; 385. 386. 387. 388. 389.int winapi int4_thread(void) 390. 391. dword result; 392. byte i; 393. static int count=0; 394. while(1) 395. 396. 397. result=waitforsingleobject(m_hevinterrupt4, infinite); 398. switch(result) 399. 400. case wait_object_0: 401. const struct pio_desc hw_pio = 402. int0, at91c_pin_pb(20), 0, pio_pullup, pio_input, 403. null, 404. ; 405. pio_setup(hw_pio, sizeof(hw_pio)/sizeof(struct pio_desc); 406. / 消除按键抖动 407. if(!isintportstable(at91c_pin_pb(20) 408. 409. interruptdone(g_dwsysintrtoirq4); 410. break; 411. 412. 413. / 中断输入是高电平,说明按键弹起 414. if(pio_get_value(at91c_pin_pb(20) 415. 416. keybd_event(virtualkey4,0, keyeventf_extendedkey|keyeventf_keyup, 0); 417. retailmsg(1,(text(virtualkey0=%d uprn),virtualkey4); 418. 419. / 否则,轮询输出低电平, 420. else 421. 422. / 输出管脚全部输出高 423. alloutpinhigh(); 424. for(i=0;i6;i+) 425. 426. pio_set_value(at91c_pin_pb(22)+i, 0); 427. sleep(3); 428. while(!pio_get_value(at91c_pin_pb(20) ) 429. 430. if(count=0) 431. 432. sleep(10); 433. /按键为y,z.0x59,0x5a. 434. /按键为0,1,2,3.0x30,0x31,0x32,0x33. 435. if(i2) 436. virtualkey4=0x59+i; 437. else 438. v
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 卫生副高职称考试试题
- 2021年税务师《财务与会计》财管公式总结
- 公考资料湖北省考《行测》真题附答案
- 国开电大老年教育专题(河北)形考任务 3参考答案
- 山西省公务员2025年考试申论真题试卷(含答案)
- 会展企业战略管理考前押题宝典
- (完整版)制药工程试题
- 工业机器人技术考试题库
- 安全员B证(项目负责人)操作证考试100题及答案
- 2025年中医眼科角膜炎中医眼科临床康复能力测试卷
- 高中化学实验校本课程
- 绿植采购合同
- 湖北省武汉市江岸区2024-2025学年上学期元调九年级化学试题(含标答)
- 橡胶硫化技术考核试卷
- 2025年春季形势与政策-从教育大国迈向教育强国
- 直肠癌结肠造瘘护理查房
- 2025年官方个人采购协议格式
- GB/T 26189.2-2024工作场所照明第2部分:室外作业场所的安全保障照明要求
- 2025届中考生物复习课件 主题5 第5讲 人体生命活动的调节
- DB21T 3820-2023 示范型居家和社区养老服务中心建设规范
- 天津市滨海新区2023-2024学年四年级上学期语文期末试卷
评论
0/150
提交评论