sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
void main()
{
unsigned char i, rfid[13];
//char String[8]= "B5:CF:79:23";
int abdo =54321;
int islam =12345;
int y;
Lcd_Init();
trisc.RC3=0;
portc.RC3=0;
portc.RC4=0;
trisc.RC4=0;
portc.RC5=0;
trisc.RC5=0; // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"RFID Tag Reader"); // Write text in first row
UART1_Init(9600); // Initialize UART, 9600 baud rate
rfid[12] = '\0'; // String Terminating Character
while(1) // Infinite Loop
{
if (UART1_Data_Ready()) // If UART Data Ready
{
for(i=0;i<5;) // To Read 5 characters
{
if (UART1_Data_Ready())
{
rfid[i] = UART1_Read();
i++;
}
}
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1," << Welcome >>"); // Write text in first row
Lcd_Cmd(_LCD_SECOND_ROW);
Lcd_Out_cp(" Card ID:");
for(i=0;i<5;)
{
Lcd_Chr_Cp(rfid[i]);
UART1_Write(rfid[i]);
i++;
delay_us(1000);
}
y = atoi(&rfid);
if( islam == y )
{
Lcd_Out(1,1," Welcome ISlAM ");
portc.RC5 =0;
portc.RC3 =1;
if(portc.RC3 =1)
{
portc.RC4 =1;
delay_ms(200);
portc.RC4 =0;
}
}
else if( abdo == y )
{
Lcd_Out(1,1," Welcome ABDO ");
portc.RC5 =0;
portc.RC3 =1;
if(portc.RC3 =1)
{
portc.RC4 =1;
delay_ms(200);
portc.RC4 =0;
}
}
else
{
portc.RC3 =0;
portc.RC4 =0;
portc.RC5 =1;
if(portc.RC5 =1)
{
portc.RC4 =1;
delay_ms(600);
portc.RC4 =0;
delay_ms(200);
}
Lcd_Out(1,1,"Check Your Card");
}
delay_ms(2000);
}
else
{
portc.RC3 =0;
portc.RC4 =0;
portc.RC5 =1;
Lcd_Out(1,1," << Welcome >> ");
Lcd_Cmd(_LCD_SECOND_ROW);
Lcd_Out(2,2,"Press Your Card ");
}
}
}
thank you sir you helped me a lot of time , I appreciate your effort.B5:CF:79:23 is a 64-bit number so you either have to break it into four 8-bit values and compare them in turn or alternatively convert them to text characters and compare them as a character string. Converting to characters is probably the easiest to maintain because you can directly read them and copy them into your program.
Otherwise you would have to convert a number like 123456 to 0x0001E240 which is harder to work with.
Brian.
HexToInt
thank you for helping ,Firstly, an 'int' will probably only hold 16-bits so it wouldn't be big enough to hold all the digits anyway.
From your schematic I assume the bytes (8-bits) from the RFID reader are arriving at the serial port. The USART only has an 8-bit receive register so they are arriving one byte at a time. I can't find a data sheet for the RDM6300 to see the data format but what I would suggest you do is write a short program to simply display the bytes on the LCD so you can see what they are. They may already be ASCII characters or you may have to convert them if they are binary but once you see what the RFID module is producing it should be easy to see how to store and compare them. Try it and let me know what the actual data from the module is.
Brian.
hi Mr Brian.Firstly, an 'int' will probably only hold 16-bits so it wouldn't be big enough to hold all the digits anyway.
From your schematic I assume the bytes (8-bits) from the RFID reader are arriving at the serial port. The USART only has an 8-bit receive register so they are arriving one byte at a time. I can't find a data sheet for the RDM6300 to see the data format but what I would suggest you do is write a short program to simply display the bytes on the LCD so you can see what they are. They may already be ASCII characters or you may have to convert them if they are binary but once you see what the RFID module is producing it should be easy to see how to store and compare them. Try it and let me know what the actual data from the module is.
Brian.
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
unsigned char byte;
void main()
{
char i, rfid[13];
int y;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,"RFID Tag Reader"); // Write text in first row
UART1_Init(9600); // Initialize UART, 9600 baud rate
rfid[12] = '\0'; // String Terminating Character
while(1) // Infinite Loop
{
if(UART1_Data_Ready()) // If UART Data Ready
{
for(i=0;i<12;) // To Read 12 characters
{
if(UART1_Data_Ready())
{
rfid[i] = UART1_Read();
i++;
}
}
lcd_cmd(_LCD_SECOND_ROW);
lcd_out_cp("Tag:");
for(i=3;i<12;)
{
lcd_chr_cp(rfid[i]);
UART1_Write(rfid[i]);
i++;
}
delay_ms(1000);
}
}
}.
thank you for helping ,I had no luck finding a definitive specification for that module but it seems it outputs 14 bytes, the first being 0x02, then 10 characters of ID, then a two character CRC and finally a 0x03 terminator.
Your code doesn't search for the 0x02 so if a byte is missed, all subsequent card reads will be wrong. A better strategy is to look for 0x02 then reset the index so you always 'frame' the data even if there is an error. Characters 11 and 12 are not part of the ID although they should always be the same for a particular tag.
From what I can see, the reader is already returning hex data as ASCII characters so you should be able to concatenate them to a character string or use 'sprintf' if you capture them into an array first.
See what happens if you modify the code in post #5 like this: ( MikroC doesn't run on my OS so I can't test it for you!)
1. allocate a character string something like this - "char TagID[15] = {0};"
2. read the UART until 0x02 is seen then initialize 'i' to zero.
3. read the next 10 characters to TagID[i++];
4. make TagID = 0 so it adds a terminator to the end of the string.
5. print TagID to the LCD.
Although 'TagID' looks like an array, the command to print it to the LCD should think its a printable string as it only contains ASCII characters and it has a zero terminator.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?