Pic 18f4550 Rfid Kart Okuyucu(Reader) Problem

drexel

Üye
Katılım
3 Eki 2009
Mesajlar
22
Puanları
1
Yaş
38
Arkadaşlar hepinize iyi forumlar.

İnternette yer alan kodlardan fayadalanarak bir rfid kart okuyucu yapmaya çalışıyorum fakat başarılı olamadım. Bana nerede hata yaptığımı söyleyebilirseniz memnun olurum.

Rfid okuyucu olarak mikroelektronika rfid reader kullanılmıştır. Bunun dışında kullanılan proximity kartlar:

PROXİMİTY KART - Elektrovadi

Aşağıda ccs kodu vardır. Program if(em4102_read()) kısmında takılıyor gibi duruyor. Nedenini hala çözemedim.

Yazdığım Rfid CCS C kodu:
Kod:
#include <18F4550.h>
#include <string.h>
#use delay(clock=4000000)

#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT,NOMCLR                                                
#include <flex_lcd.c>
#include <em4095_read.c>                  
#include <em4102.c>                     
                                                             
   char text[] = "RFID SISTEMI";               
   char text2[] = "Altan";               
                                               
   int32 tagNum;                                 
   int8  customerCode;                          
   int8 code[5];
                                                                                      
void main()                                                
{ 
	setup_adc_ports(NO_ANALOGS);
   setup_comparator(NC_NC_NC_NC);

   lcd_init();
                                                         
   rf_init();    //rfid yüklemesini yap              
                                   
   output_high(PIN_A0);          
   Output_high(PIN_A1);
   output_low(PIN_A2);              
   output_high(PIN_A3);                                
                                       
   lcd_gotoxy(1,1);                              
   printf(lcd_putc,"%s",text);
   delay_ms(1000);                    
   lcd_gotoxy(1,2); 
   printf(lcd_putc,"%s",text2);         
   delay_ms(1000);
   lcd_gotoxy(1,1);                                                    
   lcd_putc("                ");           
   lcd_gotoxy(1,2);                                  
   lcd_putc("                ");                            
                  
   while (1)
   {
      if(read_4102(code))  //kart antene yaklaştırılınca
      {                                                 
      	lcd_gotoxy(1,1);                                               
      	lcd_putc("Kart Okunuyor...");                                
      	delay_ms(1000);
      	lcd_gotoxy(1,1);                    
      	lcd_putc("                ");                 
         tagNum = make32(code[1],code[2],code[3],code[4]);                   
         customerCode = code[0];                                      
         lcd_gotoxy(1,1);  
         printf(lcd_putc,"%s",customerCode);
         lcd_gotoxy(1,2);
         printf(lcd_putc,"%s",tagNum);
      }                                       
	}                                                      

}

Bu da em4102_read.c kodu

Kod:
/////////////////////////////////////////////////////////////////////////
////                             em4095_read.c                       ////
//// This file contains drivers for a EM4095 RFID basestation.       ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////                          Pin Layout                             ////
////   ------------------------------------------------------------  ////
////   |                                                          |  ////
////   | 1: VSS       GND         | 16: DC2                       |  ////
////   |                          |                               |  ////
////   | 2: RDY/CLK   RF_RDY_CLK  | 15: FCAP                      |  ////
////   |                          |                               |  ////
////   | 3: ANT1                  | 14: SHD         RF_SHD        |  ////
////   |                          |                               |  ////
////   | 4: DVDD                  | 13: DEMOD_OUT   RF_DEMOD_OUT  |  ////
////   |                          |                               |  ////
////   | 5: DVDS                  | 12: MOD         RF_MOD        |  ////
////   |                          |                               |  ////
////   | 6: ANT2                  | 11: AGND                      |  ////
////   |                          |                               |  ////
////   | 7: VDD       +5V         | 10: CDEC_IN                   |  ////
////   |                          |                               |  ////
////   | 8: DMOD_IN               |  9: CDEC_OUT                  |  ////
////   ------------------------------------------------------------  ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////

#ifndef EM4095                                                                              
#define EM4095
                                                                                                      
#ifndef RF_SHD
#define RF_RDY_CLK   PIN_C0         // External interrupt used to read clock
#define RF_SHD       PIN_D3         // High disables the antenna signal
#define RF_MOD       PIN_D2         // High does 100% modulation
#define RF_DEMOD_OUT PIN_C2         // Data read in interrupt service routine
#endif


// Provide a buffer for storing recieved data and data to be sent                          
#define RFBUFFER_SIZE 20
int8 RFbuffer[RFBUFFER_SIZE];
int8 RFbuffer_index = 0;         
int8 RFbuffer_bitIndex = 0;
#define END_OF_RFBUFFER (RFbuffer_index == sizeof(RFbuffer))


