zigbee吧 关注:5,015贴子:18,675
  • 0回复贴,共1

RFID卡读取

只看楼主收藏回复

#include "variable.h"
#include"delay.h"
#include "UART.h"
#include "IC_w_r.h"
void InitIO()
{
CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振
while(CLKCONSTA & 0x40); //等待晶振稳定为32M
CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ
UartInitial();
// IC_SDA P2_0
P2DIR |= 1<<0;
P2INP |= 1<<0;
P2SEL &= ~(1<<0);
// IC_SCK P0_7
P0DIR |= 1<<7;
P0INP |= 1<<7;
P0SEL &= ~(1<<7);
// IC_MOSI P0_6
P0DIR |= 1<<6;
P0INP |= 1<<6;
P0SEL &= ~(1<<6);
// IC_MISO P0_5
P0DIR |= 1<<5;
P0INP |= 1<<5;
P0SEL &= ~(1<<5);
// IC_RST P0_4
P0DIR &= ~(1<<4);
P0INP &= ~(1<<4);
P0SEL &= ~(1<<4);
IC_SCK = 1;
IC_SDA = 1;
}
void IC_test()
{
uchar ucTagType[4];
uchar find=0xaa;
uchar ret;
while(1)
{
//16进制转ASC码
char i;
char Card_Id[8]; //存放32位卡号
uchar asc_16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
ret = PcdRequest(0x52,ucTagType);//寻卡
if(ret != 0x26)
ret = PcdRequest(0x52,ucTagType);
if(ret != 0x26)
find = 0xaa;
if((ret == 0x26)&&(find == 0xaa))
{
if(PcdAnticoll(ucTagType) == 0x26);//防冲撞
{
UartSend_String("The Card ID is: ",16);
//16进制转ASC码
for(i=0;i<4;i++)
{
Card_Id[i*2]=asc_16[ucTagType[i]/16];
Card_Id[i*2+1]=asc_16[ucTagType[i]%16];
}
UartSend_String(Card_Id,8);
UartSend_String("\n",1);
find = 0x00;
}
}
}
}
void main()
{
InitIO();
PcdReset();
M500PcdConfigISOType('A');//设置工作方式
while(1)
{
IC_test(); //检测IC卡
}
}


IP属地:山东1楼2022-12-06 07:54回复