'-------------------------------------------------------------------------- ' MAGCARD.BAS ' This example show you how to read data from a magnetic card ' It was tested on the CP-MEGA/AVR V2.0 '-------------------------------------------------------------------------- '[reserve some space] Dim Ar(100) As Byte , B As Byte , A As Byte 'the magnetic card reader has 5 wires 'red - connect to +5V 'black - connect to GND 'white - Card inserted signal CS 'green - clock 'yellow - data 'You can find out for your reader which wires you have to use by connecting +5V 'And moving the card through the reader. CS gets low, the clock gives a clock pulse of equal pulses 'and the data varies 'I have little knowledge about these cards and please dont contact me about magnectic readers 'It is important however that you pull the card from the right direction as I was doing it wrong for 'some time :-) '[We use ALIAS to specify the pins and PIN register] _mport Alias Pind 'all pins are connected to PIND _mdata Alias 4 'data line (blue) PORTD.4 _mcs Alias 3 'CS line (yellow) PORTD.3 _mclock Alias 5 'clock line (green) PORTD.5 Config Portd = Input 'we only need bit 2,4 and 5 for input Portd = 255 'make them high Do Print "Insert magnetic card" 'print a message Readmagcard Ar(1) , B , 5 'read the data Print B ; " bytes received" For A = 1 To B Print Ar(a); 'print the bytes Next Print Loop 'By sepcifying 7 instead of 5 you can read 7 bit data