Rfid reader board

Post your reviews about the boards you have got.
Post Reply
Author
Message
Noble
Posts: 5
Joined: 17 Sep 2014 09:06

Rfid reader board

#1 Post by Noble » 27 Dec 2015 15:46

hi, tried the rfid reader example on easy pic v7 but it did not work. I wanted the card ID to b displayed on an lcd when the reader detects the card but was having issues. I jumpered the lcd to portD so as to use portb for the rfid reader.the lcd worked quite well when i tested the lcd example on it with the modified lcd pin definitions. I copied this same pin definition to the rfid example and tested,nothing was displayed Am sure maybe I didn't send the correct array that stores the Card ID to the lcd or maybe I didn't keep it in the right place in the program , please help. Thanks

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: Rfid reader board

#2 Post by aleksa.jovanovic » 28 Dec 2015 10:06

The card id array is much larger then the LCD can show at once.
Can I have a look at your modified example?

Best regards,
Aleksa

Noble
Posts: 5
Joined: 17 Sep 2014 09:06

Re: Rfid reader board

#3 Post by Noble » 28 Dec 2015 10:35

this is modified example.

/*
* Project name
RFiD (Displaying CRC check of RFid card via Usart)
* Copyright
(c) mikroElektronika, 2010.
* Revision History
20091220:
- initial release;
20101021:
- added active comments, sbit approach, code reorganized...
* Description
The code demonstrates using two external interrupts to read data sent
by EM4095 chip (clock - RDY/CLK; data - OUT).
Upon correct identification of the card, results are displayed via USART
along with the card specific number.
* Test configuration:
MCU: PIC18F4520
http://ww1.microchip.com/downloads/en/D ... 39631E.pdf
Dev.Board: EasyPIC6
http://www.mikroe.com/eng/products/view ... nt-system/
Oscillator: HS-PLL, 32.0000 MHz
Ext. Modules: mE RFid Reader Board
ac:RFid_reader
http://www.mikroe.com/eng/products/view ... der-board/
SW: mikroC PRO for PIC
http://www.mikroe.com/eng/products/view ... o-for-pic/
* NOTES:
- mE RFid Reader Board should be connected to PORTB
- Make sure you turn on the apropriate switches to enable USART communication (board specific)
- Upon correct CRC check program will send "CRC CHECK OK!" via USART
- Usage of P18 family of MCUs and clock setting >= 32 MHz is recommended when working with RFid Reader Board
*/

// Lcd module connections
sbit LCD_RS at LATD4_bit;
sbit LCD_EN at LATD5_bit;
sbit LCD_D4 at LATD0_bit;
sbit LCD_D5 at LATD1_bit;
sbit LCD_D6 at LATD2_bit;
sbit LCD_D7 at LATD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End Lcd module connections


sbit OUT at RB0_bit;
sbit RDY_CLK at RB1_bit;
sbit SHD at RB2_bit;
sbit MOD at RB3_bit;

sbit OUT_Direction at TRISB0_bit;
sbit RDY_CLK_Direction at TRISB1_bit;
sbit SHD_Direction at TRISB2_bit;
sbit MOD_Direction at TRISB3_bit;

unsigned short sync_flag, // in the sync routine if this flag is set
one_seq, // counts the number of 'logic one' in series
data_in, // gets data bit depending on data_in_1st and data_in_2nd
cnt, // interrupt counter
cnt1, cnt2; // auxiliary counters
unsigned short data_index; // marks position in data arrey
char i;
char _data[256];
char data_valid[64];
char bad_synch; // variable for detecting bad synchronization

void Interrupt() {

// This is external INT1 interrupt (for sync and sample)
// it is enabled until we get 128 data bits
if (INT1IF_bit && INT1IE_bit) {
cnt++; // count interrupts on INT1 pin (RB1)
INT1IF_bit = 0;
}

// This is external INT0 interrupt (for sync start)
// - once we get falling edge on RB0 we are disabling INT0 interrupt
else if (INT0IF_bit && INT0IE_bit) {
cnt = 0;
sync_flag = 1;
INT0IF_bit = 0;
INT0IE_bit = 0;
INT1IF_bit = 0;
INT1IE_bit = 1;
}
}


