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

Little problem with mcr.c driver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
DiegoGarcia



Joined: 01 Mar 2008
Posts: 48

View user's profile Send private message

Little problem with mcr.c driver
PostPosted: Thu Apr 10, 2008 1:09 pm     Reply with quote

Hi guys, its me again !

The mcr.c is working amazing the only problem that I dont figure out yet is that when I pass the first card into the magnetic card reader the mcr_read function fills both the tracks with 0, after the first time it works amazing ...

Any tips ?

Here is my code:

Code:

#define MCR_CARD_PRESENT   PIN_B0
#define MCR_DATA2          PIN_G2
#define MCR_STROBE2        PIN_G1
#define MCR_DATA1          PIN_F2
#define MCR_STROBE1        PIN_B2

#include <mmcsd.c>
//#include <funcoes.c>
#include <teclado.c>
#include <custom_mcr.c>


//Necessario para habilitar a USB
#bit PLLEN = 0xf9b.6
                                                                                                                                 
void main()
{
   int i, i1, i2, rMCardError;
   int8 out_data[4];
   int8 in_data[2];
   Byte bHasError, bReadMCard;
   char Track1[79];
   char Track2[40];


   //Habilita o oscilador para funcionar com a usb
   PLLEN = 1; 

   bReadMCard = True;
   
   usb_init_cs();

   while (TRUE)
    {
   
     if (bReadMCard)
      {
        for (i=0; i<80;i++)
         {
           Track1[i] = 0x00;
           Track2[i] = 0x00;
         }
       rMCardError = mcr_read(Track1,Track2);
       bReadMCard = False;     
      }
     
     usb_task();         
     
      if (usb_enumerated())
       {                 
           
            if (usb_kbhit(1))
             {
             
              usb_get_packet(1, in_data, 2);

              if (in_data[0] == 0x01)  // LĂȘ
                 {

                   // Check for card reading errors
                   if(rMCardError & MCR_ERR_PARITY1)
                    {
                      bHasError = True;
                      rMCardError = 0x01;
                    }
                   
                   if(rMCardError & MCR_ERR_PARITY2)
                    {
                      bHasError = True;
                      rMCardError = 0x02;                    }

                   if(rMCardError & MCR_ERR_LRC1)
                    {
                      bHasError = True;
                      rMCardError = 0x03;
                    }

                   if(rMCardError & MCR_ERR_LRC2)
                    {
                      bHasError = True;
                      rMCardError = 0x04;
                    }

                  if (!bHasError)
                   {

                      i=0;
                      i1=0;
                      i2=0;

                      // Loop until the end sentinel (?) is displayed.
                      // This loop does not display the LRC character.
                      do
                       {
                         out_data[0] = 0x22;
                         //Envia o caracter e incrementa o indice
                         out_data[1] = Track1[i1++];

                         out_data[2] = Track1[i1++];                   

                         if (Track2[i2-1] != '?')                                   
                          out_data[3] = Track2[i2++]; else
                          out_data[3] = 0x00;
                         
                         usb_put_packet(1, out_data, 4, USB_DTS_TOGGLE);
                         
                         delay_ms(50);
                         
                         i++;
                        }while(Track1[i1-1] != '?' && i<40);                 
                  }
                   else
                       {
                          out_data[0] = 0x40;
                          out_data[1] = 0x00;                     
                          out_data[2] = 0x00;
                          out_data[3] = rMCardError;
     
                          usb_put_packet(1, out_data, 4, USB_DTS_TOGGLE);
                          delay_ms(50);
                          bHasError = False;
                       }
                } // End if in_data[0]

               //Read another card
               if (in_data[0] == 0x03)
                 bReadMCard = True;

           } //End if usb_kbhit
      delay_ms(10);
    }//End ubs_enumerated
 } //End while true
} //End main



Thanks a lot guys,
Regards,
Diego Garcia
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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