Interfacing EM-18 μRFID reader Wiegand26 with AT89S52
The communications protocol used on a Wiegand interface is known as the Wiegand protocol. The original Wiegand format had one parity bit, 8 bits of facility code, 16 bits of ID code, and a trailing parity bit for a total of 26 bits.
RFID is Radio Frequency Identification. An RFID reader is used to read RFID tags (which contain certain unique data stored in a chip). An RFID reader and an RFID tag, both have a coil surrounding them. When an RFID tag is shown near an RFID Reader, it collects the unique tag data (a combination of digits and characters) from the RFID tag. Power the μRFID reader; when an RFID tag is shown near the reader, electromagnetic induction will take place between the coils and this powers the chip inside tag. This chip will send data electromagnetically to the reader. The reader will receive this electromagnetically transferred data and output is in Wiegand format. We can collect the data by interfacing GPIO pins using AT89S52.
Wiegand26 communication can be enabled by giving low value to the SEL pin of the reader. The Wiegand interface uses two data transmission pins usually called DATA0 and DATA1, alternately labeled “D0″ and “D1″ or “Data Low” and “Data High”. When no data is being sent, both DATA0 and DATA1 are pulled up to the “high” voltage level usually, 3.3 – 5.5 VDC. When a 0 is sent the DATA0 wire is pulled to a low voltage while the DATA1 wire stays at a high voltage. When a 1 is sent the DATA1 wire is pulled to a low voltage while DATA0 stays at a high voltage.
The output in this mode is based on the table below-
Note:
E: Summed for even parity
O: Summed for odd parity
P: Parity(even or odd)
D: Data code for card
Interfacing μRFID reader Wiegand26 with AT89S52
A Wiegand format compatible output obtained by reading data pins connected directly to AT89S52. Make sure you connect Ground Pin of RFID reader to Ground Pin of AT89S52.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
/***************************************************************************************************** * Header file * *****************************************************************************************************/ #include<REGX52.H> #include<string.h> #define D0 P2_4 /* Weigand Data 0 */ #define D1 P2_3 /* Weigand Data 1 */ #define LCD_PORT P0 #define EN P1_0 #define RS P1_2 /***************************************************************************************************** * Function Decleration * *****************************************************************************************************/ void lcd_Initial(); void lcd_command(char value); void lcd_data(char value); void delay_us(int Delay); void delay_ms(unsigned long int Delay); void lcd_display(unsigned char locn,const char *dat); /***************************************************************************************************** * Variable Decleration * *****************************************************************************************************/ volatile char Card_ID[28]; volatile char Stored_ID[28]="00000100000010111011011110"; /* Tag ID */ volatile int i=0; /***************************************************************************************************** * Main code * *****************************************************************************************************/ void main() { P2=0xFF; lcd_Initial(); /* LCD Initialization */ lcd_display(0x80,"RFID Based Login"); /* Initial displays for login */ lcd_display(0xC0," System "); delay_ms(1000); lcd_display(0x80,"Use your Tag to "); /* Introduce the tag */ lcd_display(0xC0,"Login (Weigand) "); while(1) { while((D0&D1)); /* Waiting for Weigand Data */ if(D0==0 && D1==1)Card_ID[i]='0'; /* Storing Card no. to array */ if(D0==1 && D1==0)Card_ID[i]='1'; i++; /* Increment array index */ while(!(D0&D1)); if (i>=26) /* Card no Reception Complete */ { lcd_command(0x01); lcd_display(0x80,"Found "); delay_ms(500); lcd_command(0x80) for(i=0;i<=12;i++) lcd_data(Card_ID[i]); /* Displaying Weigand Data */ lcd_command(0xC0); for(i=13;i<=25;i++) lcd_data(Card_ID[i]); /* Displaying Weigand Data */ i=0; delay_ms(500); if(!strcmp(Card_ID,Stored_ID)) /* Comparing with Stored ID */ { lcd_command(0x01);delay_us(200); lcd_display(0x80,"Login Succeeded "); /* Login sucess */ delay_ms(1000); lcd_display(0x80,"Use your Tag to "); lcd_display(0xC0,"Login (Weigand) "); } else { lcd_command(0x01);delay_us(200); lcd_display(0x80,"Login Failed "); /* Login failed */ delay_ms(1000); lcd_display(0x80,"Use your Tag to "); lcd_display(0xC0,"Login (Weigand) "); } } } } /*===================================================================================================== * Function : lcd_Initial * Description : Function to Initialize LCD * Parameters : None =====================================================================================================*/ void lcd_Initial() { /* ---LCD Intialization Commands----- */ lcd_command(0x30); delay_us(5); /* LCD Specification Command */ lcd_command(0x30); delay_us(5); /* LCD Specification Command */ lcd_command(0x30); delay_us(5); /* LCD Specification Command */ lcd_command(0x38); /* LCD Double Line Display Command */ lcd_command(0x06); /* LCD Auto Increment Location Command */ lcd_command(0x0C); /* LCD Display ON Command */ lcd_command(0x01); delay_us(200); /* LCD Display Clear Cmdmand */ } /*===================================================================================================== * Function : lcd_command * Description : Function to send a command to LCD * Parameters : value, contains the command to be send =====================================================================================================*/ void lcd_command(char value) { RS=0; EN=1; LCD_PORT=value; delay_us(5); EN=0; } /*==================================================================================================== * Function : lcd_data * Description : Function to send a data to LCD * Parameters : value, contains the data to be send ====================================================================================================*/ void lcd_data(char value) { RS=1; EN=1; LCD_PORT=value; delay_us(5); EN=0; } /*=================================================================================================== * Function : delay_us * Description : Function to provide delayin us for LCD * Parameters : Delay, provide delay needed ====================================================================================================*/ void delay_us(int Delay) { while((--Delay)!=0); } /*=================================================================================================== * Function : delay_ms * Description : Function to provide delayin MS for LCD * Parameters : Delay, provide delay needed ====================================================================================================*/ void delay_ms(unsigned long int Delay) { Delay=Delay*15; while(--Delay!=0); } /*=================================================================================================== * Function : lcd_display * Description : Function to send a string of data in to LCD * Parameters : dat, contains the adddress of a string ====================================================================================================*/ void lcd_display(unsigned char locn,const char *dat) { lcd_command(locn); while(*dat!='\0') { lcd_data(*dat); dat++; } } /**************************************************************************************************** * END of Micro RFID Program * *****************************************************************************************************/ |
Resources
- Software
- Data sheet
- Example Projects
- Interfacing μRFID reader TTL protocol with AT89S52
- Interfacing μRFID reader Wiegand26 with AT89S52
- Interfacing μRFID reader TTL protocol with Arduino Uno
- Interfacing μRFID reader Wiegand26 with Arduino Uno
How to Buy?
- click here to buy µRFID Reader (EM-18 compatible)
- Click here to buy the rhydoLABZ AT89S52 Mni Development Board (Mini) V1.01
- Click here to buy the rhydoLABZ AT89S52 Development Board
- Click here to buy the rhydoLABZ ATMEL 89SXX ISP Programmer (RS232)
Support
Please share your ideas with us, visit our forum for discussion
Frequently Asked Questions(FAQ):
Q. What is the frequency range of μRFID reader?
Ans. The operating frequency range of RFID card is 125kHz.
Q. What are the protocols μRFID reader supported?
Ans. There are two supported protocols namely TTL Serial & Wiegand 26 as per the system design.