char CRC_Check(char *bit_array) {

char row_count, row_bit, column_count;
char row_sum, column_sum;
char row_check[5];
char column_check[11];

// row parity check:
row_count = 9; // count rows
while (row_count < 59) {
column_count = 0; // count columns
while (column_count < 5) {
row_check[column_count] = bit_array[row_count+column_count];
column_count++;
}
row_bit = 0; // count row bits
row_sum = 0;
while (row_bit < 4) {
row_sum = row_sum + row_check[row_bit];
row_bit++;
}

if (row_sum.B0 != row_check[4].B0) {
return 0;
}
row_count = row_count + 5;
}
// end row parity check

// column parity check
column_count = 9; // count columns
while (column_count < 13) {
row_bit = 0; // count column bits
row_count = 0; // count rows
while (row_bit < 11) {
column_check[row_bit] = bit_array[column_count+row_count];
row_bit++;
row_count = row_count + 5;
}

row_bit = 0; // count column bits
column_sum = 0;
while (row_bit < 10) {
column_sum = column_sum + column_check[row_bit];
row_bit++;
}

if (column_sum.B0 != column_check[10].B0) {
return 0;
}
column_count++;
}
// end column parity check
if (bit_array[63] == 1) {
return 0;
}
return 1;
}

// main program
void main() {
ANSELB = 0; // Configure AN pins as digital I/O
ANSELD = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;


OUT_Direction = 1;
RDY_CLK_Direction = 1;
SHD_Direction = 0;
MOD_Direction = 0;

SHD = 0;
MOD = 0;

UART1_Init(19200); // Initialise USART communication
Delay_ms(100);

sync_flag = 0; // sync_flag is set when falling edge on RB0 is detected
one_seq = 0; // counts the number of 'logic one' in series
data_in = 0; // gets data bit
data_index = 0; // marks position in data arrey
cnt = 0; // interrupt counter
cnt1 = 0; // auxiliary counter
cnt2 = 0; // auxiliary counter

// setup interrupts
INTEDG0_bit = 0; // Interrupt on falling edge on RB0
INTEDG1_bit = 1; // Interrupt on rising edge on RB1
INT0IF_bit = 0; // Clear INT0IF
INT1IF_bit = 0; // Clear INT1IF

INT0IE_bit = 0; // turn OFF interrupt on INT0
INT1IE_bit = 0; // turn OFF interrupt on INT1
GIE_bit = 1; // enable GIE


while (1) {
bad_synch = 0; // set bad synchronization variable to zero
cnt = 0; // reseting interrupt counter
sync_flag = 0; // reseting sync flag
INT1IF_bit = 0;
INT1IE_bit = 0; // disable external interrupt on RB1 (for sync and sample)
INT0IF_bit = 0;
INT0IE_bit = 1; // enable external interrupt on RB0 (start sync procedure)

while (sync_flag == 0) { // waiting for falling edge on RB0
asm nop
}

while (cnt != 16) { // waiting 16 clocks on RB1 (positioning for sampling)
asm nop
}

cnt = 0;
_data[0] = OUT & 1;

for (data_index = 1; data_index != 0; data_index++) { // getting 128 bits of data from RB0
while (cnt != 32) { // getting bit from RB0 every 32 clocks on RB1
asm nop
}
cnt = 0; // reseting interrupt counter
_data[data_index] = OUT & 1; // geting bit
if(data_index & 1)
if (!(_data[data_index] ^ _data[data_index-1]))
{
bad_synch = 1;
break; //bad synchronisation
}
}

INT1IE_bit = 0; // disable external interrupt on RB1 (for sync and sample)
if (bad_synch)
continue; // try again
cnt1 = 0;
one_seq = 0;
for(cnt1 = 0; cnt1 <= 127; cnt1++) { // we are counting 'logic one' in the data array
if (_data[cnt1 << 1] == 1) {
one_seq++;
}
else {
one_seq = 0;
}

if (one_seq == 9) { // if we get 9 'logic one' we break from the loop
break;
}
} // (the position of the last 'logic one' is in the cnt1)
if ((one_seq == 9) && (cnt1 < 73)) { // if we got 9 'logic one' before cnt1 position 73
// we write that data into data_valid array
data_valid[0] = 1; // (it has to be before cnt1 position 73 in order
data_valid[1] = 1; // to have all 64 bits available in data array)
data_valid[2] = 1;
data_valid[3] = 1;
data_valid[4] = 1;
data_valid[5] = 1;
data_valid[6] = 1;
data_valid[7] = 1;
data_valid[8] = 1;
for(cnt2 = 9; cnt2 <= 63; cnt2++) { // copying the rest of data from the data array into data_valid array
cnt1++;
data_valid[cnt2] = _data[cnt1 << 1];
}
if (CRC_Check(data_valid) == 1) { // if data in data_valid array pass the CRC check

UART1_Write_Text("CRC CHECK OK!"); // Writing of the CRC Check confirmation through USART communication
UART1_Write(13); // Cariage return (view ASCII chart)
UART1_Write(10); // Line Feed (view ASCII chart)



for (i = 0; i <= 64; i++){ // This part of the code
// dislays the number of the specific RfID CARD
if (data_valid == 0) {
Uart1_Write('0');
}
else {
Uart1_Write('1'); // at the end of this for loop you will get a string of "0" and "1"
}
} // specific to a single RfID CARD

Lcd_Chr(1, 10, data_valid); // this is the value(card ID) i wanted to display on the lcd

UART1_Write(13); // Cariage return (view ASCII chart)
UART1_Write(10); // Line Feed (view ASCII chart)
Delay_ms(500);

}
}

}
}

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: Rfid reader board

