1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
|
#include "as608.h"
u32 AS608Addr = 0XFFFFFFFF;
void PS_StaGPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(AS608_GPIO_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = AS608_TOUCH_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(AS608_GPIO_PORT, &GPIO_InitStructure); }
static void SendHead(void) { Usart_SendByte(AS608_USART,0xEF); Usart_SendByte(AS608_USART,0x01); }
static void SendAddr(void) { Usart_SendByte(AS608_USART,AS608Addr>>24); Usart_SendByte(AS608_USART,AS608Addr>>16); Usart_SendByte(AS608_USART,AS608Addr>>8); Usart_SendByte(AS608_USART,AS608Addr); }
static void SendFlag(u8 flag) { Usart_SendByte(AS608_USART,flag); }
static void SendLength(int length) { Usart_SendByte(AS608_USART,length>>8); Usart_SendByte(AS608_USART,length); }
static void Sendcmd(u8 cmd) { Usart_SendByte(AS608_USART,cmd); }
static void SendCheck(u16 check) { Usart_SendByte(AS608_USART,check>>8); Usart_SendByte(AS608_USART,check); }
static u8 *JudgeStr(u16 waittime) { char *data; u8 str[8]; str[0]=0xef; str[1]=0x01; str[2]=AS608Addr>>24; str[3]=AS608Addr>>16; str[4]=AS608Addr>>8; str[5]=AS608Addr; str[6]=0x07; str[7]='\0'; AS608_RX_STA=0; while(--waittime) { delay_ms(1); if(AS608_RX_STA&0X8000) { AS608_RX_STA=0; data=strstr((const char*)AS608_RX_BUF,(const char*)str); if(data) return (u8*)data; } } return 0; }
u8 PS_GetImage(void) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x03); Sendcmd(0x01); temp = 0x01+0x03+0x01; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_GenChar(u8 BufferID) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x04); Sendcmd(0x02); Usart_SendByte(AS608_USART,BufferID); temp = 0x01+0x04+0x02+BufferID; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_Match(void) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x03); Sendcmd(0x03); temp = 0x01+0x03+0x03; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_Search(u8 BufferID,u16 StartPage,u16 PageNum,SearchResult *p) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x08); Sendcmd(0x04); Usart_SendByte(AS608_USART,BufferID); Usart_SendByte(AS608_USART,StartPage>>8); Usart_SendByte(AS608_USART,StartPage); Usart_SendByte(AS608_USART,PageNum>>8); Usart_SendByte(AS608_USART,PageNum); temp = 0x01+0x08+0x04+BufferID+(StartPage>>8)+(u8)StartPage+(PageNum>>8)+(u8)PageNum; SendCheck(temp); data = JudgeStr(2000); if(data) { ensure = data[9]; p->pageID = (data[10]<<8)+data[11]; p->mathscore = (data[12]<<8)+data[13]; } else ensure = 0xff; return ensure; }
u8 PS_RegModel(void) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x03); Sendcmd(0x05); temp = 0x01+0x03+0x05; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_StoreChar(u8 BufferID,u16 PageID) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x06); Sendcmd(0x06); Usart_SendByte(AS608_USART,BufferID); Usart_SendByte(AS608_USART,PageID>>8); Usart_SendByte(AS608_USART,PageID); temp = 0x01+0x06+0x06+BufferID+(PageID>>8)+(u8)PageID; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_DeletChar(u16 PageID,u16 N) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x07); Sendcmd(0x0C); Usart_SendByte(AS608_USART,PageID>>8); Usart_SendByte(AS608_USART,PageID); Usart_SendByte(AS608_USART,N>>8); Usart_SendByte(AS608_USART,N); temp = 0x01+0x07+0x0C+(PageID>>8)+(u8)PageID+(N>>8)+(u8)N; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_Empty(void) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x03); Sendcmd(0x0D); temp = 0x01+0x03+0x0D; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_WriteReg(u8 RegNum,u8 DATA) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x05); Sendcmd(0x0E); Usart_SendByte(AS608_USART,RegNum); Usart_SendByte(AS608_USART,DATA); temp = RegNum+DATA+0x01+0x05+0x0E; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff;
return ensure; }
u8 PS_ReadSysPara(SysPara *p) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x03); Sendcmd(0x0F); temp = 0x01+0x03+0x0F; SendCheck(temp); data = JudgeStr(1000); if(data) { ensure = data[9]; p->PS_max = (data[14]<<8)+data[15]; p->PS_level = data[17]; p->PS_addr = (data[18]<<24)+(data[19]<<16)+(data[20]<<8)+data[21]; p->PS_size = data[23]; p->PS_N = data[25]; } else ensure=0xff;
return ensure; }
u8 PS_SetAddr(u32 PS_addr) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x07); Sendcmd(0x15); Usart_SendByte(AS608_USART,PS_addr>>24); Usart_SendByte(AS608_USART,PS_addr>>16); Usart_SendByte(AS608_USART,PS_addr>>8); Usart_SendByte(AS608_USART,PS_addr); temp = 0x01+0x07+0x15+(u8)(PS_addr>>24)+(u8)(PS_addr>>16)+(u8)(PS_addr>>8) +(u8)PS_addr; SendCheck(temp); AS608Addr = PS_addr; data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff;
return ensure; }
u8 PS_WriteNotepad(u8 NotePageNum,u8 *Byte32) { u16 temp; u8 ensure,i; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(36); Sendcmd(0x18); Usart_SendByte(AS608_USART,NotePageNum); for(i=0;i<32;i++) { Usart_SendByte(AS608_USART,Byte32[i]); temp += Byte32[i]; } temp = 0x01+36+0x18+NotePageNum+temp; SendCheck(temp); data = JudgeStr(2000); if(data) ensure = data[9]; else ensure = 0xff; return ensure; }
u8 PS_ReadNotepad(u8 NotePageNum,u8 *Byte32) { u16 temp; u8 ensure,i; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x04); Sendcmd(0x19); Usart_SendByte(AS608_USART,NotePageNum); temp = 0x01+0x04+0x19+NotePageNum; SendCheck(temp); data = JudgeStr(2000); if(data) { ensure = data[9]; for(i=0;i<32;i++) { Byte32[i] = data[10+i]; } } else ensure = 0xff; return ensure; }
u8 PS_HighSpeedSearch(u8 BufferID,u16 StartPage,u16 PageNum,SearchResult *p) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x08); Sendcmd(0x1b); Usart_SendByte(AS608_USART,BufferID); Usart_SendByte(AS608_USART,StartPage>>8); Usart_SendByte(AS608_USART,StartPage); Usart_SendByte(AS608_USART,PageNum>>8); Usart_SendByte(AS608_USART,PageNum); temp = 0x01+0x08+0x1b+BufferID+(StartPage>>8)+(u8)StartPage+(PageNum>>8)+(u8)PageNum; SendCheck(temp); data = JudgeStr(2000); if(data) { ensure = data[9]; p->pageID = (data[10]<<8) +data[11]; p->mathscore = (data[12]<<8) +data[13]; } else ensure=0xff; return ensure; }
u8 PS_ValidTempleteNum(u16 *ValidN) { u16 temp; u8 ensure; u8 *data; SendHead(); SendAddr(); SendFlag(0x01); SendLength(0x03); Sendcmd(0x1d); temp = 0x01+0x03+0x1d; SendCheck(temp); data=JudgeStr(2000); if(data) { ensure=data[9]; *ValidN = (data[10]<<8) +data[11]; } else ensure=0xff;
return ensure; }
u8 PS_HandShake(u32 *PS_Addr) { SendHead(); SendAddr(); Usart_SendByte(AS608_USART,0X01); Usart_SendByte(AS608_USART,0X00); Usart_SendByte(AS608_USART,0X00); delay_ms(200); if(AS608_RX_STA&0X8000) { if( AS608_RX_BUF[0]==0XEF&&AS608_RX_BUF[1]==0X01&&AS608_RX_BUF[6]==0X07) { *PS_Addr=(AS608_RX_BUF[2]<<24) + (AS608_RX_BUF[3]<<16) +(AS608_RX_BUF[4]<<8) + (AS608_RX_BUF[5]); AS608_RX_STA = 0; return 0; } AS608_RX_STA=0; } return 1; }
const char *EnsureMessage(u8 ensure) { const char *p; switch(ensure) { case 0x00: p="OK";break; case 0x01: p="数据包接收错误";break; case 0x02: p="传感器上没有手指";break; case 0x03: p="录入指纹图像失败";break; case 0x04: p="指纹图像太干、太淡而生不成特征";break; case 0x05: p="指纹图像太湿、太糊而生不成特征";break; case 0x06: p="指纹图像太乱而生不成特征";break; case 0x07: p="指纹图像正常,但特征点太少(或面积太小)而生不成特征";break; case 0x08: p="指纹不匹配";break; case 0x09: p="没搜索到指纹";break; case 0x0a: p="特征合并失败";break; case 0x0b: p="访问指纹库时地址序号超出指纹库范围"; case 0x10: p="删除模板失败";break; case 0x11: p="清空指纹库失败";break; case 0x15: p="缓冲区内没有有效原始图而生不成图像";break; case 0x18: p="读写 FLASH 出错";break; case 0x19: p="未定义错误";break; case 0x1a: p="无效寄存器号";break; case 0x1b: p="寄存器设定内容错误";break; case 0x1c: p="记事本页码指定错误";break; case 0x1f: p="指纹库满";break; case 0x20: p="地址错误";break; default : p="模块返回确认码有误";break; } return p; }
|