DiegoGarcia
Joined: 01 Mar 2008 Posts: 48
|
Little problem with mcr.c driver |
Posted: Thu Apr 10, 2008 1:09 pm |
|
|
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 |
|