RFID Interfacing with 8051

 What is RFID?

Radio Frequency Identification (RFID) is a wireless Identification technology that uses radio waves to identify the presence of RFID tags.

The RFID system is based on two basic elements:-

1. RFID tag:-  The RFID tag  includes a microchip with a radio antenna mounted on a substrate that carries  12-byte  unique identification numbers.

2. RFID Module:-  The RFID Module is used to read unique IDs from the tags. whenever an RFID tag comes in range, the RFID reader reads its unique ID and Transmits it serially to the microcontroller.

Image of RFID Module:-


Task 1: To display an RFID Tag value on a Serial monitor.

Code:-

 #include<reg51.h>

#include "lcd.h"

#include "Uart.h"

char d[12];

unsigned int len=0;

void uart_begin();

void transfer(unsigned char a);

unsigned char receive();

void str(unsigned char b[]);

void restr();


void main ()

{

uart_begin();

str("Show RFID Tag :");

receive_string();

}

void uart_begin()

{

SCON=0x50;//usingg mode2 and enable port to high to receive dataa

TMOD=0x20;//to turn on timer 1 and mode2

TH1=0xFD;//baud rate 9600

TR1=1;// turn on timer1

}

void transfer(unsigned char a)

{

SBUF=a;// store the character in empty registerr

while(TI==0);//wait till flag turns to 1

TI=0;// clear again

}

unsigned char receive()

{

while(RI==0);

RI=0;

return SBUF;

}

void str(unsigned char b[])

{

unsigned int i;

for (i=0;b[i]!='\0';i++)

{

transfer(b[i]);

}

}

void recstr()

{

int i;

for(i=0;i<12;i++)

{

d[i]=receive();

}

}

Task 2:- Print The received message on 4 bit lcd

Code:-

#include<reg51.h>
#define datapins P2
sbit RS=P2^4;
sbit E=P2^5;
int len=0;
void delay(unsigned int t);
void lcd_begin();
void lcd_command(unsigned int cmd);
void lcd_message(unsigned char ch);
void lcd_string(unsigned char a[]);
void uart_begin();
unsigned char uart_receive();
void main()
{
lcd_begin();
uart_begin();
lcd_command(0x01);
while(1)
{
if (len<16)
{
for (len=0;len<16;len++)
{
lcd_message(uart_receive());

}
}
else
{    lcd_command(0xC0);
for(len=17;len<32;len++)
{
lcd_message(uart_receive());
}
lcd_command(0x01);
len=0;
}
}
}
void lcd_begin()
{
lcd_command(0x28);
lcd_command(0x01);
lcd_command(0x0F);
lcd_command(0x80);
}
void lcd_command(unsigned int cmd)
{
datapins=(cmd>>4);
RS=0;
E=1;
delay(1);
E=0;
datapins=cmd;
RS=0;
E=1;
delay(1);
E=0;
}
void lcd_message(unsigned char ch)
{
datapins=(ch>>4);
RS=1;
E=1;
delay(1);
E=0;
datapins=ch;                             
RS=1;
E=1;
delay(1);
E=0;
}
void lcd_string(unsigned char a[])
{
unsigned int i;
for(i=0;a[i]!='\0';i++)
{
lcd_message(a[i]);
}
}
void delay(unsigned int t)
{
int i,j;
for(i=0;i<=10*t;i++)
{
for(j=0;j<=1257;j++);
{
}
}
}
void uart_begin()
{
SCON=0x50;
TMOD=0x20;
TH1=0xFD;
TR1=1;
}
unsigned char uart_receive()
{
while (RI==0);
RI=0;
return SBUF;
}