/////////////////////////////////////////////////////////////////////////
//// Read modes available for reading data from a transponder
/////////////////////////////////////////////////////////////////////////
int8 RF_readMode;
#define RF_MANCHESTER_DATA    0     // Reads Manchester encoded data
#define RF_MEASURE_WIDTHS     1     // Measure a series of widths
#define RF_FIND_WIDTH         2     // Find a specific width
#define RF_FIND_PATTERN       3     // Find a pattern of widths
/////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////
//// Global Variables
/////////////////////////////////////////////////////////////////////////
int1  bitValue              = 1;                 
int1  storeData             = TRUE;
int1  RE_FE_TOGGLE          = 1;
int1  RF_widthFound         = FALSE;
int1  RF_patternFound       = FALSE;
int8  RF_widthToFind        = 0;
int8* RF_findWidths         = 0;
int8  RF_uncertainty        = 0;
int8  timer0_overflows      = 0;
int8  dataTransferred       = 0;
int16 old_clock             = 0;
/////////////////////////////////////////////////////////////////////////


// Purpose:       Initializes the 4095 into sleep mode
//                Sets up the timers and interrupts
void rf_init()
{
   output_low(RF_SHD);
   output_low(RF_MOD);    
                                                                  
   setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);
   setup_ccp1(CCP_CAPTURE_RE);
   //setup_ccp2(CCP_COMPARE_INT);

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);                                          
}

// Purpose:       Powers down the RF antenna
//#define rf_powerDown()  output_high(RF_SHD);
                                                    
// Purpose:       Powers up the RF antenna
//#define rf_powerUp()    output_low(RF_SHD);


// Purpose:       Select which edge to begin reading data
void RF_readEdge(int1 edge)
{
   if(edge)
   {
      setup_ccp1(CCP_CAPTURE_RE);
      RE_FE_TOGGLE = 1;
   }
   else
   {
      setup_ccp1(CCP_CAPTURE_FE);
      RE_FE_TOGGLE = 0;
   }
}
                            

// Purpose:       Interrupt service routine to handle compare 1 interrupts.
//                Reads incoming data from a transponder and stores it in
//                the global buffer.
#INT_CCP1
void isr_ccp1()
{
   int8  width;                      

   // Toggle between capturing rising and falling edges to meausure width
   if(RE_FE_TOGGLE)
   {
      setup_ccp1(CCP_CAPTURE_FE);
      RE_FE_TOGGLE = 0;
   }
   else
   {
      setup_ccp1(CCP_CAPTURE_RE);
      RE_FE_TOGGLE = 1;
   }

   // Calculate the width
   width = CCP_1 - old_clock;
   old_clock = CCP_1;

   switch(RF_readMode)
   {
      // Use to receive manchester formatted data from a transponder
      case RF_MANCHESTER_DATA:
      {
         if(width > 54)           // Check for a phase change
         {
            bitValue = ~bitValue; // Invert the save bit value
            storeData = TRUE;     // Force a bit store
         }

         if(storeData)
         {
            shift_right(RFbuffer+RFbuffer_index, 1, bitValue);
            ++dataTransferred;

            if(++RFbuffer_bitIndex == 8)
            {
               RFbuffer_bitIndex = 0;
               ++RFbuffer_index;
            }
         }

         storeData = ~storeData;
         break;
      }

      // Use to read high and low widths
      case RF_MEASURE_WIDTHS:
      {
         RFbuffer[RFbuffer_index++] = width;
         ++dataTransferred;

         break;
      }

      // Use to search for a certain pulse width
      case RF_FIND_WIDTH:
      {
         if(width > (RF_widthToFind - RF_uncertainty)
         && width < (RF_widthToFind + RF_uncertainty))
         {
            RF_widthFound = TRUE;
         }
         break;
      }

      case RF_FIND_PATTERN:
      {
         if(width > RF_findWidths[RFbuffer_index] - RF_uncertainty
         && width < RF_findWidths[RFbuffer_index] + RF_uncertainty)
         {
            if(++RFbuffer_index == dataTransferred)
            {
               RF_patternFound = TRUE;
            }
         }
         else
         {
            if(RFbuffer_index > 0)
            {
               int8 pos, i, j;
               pos = RFbuffer_index-1;   // Save the initial position

               // Try to match partial pattern
               while(--RFbuffer_index != 0)
               {
                  if(width > RF_findWidths[RFbuffer_index] - RF_uncertainty
                  && width < RF_findWidths[RFbuffer_index] + RF_uncertainty)
                  {
                     for(i=pos, j=RFbuffer_index-1; j!=255; --i, --j)
                     {
                        if(RF_findWidths[j] != RF_findWidths[i])
                        {
                           break;
                        }
                     }
                     if(j == 255)
                     {
                        break;
                     }
                  }
               }
            }
         }
         break;
      }
   }
}


