Overview of RFID
The EM18 RFID reader module is designed to read RFID cards operating at 125 kHz. When an RFID card comes within the reader’s range, the unique data encoded on the card is transmitted as an RF signal.
The reader then sends this data in byte format through its serial transmit pin. A microcontroller can read this data using USART communication, or it can be viewed on a PC terminal.
For more details on the EM18 RFID reader and its usage, refer to the RFID Reader EM18 topic in the sensors and modules section.
For information on USART in the PIC18F4550 and how to use it, refer to the USART in PIC18F4550 topic in the PIC inside section.
EM-18 RFID Reader Module
Connection Diagram of RFID EM-18 to PIC18F4550
RFID Reader Module Interfacing with PIC18F4550
Read RFID EM-18 using PIC18F4550
Read the RFID tags using the EM-18 RFID reader and send the data serially to the PIC18F4550 microcontroller. After receiving the 12-byte unique ID, display it on a 16×2 LCD.
RFID EM-18 Code for PIC18F4550
- Initialize USART Communication
Set up the USART module on the PIC18F4550 to enable serial communication. - Initialize LCD16x2 Display
Configure the LCD16x2 display for use, setting up the necessary pins and initializing it. - Wait for 12-Byte Data
Continuously monitor the USART receive buffer for incoming data from the EM-18 RFID reader. - Display Data on LCD
Once the 12-byte unique ID is received, display it on the LCD16x2 screen.
Program
/*
* 125 kHz RFID interface with PIC18F4550
* http://www.electronicwings.com
*
*/
#include <string.h>
#include <stdio.h>
#include <pic18f4550.h>
#include "Configuration_Header_File.h"
#include "LCD_16x2_8-bit_Header_File.h"
#include "USART_Header_File.h"
void main(void)
{
unsigned char i;
unsigned char ID[13];
OSCCON=0x72; /* select internal oscillator freq = 8 Mhz */
LCD_Init(); /* initialize LCD16x2 */
USART_Init(9600); /*initialize USART Communication with 9600 baud rate */
memset(ID,0,13);
LCD_String_xy(0,0,"RFID: ");
while(1)
{
for(i=0;i<12;i++)
{
ID[i]=USART_RxChar(); /* Receiving Data and Storing it in data_in */
}
LCD_String_xy(1,0,ID); /* Send Received data to LCD */
memset(ID,0,13);
}
}