CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RDM8800 NFC / RFID Module Driver.

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
mohammad3d



Joined: 28 Mar 2009
Posts: 17

View user's profile Send private message Send e-mail

RDM8800 NFC / RFID Module Driver.
PostPosted: Sat Oct 13, 2018 3:05 am     Reply with quote

Hi every one.

I write a simple code for reading data from RDM8800 module via serial pin on
pic 16f877 device.

I use an 2x16 charater LCD for display UID tag number.
Just connect RDM8800 TX pin to PIC RX pin(RC7/RX pin26) and enjoy...

Main.c

Code:

//main.c File
#include <16F887.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage programing, B3(PIC16) or B5(PIC18) used for I/O
#FUSES XT
#use delay(crystal=4000000)//Set frequency at 4Mhz
#use rs232( baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, ERRORS)
#include <C_LCD.h>//2x16 Character LCD driver
#define Time_out 200
int16 RS232_timeout=0;
int8 string_index=1;
int8 i=1;
char NFC_uid[20];
int1 Data_recieve_flag=0;
int1 Read_card_flag=1;


void main()
{
   
   lcd_init();//initialize 2x16 caracter LCD
   lcd_putc('\f');//Clear screen
   lcd_gotoxy(1,1);
   printf(lcd_putc,"RDM8800 NFC/RFID");     
   lcd_gotoxy(1,2);
   printf(lcd_putc,"     READER     ");
   delay_ms(1000);
   lcd_putc('\f');//Clear screen
   while(TRUE)
   {
    RS232_timeout++;
    if(Read_card_flag==1)//Permit read serial port
       if(kbhit())
         {
          RS232_timeout=0;
          NFC_uid[string_index]=getc();
          if(string_index==12) Data_recieve_flag=1;//recieve 12 character from RDM8800
             else string_index++;               
         }     
         
       if(Data_recieve_flag==1)//receive 12 character successfully
         {
         
          Read_card_flag=0;
          Data_recieve_flag=0;
          if(NFC_uid[11]==0x0D && NFC_uid[12]==0x0A)//If received stream is correct, with break line "0x0D 0x0A".
            {           
             lcd_gotoxy(1,1);
             printf(lcd_putc,"Card UID number:");               
             delay_ms(1000);
             lcd_putc('\f');//Clear screen
             //////////// display 10 digit UID number on LCD ////////////
             for(i=1;i<=5;i++)
                printf(lcd_putc,"%c,",NFC_uid[i]);   
               
                lcd_gotoxy(1,2);
             for(i=6;i<=9;i++)
                 printf(lcd_putc,"%c,",NFC_uid[i]);
                 
             printf(lcd_putc,"%c",NFC_uid[10]);   
             /////////////////////////////////////////////////////////////   
             delay_ms(5000); 
             lcd_putc('\f');//Clear screen
             
            }
            else ///////// if stream is not correct //////////
                {
                 lcd_putc('\f');//Clear screen
                 lcd_gotoxy(1,1);
                 printf(lcd_putc,"Data read error");   
                 delay_ms(1000);
                }           
         }
         
       if(RS232_timeout>Time_out)///// detect blank time between two stream
         {
          RS232_timeout=Time_out;
          string_index=1;
          Data_recieve_flag=0;
          lcd_gotoxy(1,1);
          printf(lcd_putc,"Checking for Tag");   
          Read_card_flag=1;
         }       
   }
}


C_LCD.h

Code:

//C_LCD.h file
#define _lcd_h_
#include <math.h>
void lcd_init(void);             
byte lcd_read_byte(void);         
byte lcd_read_nibble(void);       
void lcd_send_byte(byte address, byte n); 
void lcd_send_nibble(byte n);   
void lcd_gotoxy(byte x, byte y);
char lcd_getc(byte x, byte y);   
void lcd_putc(char c);           
//Define LCD connection Pins
#define LCD_RS_PIN         PIN_D1   
#define LCD_RW_PIN         PIN_D2
#define LCD_ENABLE_PIN     PIN_D3
#define LCD_DATA4          PIN_D4
#define LCD_DATA5          PIN_D5
#define LCD_DATA6          PIN_D6
#define LCD_DATA7          PIN_D7

#define lcd_output_enable(x)   output_bit(LCD_ENABLE_PIN, x) 
#define lcd_enable_tris()   output_drive(LCD_ENABLE_PIN)

