打印

Soliddigi UHF RFID 读写器和Arduino Mege128通信程序

[复制链接]
2598|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wjscl520|  楼主 | 2011-10-14 16:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Soliddigi UHF RFID 读写器和Arduino Mege128通信程序

以下程序实现如下功能:

1.自动扫描标签(如果没有扫描到标签,向串口发“No Tag”信息)

2.如果扫描到标签就把标签id发到串口,暂停停扫描20秒。然后循环自步骤1;



/*
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// include the library code:
#include <LiquidCrystal.h>
#include <string.h>
#define BUFFSIZ 90

//RFID parser
char buffer_RFID[BUFFSIZ];
char buffidx_RFID;
char response_str[64];
char command_scantag[]={0x43,0x03,0x01};//const
char No_label[]={0x44,0x05,0x00,0x00,0x00};
char Receive_data[22];
unsigned char  incomingByte,incomingByte1,incomingByte2;
unsigned char parsed_okay=0;
unsigned char tag_found_number;
unsigned int bytecount=0;
unsigned char cnt,cnt1;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
  parsed_okay=0;
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Xbee UHFRFID Reader");
  Serial.begin(9600);
  Serial1.begin(115200);
  for(char i=0;i<3;i++)
       {
         Serial1.print(command_scantag);
       }
}

void loop()
{
  while(Serial1.available())
  {
    incomingByte2= incomingByte1;
    incomingByte1= incomingByte;
    incomingByte = Serial1.read();
    Receive_data[cnt]= incomingByte;
    //Serial.print(incomingByte);
    cnt++;
  }
  if(strcmp(Receive_data,No_label)==0)
  {
    Serial.println("No Tag");
    cnt=0;
  }
  if(cnt>=22 && cnt%22==0 && Receive_data[0]==0x44 && Receive_data[1]==0x16)
  {
    cnt1=cnt/22;
    for(unsigned char j=0;j<cnt1;j++)
    {
    //if(cnt==22)
    //{
      for(unsigned char i=j*22+10;i<j*22+22;i++)
      {
        Serial.print(Receive_data);
      }
    //}
    }
    for(unsigned char i=0;i<cnt;i++)
    {
      Receive_data=0x00;
    }
    cnt=0;
  }
  delay(500);
   for(char i=0;i<3;i++)
   {
     Serial1.print(command_scantag);
   }
   delay(500);
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

3

帖子

1

粉丝