??? 02/14/07 09:18 Read: times |
#132882 - Reading a ISO7811 card with AT89c2051 |
I'm trying to read a card using a AT89c2051 and a KDR1932 CardReader. i wrote the code in franklin software p roview (C).
the ideea: the ucontroller is waiting for the card. a interrupt occurs when the card reader is sending the clock signal. in the interrupt function i'm reading the data sent by the card reader: port1=(~P1)&0x01; //reading P1 bit 1 (data pin) my_byte[i]=my_byte[i]<<1; my_byte[i]=my_byte[i]+port1; nrb++; //number of bits if (nrb==5){ //if nr of bits is 5 then I write in the next location of my_byte; in ISO 7811 each digit is 5 bits long, comprising a 4-bit BCD digit and a parity bit. i++; nrb=0; } //end of interrupt function in the main program i'am waiting for something to be received on the serial port then send the data. while1: c = getchar (); for(j=0;j<40;j++) { printf ("%c", my_byte[j]+48); //i add 48 to the char so that it would be a readable character byte_meu[j]=0x0; } nrb=0; i=0; goto while1; so... somethimes the reading is good and sometimes the reading is bad. i can't figure out why. for exemple: 1.i slide the card through card reader 2.press a key from my PC to send data to serial 3.i receive the correct data 4.i slide again the card through card reader 5.press a key from my PC to send data to serial 6.i receive wrong data but if between readings (between steps 3 and 4) i clear the memmory again(my_byte) the data readen is correct!! thank you! PS if somebody wants to see the entire code i can send it to them |