// Purpose:       This interrupt service routine is used
//                to send data to a transponder
// Inputs:        None
// Outputs:       None



// Purpose:       Interrupt for timer 0. Keeps track of the number of
//                overflows for timeouts.
// Inputs:        None
// Outputs:       None
#INT_RTCC
void isr_rtcc()
{
   ++timer0_overflows;
}


// Purpose:       Fill the buffer with data read from the basestation
// Inputs:        1) The number of bits to read
//                2) TRUE start on rising edge
//                   FALSE start on falling edge
// Outputs:       The number of bits read. Could be used to check for timeout
int8 RF_get(int8 numBits, int1 edge)
{
   RF_readEdge(edge);
   RF_readMode = RF_MANCHESTER_DATA;

   storeData         = TRUE;
   bitValue          = 0;
   RFbuffer_index    = 0;
   RFbuffer_bitIndex = 0;
   dataTransferred   = 0;
   timer0_overflows  = 0;
   old_clock         = 0;
   set_timer1(0);

   clear_interrupt(INT_CCP1);
   enable_interrupts(INT_CCP1);
   while(dataTransferred < numBits && timer0_overflows < 15);
   disable_interrupts(INT_CCP1);

   RFbuffer_index = 0;
   RFbuffer_bitIndex = 0;

   return dataTransferred;
}


// Purpose:       Send data from the buffer to the transponder
// Inputs:        1) Send numBits of data to the transponder
//                2) The index in the buffer to start at
//                3) The bit position at the index to start at
// Outputs:       None



// Purpose:       Search for a certain pulse width
// Inputs:        1) The width length in clocks
//                2) Uncertainty to search over a range
//                3) TRUE start on rising edge
//                   FALSE start on falling edge
//                ex) numClocks = 128; uncertainty = 6; range = 122 to 134
// Outputs:       TRUE if width was found, FALSE if not found
int1 RF_findWidth(int8 numClocks, int8 uncertainty, int1 edge)
{
   RF_readEdge(edge);

   RF_readMode          = RF_FIND_WIDTH;
   RF_widthToFind       = numClocks;
   RF_widthFound        = FALSE;
   RF_uncertainty       = uncertainty;
   timer0_overflows     = 0;
   old_clock            = 0;
   set_timer1(0);

   clear_interrupt(INT_CCP1);
   enable_interrupts(INT_CCP1);
   while(RF_widthFound == FALSE && timer0_overflows < 50);
   disable_interrupts(INT_CCP1);

   return RF_widthFound;
}


// Purpose:    Measure a number of pulse widths, both high and low
// Inputs:     1) The number of widths to measure
//             2) TRUE start on rising edge
//                FALSE start on falling edge
// Outputs:    The number of widths that were measured. If there is
//             no transponder in range, the timeout could occur.
int8 RF_measureWidths(int8 numWidths, int1 edge)
{
   RF_readEdge(edge);

   RF_readMode       = RF_MEASURE_WIDTHS;
   dataTransferred   = 0;
   RFbuffer_index    = 0;
   timer0_overflows  = 0;
   old_clock         = 0;
   set_timer1(0);

   clear_interrupt(INT_CCP1);
   enable_interrupts(INT_CCP1);
   while(dataTransferred < numWidths && timer0_overflows < 50);
   disable_interrupts(INT_CCP1);

   return dataTransferred;
}

// Purpose:    Measure a number of pulse widths, both high and low
// Inputs:     1) A pointer to an array of widths. It is safe to use RFbuffer.
//             2) The number of widths in the pattern
//             3) Uncertainty to search over a range
//             4) TRUE start on rising edge
//                FALSE start on falling edge
// Outputs:    The number of widths that were measured. If there is
//             no transponder in range, the timeout could occur.
int8 RF_findPattern(int8* widths, int8 numWidths, int8 uncertainty, int1 edge)
{
   RF_readEdge(edge);

   RF_readMode       = RF_FIND_PATTERN;
   RF_patternFound   = FALSE;
   RFbuffer_index    = 0;
   RF_findWidths     = widths;
   dataTransferred   = numWidths;
   RF_uncertainty    = uncertainty;
   timer0_overflows  = 0;
   old_clock         = 0;
   set_timer1(0);

   clear_interrupt(INT_CCP1);
   enable_interrupts(INT_CCP1);
   while(RF_patternFound == FALSE && timer0_overflows < 40);
   disable_interrupts(INT_CCP1);

   return RF_patternFound;
}