#define lcd_output_rs(x)   output_bit(LCD_RS_PIN, x) 
#define lcd_rs_tris()      output_drive(LCD_RS_PIN)

#define lcd_output_rw(x)   output_bit(LCD_RW_PIN, x)
#define lcd_rw_tris()      output_drive(LCD_RW_PIN)

#define lcd_line_one   0x00   
#define lcd_line_two   0x40   
#define lcd_line_three   0x14
#define lcd_line_four   0x54
#define LCD_TYPE 0x02         


byte const LCD_INIT_STRING[4] = {0x28 | (LCD_TYPE << 2), 0x0C, 0x01, 0x06};
void lcd_init(void)   
{

byte i;

output_drive(LCD_DATA4); 
output_drive(LCD_DATA5);
output_drive(LCD_DATA6);
output_drive(LCD_DATA7);

lcd_enable_tris();
lcd_rs_tris();
lcd_rw_tris();

lcd_output_rs(0);     
lcd_output_rw(0);       
lcd_output_enable(0);   

delay_ms(15);

for(i=1;i<=3;i++)       
   {               
   lcd_send_nibble(0x03);   
   delay_ms(5);       
   }               
                   

lcd_send_nibble(0x02);     
for(i=0;i<=3;i++)
   lcd_send_byte(0,LCD_INIT_STRING[i]);
}                           

// ***************************************************
byte lcd_read_byte(void)   
{
byte low,high;
output_float(LCD_DATA4); 
output_float(LCD_DATA5);
output_float(LCD_DATA6);
output_float(LCD_DATA7);

lcd_output_rw(1);       
delay_cycles(1);       
lcd_output_enable(1);     
delay_cycles(1);         
high = lcd_read_nibble(); 
lcd_output_enable(0);     
               
delay_cycles(1);       
lcd_output_enable(1);     
delay_cycles(1);         
low = lcd_read_nibble();   
lcd_output_enable(0);     

output_drive(LCD_DATA4);   
output_drive(LCD_DATA5);
output_drive(LCD_DATA6);
output_drive(LCD_DATA7);

return((high<<4) | low);   
}

// ***************************************************
byte lcd_read_nibble(void)   
{

byte n = 0x00; 

n |= input(LCD_DATA4);       
n |= input(LCD_DATA5) << 1;
n |= input(LCD_DATA6) << 2;
n |= input(LCD_DATA7) << 3;

return(n);   
}

// ***************************************************
void lcd_send_byte(byte address, byte n)   
{                               

lcd_output_rs(0);     
while(bit_test(lcd_read_byte(),7)); 
lcd_output_rs(address); 
delay_cycles(1);   
lcd_output_rw(0);   
delay_cycles(1);     
lcd_output_enable(0);   
lcd_send_nibble(n >> 4); 
lcd_send_nibble(n & 0x0F); 
}

// ***************************************************
void lcd_send_nibble(byte n) 
{

output_bit(LCD_DATA4, bit_test(n, 0)); 
output_bit(LCD_DATA5, bit_test(n, 1));
output_bit(LCD_DATA6, bit_test(n, 2));
output_bit(LCD_DATA7, bit_test(n, 3));
   
delay_cycles(1);     
lcd_output_enable(1); 
delay_us(2);         
lcd_output_enable(0);   
}

// ***************************************************
void lcd_gotoxy(byte x, byte y) 
{

byte address;

if(y==1)             
   address=lcd_line_one;     
else if(y==2)     
   address=lcd_line_two;     
else if(y==3)
   address=lcd_line_three;     
else if(y==4)
   address=lcd_line_four;   

address+=x-1;             
lcd_send_byte(0,0x80|address); 
}                     

// ***************************************************
char lcd_getc(byte x, byte y)
{

char value;

lcd_gotoxy(x,y);           
while(bit_test(lcd_read_byte(),7)); 
lcd_output_rs(1);       
value = lcd_read_byte(); 
lcd_output_rs(0);       

return(value);   
}

// ***************************************************
void lcd_putc(char c) 
{

switch (c)
   {
   case '\f':   
      lcd_send_byte(0,0x01); 
      delay_ms(2);     
      break;
   case '\n':     
      lcd_gotoxy(1,0x02);     
      break;
    case '\b':     
      lcd_send_byte(0,0x10);
      break;           
   default:       
      lcd_send_byte(1,c);   
      break;
   }
}     
// ***************************************************   
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group