Author Topic: use 8051 send data to trigger rfid read data  (Read 6209 times)

geroli

  • Guest
use 8051 send data to trigger rfid read data
« on: November 19, 2011, 10:50:58 am »
I\'m interfacing the 8051 microcontroller with PSR-MF80 Reader/Writer Module.  I\'m using RS232 to communicate between the reader and microcontroller. I use the COM PORT HEX TOOLS to get the request and the read hex code, but I can\'t get the data from RFID. I get the hex code is

rfid request:      AA BB 06 00 00 00 01 01 07 07
rfid read:      AA BB 0D 00 00 00 07 02 60 04 FF FF FF FF FF FF 61


So, i write a function to send the hex code to RFID, and i am use the max232.

Here is the function :
void request() {

 SBUF = 0xAA;
 SBUF = 0xBB;
 SBUF = 0x06;
 SBUF = 0x00;
 SBUF = 0x00;
 SBUF = 0x00;
 SBUF = 0x01;
 SBUF = 0x01;
 SBUF = 0x07;
 SBUF = 0x07;
 while(TI == 0);
 TI = 0;
 delay(10);
}
void read(){
 SBUF = 0xAA;
 SBUF = 0xBB;
 SBUF = 0x0D;
 SBUF = 0x00;
 SBUF = 0x00;
 SBUF = 0x00;
 SBUF = 0x07;
 SBUF = 0x02;
 SBUF = 0x60;
 SBUF = 0x04;
 SBUF = 0xFF;
 SBUF = 0xFF;
 SBUF = 0xFF;
 SBUF = 0xFF;
 SBUF = 0xFF;
 SBUF = 0xFF;
 SBUF = 0x61;
 while(TI == 0);
 TI = 0;
 delay(10);
}
void recieve()     //Function to recieve data serialy from RS232
{
    unsigned char k;
     for(k=0;k<12;k++)
     {
         while(RI==0);
          card_id[k]=SBUF;
          RI=0;
    }
}

Is that the function something wrong to make me can\'t get the data from RFID?

Thanks

vitaliy

  • Full Member
  • ***
  • Posts: 30
    • View Profile
Re: use 8051 send data to trigger rfid read data
« Reply #1 on: November 19, 2011, 03:40:13 pm »
add while(TI == 0) after any write to SBUF

geroli

  • Guest
Re: use 8051 send data to trigger rfid read data
« Reply #2 on: November 19, 2011, 08:21:09 pm »
Thanks

So the function so be:
void request() {

SBUF = 0xAA;
while(TI == 0);
SBUF = 0xBB;
while(TI == 0);
SBUF = 0x06;
while(TI == 0);
SBUF = 0x00;
while(TI == 0);
SBUF = 0x00;
while(TI == 0);
SBUF = 0x00;
while(TI == 0);
SBUF = 0x01;
while(TI == 0);
SBUF = 0x01;
while(TI == 0);
SBUF = 0x07;
while(TI == 0);
SBUF = 0x07;
while(TI == 0);
TI = 0;
delay(10);
}

Look like this? And I will try that in tomorrow.
Thanks

geroli

  • Guest
Re: use 8051 send data to trigger rfid read data
« Reply #3 on: November 21, 2011, 02:24:09 am »
hey,now have the question.

i have already to add the while(TI == 0) after any write to SBUF.
but still can\'t get the data from rfid and show on the lcd display. The lcd is can display the value,so is that my main function have the error?

here is a main function and the LCD function:

void lcd_command(unsigned char comm)   //Lcd command funtion
{
     lcd_data_pin=comm;
     en=1;
     rs=0;
     rw=0;
     delay(1);
     en=0;
}

void lcd_data(unsigned char disp)  //Lcd data function
{
     lcd_data_pin=disp;
     en=1;
     rs=1;
     rw=0;
     delay(1);
     en=0;
}

lcd_string(unsigned char *disp)     //Function to send string
{
     int x;
     for(x=0;disp
  • !=0;x++)

    {
         lcd_data(disp
  • );

    }
}
void lcd_ini()                  //Function to initialize the LCD
{
    lcd_command(0x38);         
    delay(5);
    lcd_command(0x0F);       
    delay(5);
    lcd_command(0x80);
    delay(5);
}
void main()
 {
  int i;
  TMOD = 0x20;               
  TH1 = 0xFD;
  SCON = 0x50;                              
  TR1 = 1;                   
  lcd_ini();
  lcd_command(0x81);       
  lcd_string("unique card id:");
    delay(200);      
    while(1)
    {   
    request();
    read();
    recieve();
    lcd_command(0xC1);      
         for(i=0;i<12;i++)
         {
              lcd_data(card_id);
          }
      }
}



Is that anything error on the main program?
Thanks

vitaliy

  • Full Member
  • ***
  • Posts: 30
    • View Profile
Re: use 8051 send data to trigger rfid read data
« Reply #4 on: November 21, 2011, 12:26:23 pm »
You may install 8051 development system
There are many examples ( including LCD) under
C:\\bipom\\devtools\\MicroC\\Examples\\8051

geroli

  • Guest
Re: use 8051 send data to trigger rfid read data
« Reply #5 on: November 21, 2011, 11:32:11 pm »
Oh,i have look the serial part example,I used the Keil uVision4,but i can\'t find the header file on my complier,
i guess the gutch() and the putch() is useful.The lcd display is work sucessfully ,and i tried to remove the max232, now the RS232 directly connect to 8051,and the lcd will display the unknow characters, So,is that the RFID can receive the request and the read data? I don\'t know why the LCD display the  unknow characters.

Thanks