// Purpose:       Set every byte in the buffer to data
// Inputs:        None
// Outputs:       None
void RFbuffer_fill(int8 data)
{
   int i;

   for(i=0; i<sizeof(RFbuffer); ++i)
   {
      RFbuffer[i] = data;
   }
}


// Purpose:       Inverts every byte in the buffer
// Inputs:        None
// Outputs:       None
void RFbuffer_invert()
{
   int i;

   for(i=0; i<sizeof(RFbuffer); ++i)
   {
      RFbuffer[i] = ~RFbuffer[i];
   }
}


// Purpose:       Get a bit of data from the buffer and increment to the next bit
// Inputs:        None
// Ouputs:        A bit of data
int1 RFbuffer_getBit()
{
   int1 bit;

   if(!END_OF_RFBUFFER)
   {
      bit = bit_test(RFbuffer[RFbuffer_index], RFbuffer_bitIndex);

      if(++RFbuffer_bitIndex == 8)
      {
         ++RFbuffer_index;
         RFbuffer_bitIndex = 0;
      }
   }

   return bit;
}


// Purpose:       Get a byte of data from the buffer
// Inputs:        None
// Outputs:       The byte of data
int8 RFbuffer_getByte()
{
   if(!END_OF_RFBUFFER)
   {
      int8 i;
      int8 data;

      for(i=0; i<8; ++i)
      {
         shift_right(&data, 1, RFbuffer_getBit());
      }

      return data;
   }
}


// Purpose:       Set the value of the next bit in the buffer
// Inputs:        None
// Outputs:       None
void RFbuffer_setBit(int1 bit)
{
   if(!END_OF_RFBUFFER)
   {
      if(bit)
      {
         bit_set(RFbuffer[RFbuffer_index], RFbuffer_bitIndex);
      }
      else
      {
         bit_clear(RFbuffer[RFbuffer_index], RFbuffer_bitIndex);
      }

      if(++RFbuffer_bitIndex >= 8)
      {
         ++RFbuffer_index;
         RFbuffer_bitIndex = 0;
      }
   }
}

// Purpose:       Set the value of the next byte in the buffer
// Inputs:        None
// Outputs:       None                                                                                                
void RFbuffer_setByte(int8 data)
{
   if(!END_OF_RFBUFFER)
   {
      int8 i;
      for(i=0; i<8; ++i)
      {
         RFbuffer_setBit(bit_test(data, 7));
         rotate_left(&data, 1);
      }
   }
}

#endif
 
arkadaşım ben pascal la yapmıştım okuyucuyu. c yi pek bilmiyrum.algolitma olarak belki yardımcı olabilirim
 
Saol titan hallettim sorunu. CCS C için yazılmış olan örnek programlar pic18f4550 ile çalışmıyor. Pic16f877a bunun dışında pic16f876 ve 18f452 i ile devre çalıştı. İlgin için çok teşekkür ederim.
 
İyi günler.Bitirme ödevim rfid okuyucular üzerine yalnız benim rf okuyucum smx1300.Modülü pic ile nasıl okuyabilirim?RS232 RX ve TX i var bunlar üzerinden doğrudan okuyabilirmiyim?Yardımcı olursanız çok sevinirim.
 
sayın drexel, proximity tecrübelerinizi paylaşırsanız seviniriz.kodu, şemayı yayınlarsanız biz de yapıp kullanalım isteriz.Bir de Proximity kartların frekansları farklı sanırım.kartklı kartları okuyabiliyormuyuz,yoksa bunun için antenle vs. değişiklik yapmak mı gerekli.yazılım ile frekansı değiştirip tüm kartları okuyabilecek miyiz ?Teşekkürler
 
merhaba arkadaşlar bende bir
[h=3]RFID reader modülü ile ID okuma[/h]yapıcam ayrıca usb haberleşme ile pc ye bağlanacak.
nasıl yapabilirim.usb haberleşme ile arayüz tamam ama bu okuyucu ile pıc arasında nasıl bir bağ kurup kod yazacam.
 
Saol titan hallettim sorunu. CCS C için yazılmış olan örnek programlar pic18f4550 ile çalışmıyor. Pic16f877a bunun dışında pic16f876 ve 18f452 i ile devre çalıştı. İlgin için çok teşekkür ederim.

Arkadaşım böyle birşey olamaz , bende PIC4550 ile çalıştım ve aynı modül bendede var sadece PİC konfigurasyonlarını iyi yapman gerekiyor o kadar.
 

Forum istatistikleri

Konular
128,319
Mesajlar
916,669
Kullanıcılar
450,155
Son üye
srtczngn

Yeni konular

Geri
Üst