PIC16F628A and Wiegand26 format

RFID reader, Reader/Writer, Tag.....

PIC16F628A and Wiegand26 format

Postby alex_86 » Sun Mar 06, 2011 11:10 pm

I am trying to incorporate the PR-8 code into my pic16f628a. Basically, instead of comparing the data and processing straight away, I intend to send the data via XBee to another section. I understand that using the wiegand26 format, the first 8 bit is the factory code and the last 16 bits with 1 start and 1 stop bit.

#include <stdio.h>
#include <htc.h>
#include <pic.h>
#include "usart.h"
#define data0 RA0 //data0(green wire) of RFID reader
#define data1 RA1 //data1(white wire) of RFID reader


//#define RX_PIN RB1 //Rx pin on PIC
//#define TX_PIN RB2 //Tx pin on PIC
#define _XTAL_FREQ 4000000

__CONFIG(0x3F30);


void main()
{
unsigned char i, a, b, database;
unsigned char data[26];
unsigned char convert1=0; //assign and clear convert1
unsigned int convert2=0; //assign and clear convert2
unsigned char mode=0; //assign and clear mode
unsigned char id1[2]={127,0}; //initialize 1st id1 in the array
unsigned int id2[2]={22449,0}; //initialize 1st id2 in the array
// data0 = 1;
// data1 = 1;
unsigned char input;

TRISB = 0x00;

//CMCON = 0x07 ; // Disable analog comparators
init_comms();

printf("Starting application\r\n");

while(1)
{

while(mode==0) //no RFID tag is placed on RFID reader
{
if((data0==0)||(data1==0))
mode=1; //RFID tag is placed on RFID reader (receive data stream from RFID tag)



}

//RFID tag is placed on RFID reader (RFID reader receive data stream from RFID tag)
while(mode==1)
{
if((data0==0)&&(data1==1)) //if data0 changes (data0 is active low)
{
data[i]=0; //save that the bit received is 0
while((data0==0)&&(data1==1)); //wait until data0 back to high logic
}
else if ((data0==1)&&(data1==0)) //if data1 changes (data1 is active low)
{
data[i]=1; //save that the bit received is 1
while((data0==1)&&(data1==0)); //wait until data1 back to high logic
}
//printf("Detected [%c].\r\n", data[i]);
i++; //i+1

while(i<26) //repeat the loop until all 26 bit data are sent (start from 0 to 25)
{
while((data0==1)&&(data1==1)); //wait while data0 and data1 remain at high logic level (no changes at data0 and data1)
if((data0==0)&&(data1==1)) //if data0 changes (data0 is active low)
{
data[i]=0; //save that the bit received is 0
while((data0==0)&&(data1==1)); //wait for data stream finish sending from RFID tag again (data0 or data1 will back to high logic)
}
else if ((data0==1)&&(data1==0)) //if data1 received is 0 (data1 is active low)
{
data[i]=1; //save that the bit received is 1
while((data0==1)&&(data1==0)); //wait for data stream finish sending from RFID tag again (data0 or data1 will back to high logic)
}
printf("Detected [%c]\r\n", data[i]);
i++; //i+1
}

mode=0; //after all data are sent, reset as no RFID tag is placed on RFID reader
//no data stream received from RFID tag
i=0; //clear i


for(i=0;i<8;i++) //loop for data[0]-data[7]
{
convert1=(convert1<<1)|data[i+1]; //shift current data and combine with previous data, store data in convert1 }
}
for(i=0;i<16;i++) //loop for data[8]-data[25]
{
convert2=(convert2<<1)|data[i+9]; //shift current data and combine with previous data, store data in convert2
}

for(b=0;b<2;b++) //compare with id[0] and id[1]
{
if((convert1==id1[b])&&(convert2==id2[b])) database=1; //id doesn't match, set database to 1
}

//putch(convert1);
//putch(convert2);


}
}
}
}

I tried to send the entire array through xbee but it doesnt work. Instead, I tried to send each of the 26bits 1 by 1 through XBee.
I am only getting FF, FD hex. (26 altogether)
Anything I'm doing wrong?
alex_86
Newbie
 
Posts: 13
Joined: Sun Jan 23, 2011 3:09 pm

Return to RFID

Who is online

Users browsing this forum: No registered users and 2 guests

cron