找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4672|回复: 0
打印 上一主题 下一主题
收起左侧

NFC刷卡机工程 基于TAM3 一个真实项目工程!

[复制链接]
跳转到指定楼层
楼主
这是一个真实项目工程!
项目目的:做一套刷卡系统,识别并控制读写NFC卡中的信息,其中NFC是主动卡(含电源MCU,并有私有命令)
本项目是系统里面刷卡端,功能是发送无线命令到NFC卡,控制卡信息信息写入,读取刷卡记录,
本代码包括一个LCD屏,一个键盘,拼音输入法,NFC控制器,低功耗设置等


完整代码下载:
ZCardA.zip (582.06 KB, 下载次数: 22)

部分源码预览:
  1. #include <tam3lib.h>
  2. #include <fcard_hal.h>

  3. #include "flash_initiator.h"
  4. #include "uart_dep_initiator.h"
  5. #include "dep_initiator.h"

  6. extern int main_app_init_user(void);
  7. extern int main_app_init_finger(void);
  8. extern int main_app_card_login(void);
  9. extern int main_app_set_datetime(void);
  10. extern int main_app_set_location(void);
  11. extern int main_app_set_password(void);
  12. extern int main_app_card_format(void);

  13. static void show_main_menu(int index){
  14.     static char *menu[]={
  15.         "设置本机密码",
  16.         "设置日期时间",
  17.         "设置位置信息",
  18.         "初始化卡用户",
  19.         "下载用户指纹",
  20.         "卡管理员登录",
  21.         "格式化卡系统"
  22.     };   
  23.     fcard_lcd_clear();
  24.     fcard_lcd_printh1("%d:%s",index+0,menu[index+0]);
  25.     fcard_lcd_printh2("%d:%s",index+1,menu[index+1]);
  26.     fcard_lcd_printh3("%d:%s",index+2,menu[index+2]);
  27.     fcard_lcd_printh4("%d:%s",index+3,menu[index+3]);
  28. }

  29. int get_choice(void){
  30.     int select = 0;
  31.     do{
  32.         mdelay(50);
  33.         select = fcard_kbd_peek();
  34.         if (select == 27 || select == 13)
  35.             break;
  36.     }while(select<'0'||select>'9');
  37.     return select;
  38. }
  39. int check_quit(void){
  40.     int select = 0;
  41.     do{
  42.         mdelay(50);
  43.         select = fcard_kbd_peek();
  44.     }while(select!=27&&select!=13);
  45.     return select;
  46. }

  47. int main_setting(){
  48.     int select=0;   
  49.     for(;;){
  50.         show_main_menu(1);
  51.         select = get_choice();  
  52.         if (select == 27) break;
  53.         switch(select){
  54.             case '0':
  55.                 printf("select 0\r\n");
  56.                 fcard_lcd_clear();
  57.                 main_app_set_password();
  58.                 //select=check_quit();
  59.                 break;
  60.             case '1':
  61.                 printf("select 1\r\n");
  62.                 fcard_lcd_clear();
  63.                 main_app_set_datetime();   
  64.                 //select=check_quit();            
  65.                 break;
  66.             case '2':
  67.                 printf("select 2\r\n");
  68.                 fcard_lcd_clear();
  69.                 main_app_set_location();   
  70.                 break;
  71.             case '3':
  72.                 printf("select 3\r\n");
  73.                 fcard_lcd_clear();
  74.                 main_app_init_user();  
  75.                 break;
  76.             case '4':
  77.                 printf("select 4\r\n");
  78.                 fcard_lcd_clear();
  79.                 main_app_init_finger();  
  80.                 break;
  81.             case '5':
  82.                 printf("select 5\r\n");
  83.                 fcard_lcd_clear();
  84.                 main_app_card_login();  
  85.                 break;
  86.             case '6':
  87.                 printf("select 6\r\n");
  88.                 fcard_lcd_clear();
  89.                 main_app_card_format();  
  90.                 break;            
  91.             default:
  92.                 printf("default\r\n");
  93.                 //fcard_lcd_clear();
  94.                 break;
  95.         }
  96.     }  
  97.     return 0;
  98. }
  99. int main_login(){
  100.     int i,key,length;
  101.     int timeout=15000;
  102.     char line[36];
  103.     char password[36];
  104.     char showinfo[36];
  105.    
  106.     fcard_beep_off();
  107.    
  108.     if (!hasAdministratorPassword()){
  109.         return main_setting();
  110.     }
  111.    
  112.     fcard_kbd_flush();
  113.     fcard_lcd_clear();
  114.     sprintf(line,"请输入管理员密码");
  115.     fcard_lcd_printh1(line);
  116.     memset(showinfo,0x00,sizeof(showinfo));
  117.     memset(password,0x00,sizeof(password));
  118.     length = 0;
  119.     for (timeout=15000;timeout>0;){
  120.         if (length>=8)break;
  121.         key = fcard_kbd_peek();
  122.         if (key==0){
  123.             mdelay(20);
  124.             timeout -= 20;
  125.             continue;
  126.         }
  127.         if (key>='0'&&key<='9'){
  128.             showinfo[length]='*';
  129.             password[length++]=key;
  130.             fcard_lcd_printh2(showinfo);
  131.             fcard_lcd_printh3(password);
  132.         }
  133.         if (key==27){
  134.             if (length>0){
  135.                 showinfo[--length]=' ';
  136.                 password[length]=' ';
  137.                 //fcard_kbd_flush();
  138.                 //fcard_lcd_clear();                        
  139.                 fcard_lcd_printh2(showinfo);
  140.                 fcard_lcd_printh3(password);  
  141.             }else{
  142.                 break;
  143.             }                 
  144.         }
  145.         if (key==13){
  146.             break;
  147.         }
  148.     }
  149.     if (strlen(password)<=0){
  150.         //timeout -= 20;
  151.         //continue;
  152.     }else if (strncmp(password,administratorPassword,8)==0){
  153.         main_setting();
  154.     }else{
  155.         sprintf(line,"  输入密码错误  ");
  156.         fcard_lcd_printh4(line);
  157.     }   
  158.     return 0;
  159. }

  160. int main(void){
  161.     struct tm  itm;
  162.     unsigned char  line[32];
  163.     unsigned char  txbuff[128];
  164.     char        username[20];
  165.     int key,i;
  166.     int length;
  167.     broadcastinfo_t  info;
  168.    
  169.     fcard_sysclk_init();
  170.     fcard_nvic_init();
  171.     fcard_leds_init();
  172.     fcard_beep_init();
  173.     fcard_flash_init();
  174.     fcard_kbd_init();
  175.     fcard_lcd_init();
  176.     fcard_rtc_init();
  177.     fcard_uart3_init(BAUD_115200,8,0,1);
  178.     //formatSystemZone();
  179.     initFingerFeatureZone();
  180.     if (!hasFingerBackgroundPicture()){
  181.         saveFingerBackgroundPictureToFlash();
  182.     }

  183.     fcard_kbd_flush();
  184.     fcard_lcd_clear();
  185.     zigbeeProtocolProcessInit();
  186.     memset(username,0x00,sizeof(username));
  187.     for (;;){
  188.         fcard_lcd_clear();
  189.         fcard_get_datetime(&itm);
  190.         sprintf(line,"仁石科技有限公司");
  191.         fcard_lcd_printh1(line);         
  192.         sprintf(line,"   %04d-%02d-%02d   ", itm.tm_year,itm.tm_mon,itm.tm_mday);
  193.         fcard_lcd_printh2(line);   
  194.         sprintf(line,"    %02d:%02d:%02d    ", itm.tm_hour,itm.tm_min,itm.tm_sec);
  195.         fcard_lcd_printh3(line);
  196.         if (strlen(username)>0){
  197.             fcard_lcd_printh4(username);
  198.             fcard_beep_off();
  199.         }else{
  200.              if (hasLocationInformation()){
  201.                 int istr=strlen(locationInformation)/2;
  202.                 if (istr>=8){
  203.                     istr=0;
  204.                 }else{
  205.                     istr=(8-istr)/2;
  206.                 }
  207.                 for (i=0;i<istr*2;i++){
  208.                     username[i]=' ';
  209.                 }
  210.                 sprintf(&username[istr*2],"%s",locationInformation);
  211.                 fcard_lcd_printh4(username);
  212.                 fcard_beep_off();
  213.             }      
  214.         }

  215.         memset(&info,0x00,sizeof(info));
  216.         if (hasLocationInformation()){
  217.             snprintf(info.location,96,"%s",locationInformation);        
  218.         }
  219.         snprintf(info.time,32,"%04d-%02d-%02d %02d:%02d:%02d",itm.tm_year,itm.tm_mon,itm.tm_mday,itm.tm_hour,itm.tm_min,itm.tm_sec);     
  220.    
  221.         length = depMakeFrame(txbuff,0xFF,0x20,(unsigned char*)&info,sizeof(info));
  222.         if (zigbeeProtocolTalkToTarget(txbuff,length,line,22)==22){
  223.             if (line[0]==0xAA && line[21]==0x55 && line[1]==0x00){
  224.                     snprintf(username,16,"%s",&line[4]);
  225.                     fcard_beep_on();
  226.             }else{
  227.                     memset(username,0x00,sizeof(username));               
  228.             }
  229.         }else{
  230.             memset(username,0x00,sizeof(username));
  231.         }
  232.       
  233.         key = fcard_kbd_peek();
  234.         if (key==13){
  235.             main_login();
  236.         }
  237.     }
  238.     zigbeeProtocolProcessExit();
  239.     return 0;
  240. }
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表