em4095是一款125k低频信号调制解调芯片,通过载波线圈与芯片通讯,搭配MCU读取em4095的曼彻斯特编码信号,即可读取芯片里的id号,本文主要介绍硬件原理图和曼彻斯特信号解码代码。
1,硬件原理图。
2,曼彻斯特解码代码
unsigned char rxBuf[4];
unsigned char rx_cnt = 0;
unsigned char tx_Buf[8] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x2A};
unsigned char tx_cnt = 0;
unsigned char tx_len;
unsigned char tx_fail[4] = {0x02, 0x01, 0xff, 0x03};
unsigned char id_read_success_flag = 0;
unsigned char RdREQ = 0, Rdcnt = Read_Try_Time;
unsigned long PreSN = 0;
unsigned char T0INT = 0;
unsigned long ledr_cnt= 0;
uchar rxdatabuf;
// typedef struct
// {
// unsigned char SN_array[4];
// unsigned char BCC;
// }TxMessage;
unsigned char SN_array[4];
unsigned char BCC;
//控制EM4095的引脚
sbit MOD = P1^0;
sbit SHD = P3^3;
sbit DEMOD_OUT = P3^2;
sbit RDY_CLK = P3^4;
sbit LED_G = P3^7;
sbit LED_R = P3^5;
//读取卡号,
ulong Read_Card()
{
uchar i=0;
uchar error;
uchar error_flag;
uchar row,col;
uchar row_parity;
uchar col_parity[5];
uchar _data;
ulong temp;
uchar timeout=0;
while(1)
{
if(timeout==100)return 0;
else timeout++;
error=0;
while(DEMOD_OUT==0)
{
if(error==TIME_OF)break;
else error++;
}
if(error==100)continue;
else error=0;
Delay384us();
if(DEMOD_OUT)
{
for(i=0;i<8;i++)
{
error=0;
while(DEMOD_OUT)
{
if(error==TIME_OF)
{
error_flag=1;
break;
}
else error++;
} .............................................
该RFID低频读卡器读卡距离最大可达到10几公分长,距离可调,成功运用多个项目,本人原创,如需完整代码,可与本人联系,扣:48445803.