#4 Post by aleksa.jovanovic » 29 Dec 2015 11:58

You need to store the entire string of card id to a variable, and then, depending on your screen size use the Lcd_Out function to display chunks of the data.

Best regards,
Aleksa

Noble
Posts: 5
Joined: 17 Sep 2014 09:06

Re: Rfid reader board

#5 Post by Noble » 29 Dec 2015 22:29

Sorry, is the card ID not stored in the array variable - data_valid? If I send the array to the lcd, won't it display?

Noble
Posts: 5
Joined: 17 Sep 2014 09:06

Re: Rfid reader board

#6 Post by Noble » 30 Dec 2015 08:48

i have tried testing the rfid examples alone without including the lcd pin definition. i cant tell if the card is working because there's no beep or an indication LED when i bring the tag to the rfid reader board. its only the power LED that is ON . Please i really need your help am using it in my final year project. i want the ID to be displayed on an LCD, in order to know that the reader and tag is working very well. thanks

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: Rfid reader board

#7 Post by aleksa.jovanovic » 30 Dec 2015 11:31

I am assuming that you are using the 2x16 character LCD.
Because the string is 64 characters long, you need to make a function that can display it all on the smaller LCD.

My suggestion is make a for loop which fills the 32 places on the LCD, then makes a delay of a couple of seconds, then displays the second 32 characters of the ID.
You can also do something more interesting, like saving the card id in your code,
then depending on which card you bring to the reader it compares the id to the predefined ids and displays some text you predefined.

Best regards,
Aleksa

Noble
Posts: 5
Joined: 17 Sep 2014 09:06

Re: Rfid reader board

#8 Post by Noble » 30 Dec 2015 12:26

i just started learning programming microcontrollers using C (MikroC). am used to graphical programming language for microcontrollers (flowcode), my friend adviced me to buy the products for my final year project from mikroe since its much cheaper, comes with code examples , and they provide support for their products. please can you help me out with the code for the function to display the ID. would be very grateful,thanks

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: Rfid reader board

#9 Post by Aleksandar.Mitrovic » 05 Jan 2016 10:56

Hi Noble,

I believe that my colleague Aleksa already explained how you can display your ID on the LCD2x16, and suggested to you couple of methods.

How do you want to check your ID?

Best regards,
Aleksandar

Post Reply

Return to “Review”