RFID Interfacing With 8051 Microcontroller
RFID Interfacing With 8051 Microcontroller
Radio Frequency Identification (RFID) uses radio frequency to read information stored in a
RFID card or tag. In this project we are going to Interface EM-18 RFID reader with 8051
microcontroller and display RFID card number on 16*2 LCD display. This wireless RF
Identification is used in many systems like RFID Based Attendance System, security
systems, voting machines etc. This project will also serve as a proper interfacing of 16*2 LCD
with 8051 microcontroller.
Components Required:
• 8051 microcontroller
• RFID cards/tags
• Potentiometer
• Jumper wires
Circuit Diagram:
8051 Microcontroller:
8051 microcontroller is a 8 bit microcontroller which has 128 bytes of on chip RAM, 4K bytes
of on chip ROM, two timers, one serial port and four 8bit ports. 8052 microcontroller is an
extension of microcontroller. The table below shows the comparison of 8051 family members.
Timers 2 3
I/O pins 32 32
Serial port 1 1
Interrupt sources 6 8
16x2 LCD:
16*2 LCD is a widely used display for embedded applications. Here is the brief explanation about
pins and working of 16*2 LCD display. There are two very important registers inside the LCD.
They are data register and command register. Command register is used to send commands such
as clear display, cursor at home etc., data register is used to send data which is to be displayed on
16*2 LCD. Below table shows the pin description of 16*2 lcd.
1 Vss - Ground
6 E I/O Enable
16 K - Ground
Code(hex) Description
powered with 5V power supply. It provides serial output along with weigand output. The range is
around 8-12cm. serial communication parameters are 9600bps, 8 data bits, 1 stop bit. Its
applications include Authentication, e-toll road pricing, e-ticketing for public transport,
The output provided by EM-18 RFID reader is in 12 digit ASCII format. Out of 12 digits first 10
digits are card number and the last two digits are the XOR result of the card number. Last two
For example, card number is 0200107D0D62 read from the reader then the card number on the
02 – preamble
project. The code is split into small meaningful chunks and explained below.
For 16*2 LCD interfacing with 8051 microcontroller, we have to define pins on which 16*2
lcd is connected to 8051 microcontroller. RS pin of 16*2 lcd is connected to P3.7, RW pin of 16*2
lcd is connected to P3.6 and E pin of 16*2 lcd is connected to P3.5. Data pins are connected to
sbit rs=P3^7;
sbit rw=P3^6;
sbit en=P3^5;
Next we have to define some functions which are used in the program. Delay function is used to
create specified time delay. Cmdwrt function is used to send commands to 16*2 lcd
display. datawrt function is used to send data to 16*2 lcd display. Rxdata function is used to
In this part of the code we are going to configure 8051 microcontroller for serial
communication.
TMOD register is loaded with 0x20 for timer 1, mode 2 (auto reload). SCON register is loaded
with 0x50 for 8 data bits, 1 stop bit and receive enabled. TH1 register is loaded with 0xfd for baud
rate of 9600 bits per second. TR1=1 is used to start the timer.
TMOD= 0x20;
SCON=0x50;
TH1=0xfd;
TR1=1;
In this part of the code , we are sending commands to 16*2 lcd. Commands such as clear display ,
increment cursor , force the cursor to beginning of 1st line are sent to 16*2 lcd display one by one
for(i=0;i<5;i++)
{
cmdwrt (cmd[i]);
delay (1);
}
In this part of the code we are receiving the output of the EM-18 RFID reader through serial
interface of 8051 microcontroller and stored in a variable. Count is used to keep track of number
of bytes received. Once all the 12bytes of data are received, next we have to display it on 16*2 lcd
while(1)
{
count=0;
cmdwrt(0xC2);
while(count<12)
{
input[count]=rxdata();
count++;
}
for(i=0;i<12;i++)
{
datawrt(input[i]);
delay(1);
}
delay(100);
}
In this part of the code, we are sending commands to 16*2 lcd display. The command is copied
to port 1 of 8051 microcontroller. RS is made low for command write. RW is made low for write
operation. High to low pulse is applied on enable (E) pin to start command write operation.
In this part of the code , we are sending data to 16*2 lcd display. The data is copied to port 1 of
8051 microcontroller. RS is made high for command write . RW is made low for write operation.
High to low pulse is applied on enable(E) pin to start data write operation.
#include<reg51.h>
char ch;
void datawrt(unsigned char); //function for sending data to 16*2 lcd disp
lay
char rxdata(void); //function for receiving a characte
r through serial port of 8051
microcontroller
void main(void)
unsigned char i;
delay(1);
while(1)
count=0;
cmdwrt(0xC2);
delay(1);
delay(100);
en=1; //send a HIGH to LOW pulse on Enable(E) pin to start commandwrite operatio
n
delay(1);
en=0;
en=1; //send a HIGH to LOW pulse on Enable(E) pin to start datawrite operation
delay(1);
en=0;
}
char rxdata()