LPC2148 – RFID Interfacing

This article is a continuation of the series of tutorials on the LPC2148 Microcontroller (ARM7). The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the GSM module with LPC2148 (ARM7).  In this tutorial, we are going to see RFID Interfacing with LPC2148. So in this tutorial, we will use EM18 RFID Reader Module. Because it will give the data via serial communication. Before interfacing please have a look at How Does RFID Works?

Suggestion to read

Why EM18?

EM-18 RFID reader is one of the commonly used RFID readers to read 125KHz tags. It features low cost, low power consumption, small form factor, and easy to use. It provides both UART and Wiegand26 output formats. It can be directly interfaced with microcontrollers using UART and with PC using an RS232 converter. Just power the module, and it will read any RFID card within range.

It will output the card’s ID in a serial string, which can easily be read by any microcontroller. The spacing on the pins is 2.54 mm, which means the module will directly fit on a breadboard.

Features

  • 5V supply
  • 125kHz read frequency
  • EM4001 64-bit RFID tag compatible
  • 9600bps TTL and RS232 output
  • Magnetic stripe emulation output
  • 100mm read range

RFID Interfacing With LPC2148

Component Required

  • EM18 Module
  • LCD Module
  • LPC2148 Development Board

Circuit Diagram

The full circuit diagram for interfacing the RFID module to LPC2148 is shown below. The unique ID code in the RFID card is read by the circuit and displayed on the 16×2 LCD display.
LCD:

RS – P1.16
RW – P1.17
EN – P1.18
Data Lines – P1.24 – P1.31

EM18 (RFID Reader):

RFID Reader TX – P0.1

lpc2148 rfid interfacing

Programming

Programming Steps

  • Initialize the LCD
  • Initialize the Serial Communication (9600 BaudRate)
  • Receive the 12 bytes and display them into the LCD Display

In this tutorial, I’ve displayed the 12 bytes id. But you can play with that bytes. For example, You can verify the number. If it is matching you can run the motor.

Code

In this code, I’m reading the unique id number using the polling method and printing that to LCD. You can also try using a serial interrupt. You can download the project here.

#include <lpc214x.h>
#define bit(x) (1<<x)

void lcd_init(void);
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void lcd_delay(void);

void ser_init(void);
void tx(unsigned char c);
unsigned char rx(void);
void tx_string(unsigned char *s);

int main()
{
	int i;
	unsigned char id[12];
	
	IO1DIR = 0xFFFFFFFF;
	ser_init();
	lcd_init();
	cmd(0x80);
	show("<<SHOW UR CARD>>");
	cmd(0xc0);
	for(i=0; i<12; i++) {
		id[i]=rx();
		dat(id[i]);
	} 	
	while(1);
}
void lcd_init()
{
	cmd(0x38);
	cmd(0x0e);
	cmd(0x01);
	cmd(0x06);
	cmd(0x0c);
	cmd(0x80);
}

void cmd(unsigned char a)
{
	IO1CLR=0xFF070000;
	IO1SET=(a<<24);
	IO1CLR=bit(16);				//rs=0
	IO1CLR=bit(17);				//rw=0
	IO1SET=bit(18);			  	//en=1
	lcd_delay();
	IO1CLR=bit(18);			   	//en=0
}

void dat(unsigned char b)
{
	IO1CLR=0xFF070000;
	IO1SET=(b<<24);
	IO1SET=bit(16);				//rs=1
	IO1CLR=bit(17);				//rw=0
	IO1SET=bit(18);			   	//en=1
	lcd_delay();
	IO1CLR=bit(18);			   	//en=0
}

void show(unsigned char *s)
{
	while(*s)
	{
		dat(*s++);
	}
}

void lcd_delay()
{
	unsigned int i;
	for(i=0;i<=3000;i++);
}
void ser_init()
{
	VPBDIV=0x02;							//PCLK = 30MHz
	PINSEL0|=0x05;
	U0LCR=0x83;
	U0DLL=195;
	U0DLM=0;
	U0LCR=0x03;
	U0TER=(1<<7);
}

void tx(unsigned char c)
{
	U0THR=c;
	while((U0LSR&(1<<5))==0);
}

void tx_string(unsigned char *s)
{
	while(*s) {
	tx(*s++);
	}
}

unsigned char rx()
{
	while((U0LSR&(1<<0))==0);
	return U0RBR;
}

You can try this code with hardware.

In our next tutorial, we will see how to interface the Ultrasonic sensor with LPC2148 (ARM7). If you want to use FreeRTOS on LPC2148, then please refer FreeRTOS series.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
STM32F7 Bootloader TutorialsRaspberry PI Pico Tutorials
STM32F103 Bootloader TutorialsRT-Thread RTOS Tutorials
Zephyr RTOS Tutorials - STM32Zephyr RTOS Tutorials - ESP32
AUTOSAR TutorialsUDS Protocol Tutorials
Product ReviewsSTM32 MikroC Bootloader Tutorial
VHDL Tutorials

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Table of Contents