HAI, I would like to implement TTL interface to a swipe card reader. I want to read track 2 of a card .This contains alphanumeric characters and each character is of 5 bit size which includes one parity bit. I designed a hardware circuit for this with AT89c2051. The data is coming as a stream of bits from the readers magnetic head. So I have store this bit stream to a bit array. I used bdata variable for this purpose, but is not possible to write to the bit position. How I can write these bits to my bit array? What is wrong with code below: I used the pin P1.6 as the input for the data from card reader's magnetic head. Please help me.
sbit dat=P1^6; bdata unsigned char mydata[13]; for (i = 0; i < 13; i++) { for (mask = 0x01; mask != 0x00; mask <<= 1) { mydata[i] & mask = dat; } }
Here the error I got is errorC141:syntax error near'=';
Please give a replay.
dear sir i would like to know that have you succeed about your project or no?? and do you have any information about magnetic card writer??? best regards majd
Hello Sreeja..!!
i am a engneering final yr student...i want to do my final project on Cashless payment system in Campus using swipe card technology!!..I want to develope Hardware of Reader and Writer Module..!! could u plz mentor me in completing my project..!!
Hope u would reply me soon.
Thanks & Regards, Krishna Mohan email: ykmohan@ymail.com
This has two magic constants that needs to be updated if changing to another bit number:
unsigned char c = (mydata[i] & 0x20) >> 5 ;
Probably better to only have one constant that depends on which bit position to work with.
unsigned char c = (mydata[i] >> 5) & 1;
I really prefer (1<<5) before 0x20 when working with single bits.
read bit 5:
turning bit 5 on:
mydata[i] |= 0x20 ;
turning bit 5 off:
mydata[i] &= ~0x20 ;
Since bit manipulation into normal C data types (char or int) is really standard: Why do you not use Google to search for example code? Are you afraid that you may find too many examples?
Access:
(*Store) & (1<<BitNumber);
Store:
if (BitVal==0) *Store &= ~(1<<BitNumber); else *Store |= (1<<BitNumber);
BitNumber is a value 0 to 7.
HAI, How can I acess a single bit from a character and store a bit into that location ? can you please post a simple example of that.
C doesn't has any bit arrays.
Standard C programming can allow you to use a byte array to store any sequence of bits. All you need are the shift operations << and >> together with bit-and & and bit-or |.
To insert five bits at a time, you can keep two variables.
Current start byte to write in. (0 .. sizeof(array)) Current bit position to write in. (0 .. 7)
if bit offset is 0: write only in first byte and increment bit offset by 5.
if bit offset is 1: write only in first byte and increment bit offset by 5.
if bit offset is 2: write only in first byte and increment bit offset by 5.
if bit offset is 3: write only in first byte. then increment byte offset and set bit offset to 0.
if bit offset is 4: write four bits in first byte. then write 1 bit to start of second byte. increment byte offset and set bit offset to 1.
...
if bit offset is 7: write one bit to first byte. then write 4 bits to start of second byte. increment byte offset and set bit offset to 4.
The above can be merged into quite few lines of C code, and is left as an exercise.
Note that writes to the first byte may require a shift left to skip a number of bit positions. Writes to the second byte may require a shift right, to throw away already written bits.
If a 16-bit processor was used, it would normally be efficient to have a 16-bit variable where the data is shifted in, and whenever it contains >= 8 bits of data, then one byte is written. This of course also requires that the transfer is finalized by inserting dummy bits after the transfer, until a full byte is available for storing.
Hai Friend, My code get some compilation error as mentioned in my first post. So the problem I think is not in hardware, but in code itself. If I get a single bit from a card, then it is possible to store in a single bit. But if it is a stream of bits, then I have to store in a bit array. How can I define a bit array and how its bits can be accessed. Actually there is 8 bits in a char, but I am not able store a bit in its bit0 or bit1 etc. Is it possible using Keil to store a stream of bits to such a variable. Is it possible to use bdata variable for this purpose? Please help me with a sample code.
Have you tried "myspace" ? :-)
"If you could only persuade Eric to change his name to "Sir Erac"..."
you be know some my freinds stil need picture of theyre goodly idal Erac. we see google and facebook but no be getting :(
Thanks Flaver, I have not done my home work on the speed.
Ah Kalib Rahib, welcome back! Thanks for the correction. If you could only persuade Eric to change his name to "Sir Erac"... :-)
if (Tamirre> Michael) NameChanged(); else SimpleTypo();
If it's data from a standard track 2 interface and your processor is running at a reasonable rate (>7MHz) then you will easily be able to write the ISR in C.
You might find it easiest to have a 'storage index' and a 'bit mask' to write each bit to a buffer. Much as 'S Edara' suggests.
View all questions in Keil forum