PDA

View Full Version : Reading Magnetic Card on Pic16f876



Finn
- 3rd February 2004, 19:56
Question:
I am fairly new to pics so please bare with me. I am using the Les Johnson program to scan the keypad(Keypad12.bas), After the keypad is scanned and the # key is pressed the following code is executed:


Define OSC 20 'Crystal is 20MHZ
Out1 VAR BYTE
Card VAR BYTE[11]

IF Key = 11 Then
Write 0,Key 'Writes Value from Key to Memory Location "0"
Read 0,Out1 'Reads Memory Location "0" and saves it as Out1
Pause 30
'SerOut PORTB.7,N2400,[#Out1] 'Sends Out1 to RS232 Transmitter ,8N1 Format
Debug I,Clr
Debug I,Line2,Clr
Debug I,Line1,"Processing" 'Prints Processing to Serial LCD Line1
Pause 3000
Debug I,Line2,"Swipe Card Now" 'Prints Swipe Card Now to LCD Line2
Pause 30
SerIn2 PORTA.4\PortA.5,16468,300,Main,[Wait ";",Ao),STR Card\11] 'Trying to read data line from Mag Card Reader
Serout PortB.5,N2400,[I,Line1,#STR Card\11] 'Trying to Print Data from Mag Card onto LCD

EndIF

After the "# "key is pressed I want to be able to read the Magnetic Card Data via A mag Card Reader: 9600/8/N/1. The data is being read from track Two in this format:
TrackID/Data/'?'.
the Track ID is ";" which is also the begin sentinel, the data follows and then the end sentinel is "?". I am trying to connect the mag card reader to the Pic16f876 and have pins 4 and 7 on the mag reader(DB9) connected to 5 volts, pin 5 to ground and Pin 3 connected to PortA.4. I cannot read the card data from the card reader. Can anyone help...maybe telling me what im doing wrong or guide me in the right direction?
Thanks in advance.

Melanie
- 4th February 2004, 09:13
I posted a Mag Card Reader program quite some time ago done in PBP at the Melabs website. Download it from ...

http://www.melabs.com/resources/samples/submitted/MagCard.txt

Mag Card readers do not conviently output asynchronous serial data that can be read with SERIN. The bit stream is totally alien and SERIN, DEBUGIN, HSERIN etc just don't hit the mark.

Melanie

Finn
- 4th February 2004, 18:09
Thank you Melanie, I am checking it out now...Appreciate your response.

Finn
- 4th February 2004, 22:08
Melanie,
I have a question on the Mag reader card hookups in your source code. Which pin is considered the clock pin on the DB9 Config and which is considered the card loaded and running signal. The pins I have hooked up are Pin 3(TX) Pin5(GRD)
Pin4(DTR) to +5volts With 1,2,6,7,8 and 9 disconnected.
Thanks,

Melanie
- 4th February 2004, 22:25
The fast answer is I don't know your Card Reader. The program I put together was for a 'bare drive'. All the bare drives have basically the reading heads giving a Clock and Data output, and a sensor that detects when the card has been inserted. If your Card Reader is an intelligent one with some form of processing and an RS-232 interface built-in, then you should refer to the manufacturer for details. I would add that just because it's got a DB9 connector on it, doesn't mean it's got a standard Serial interface. It may have those basic signals brought out to the DB9 pins. I've seen people couple the wierdest things thru those 9-pin connectors.

Finn
- 4th February 2004, 22:40
I checked through the datasheet and found pins I think I can use. For the Running and loaded signal im going to use DTR, or a constant 5 volts and the TX Pin for data. I was looking through you code and it seems that the program is ready to execute and recieve data when the clock signal is low, So maybe I can just set that pin to low and have it work? Also the data is coming in at 9600bps, which i imagine is the same as your "bare" reader. Is there a Define needed for the data rate?
Thanks,

Melanie
- 5th February 2004, 00:28
The first thing you have to do is identify if your Card Reader is intelligent with Serial RS-232 type output, in which case my program will not be suitable. You must ID the reader and it's connections first, otherwise you're just stabbing blindly in the dark.

With separate Clock and Data lines, the host program syncs to the speed of the Clock signal. This Clock will vary in speed depending how fast a Card is swiped thru the Reader. As I recall, in tests, you couldn't physically swipe a card thru the reader so fast that the host PIC at 4MHz didn't catch it every time.

Finn
- 5th February 2004, 00:36
Thanks Melanie. Im going to do a little more research on the reader I have and go from there. Thanks for your help.