The text of a manual · part 4 of 7
I/O Interface for TTL Magnetic Stripe Readers Technical Reference Manual, pages 17 to 22
Pages 17 to 22 of 34: SECTION 3. LRC CALCULATION; SECTION 4. ERROR CHECKING
The original document is the PDF (1.1 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the MagTek 101mm Swipe Reader
Page 17
SECTION 3. LRC CALCULATION The formula for calculating LRC below uses Track 2 as an example. Perform the following: 1.
Write the value for each character (see examples below and Appendix A).
2.
Do not use the odd parity bit (P) in the formula for calculating LRC calculation.
3.
Count the number of one bits in each of the 4 vertical columns.
4.
Enter a zero or one in the LRC position so that each vertical column has a even number of ones (not the parity column {P}).
5.
After all 4 vertical columns have their LRC bit affixed, affix odd parity to the LRC character itself.
Examples: P8421 B 0 F
01011 10000 11111 _______ 00100
4 Where: "B" is the start sentinel "F" is the end sentinel The LRC is under the line
P8421 B 0 1 F 5
01011 10000 00001 11111 _______ 10101
P8421 B 0 1 2 3 F 4
01011 10000 00001 00010 10011 11111 _______ 00100
13
Page 18
I/O Interface for TTL Magnetic Stripe Readers
Calculation of LRC for an encoder, using a Micro Processor (Intel 8751), is as follows: START: MOV R2,#0 ;ZERO REGISTER 2 (LRC ACCUMULATOR) MOV R0,#START_SEN ;POINT AT FIRST CARD CHARACTER (START SENTINEL)
LOOP1: MOVX A,@R0 ;PUT A CARD CHARACTER INTO THE ACCUMULATOR ANL A,#0FH ;MASK OFF THE PARITY BIT XCH A,R2 ;EXCHANGE THE ACCUMULATOR & REG 2 XRL A,R2 ;"EXCLUSIVE OR" ACC WITH R2 XCH A,R2 ;RUNNING TOTAL OF LRC IS NOW IN REG 2, CARD CHARACTER IN ACC. INC R0 ;POINT AT THE NEXT CHARACTER CJNE A,0FH,LOOP1 ;COMPARE, JUMP TO LOOP1 IF NOT EQUAL TO A END SENTINEL. ;WHEN THE PROGRAM FALLS THROUGH THE ABOVE INSTRUCTION THE FINAL LRC IS ;IN REGISTER 2, WE CALL THE ODD PARITY ROUTINE TO AFFIX ODD PARITY TO THE ;LRC AND WE ARE READY TO WRITE THE LRC ON A CARD.
14
Page 19
SECTION 4. ERROR CHECKING This section describes error checking by a typical single track reader and with and Intel 8751 CPU on a typical Track 2 reader. ERROR CHECKS BY A TYPICAL READER The following error checking is performed by a typical card reader: 1.
While the card is being swiped no error checking is done. All of the micro processor unit (MPU) time is being devoted to storing the data being read off the card into memory (RAM). Normally the strobe output from the card reader is connected to an interrupt input on the MPU. The MPU is set so that the interrupt is triggered on the falling edge of the strobe. The data output line from the card reader goes to a normal MPU port input pin. On each Falling edge of the strobe, one bit of data is collected from the data input line and the interrupt routine is exited. The 'Card Present' output from the card reader goes to a normal MPU port Input pin. All outputs from the card reader are quiescently high (Vcc).
2.
When 'card present' returns to high again the MPU knows that the card has cleared the read head and error checking can begin. The MPU now checks each character that it collected in step 1 for the following: A. Checks to ensure the first character is a 'Start Sentinel'. This will be a hex B (01011) for Track 2 or Track 3. For Track 1 it will be a percent sign (1000101). B. Checks each character for odd parity (an odd number of one bits). C. Updates the LRC total as each character is checked. D.
Checks to see if the current character is an 'End Sentinel' (11111, 0011111). If no 'End Sentinel' is found, this is an error. When the 'end sentinel' is found, the MPU inputs the next character (LRC), checks its parity, and updates the LRC total. It then checks that the LRC total is zero. If it is not zero it is an error.
3.
Some readers keep count of the number of characters checked, and if this number exceeds the maximum allowed, will give an error. The maximum allowed is: track 1 = 79; track 2 = 40; track 3 = 107.
4.
If for some reason you do not have enough interrupts available to use the preceding method, MagTek can provide an application note on how to do it without using interrupts. This is done by using a "USART" for each track along with an MPU. See Appendix D. 15
Page 20
I/O Interface for TTL Magnetic Stripe Readers
ERROR CHECKING, TRACK 2, WITH AN INTEL 8751 Example of error checking in a Track 2 reader, using an Intel 8751 CPU: ; INITAILIZE REGISTERS AND FLAG BITS. CHECK: MOV R2,#0 ;ZERO REGISTER 2 (LRC ACCUMULATOR) CLR PARITY_FLAG ;CLEAR THE PARITY ERROR FLAG MOV R0,#START_SEN ;POINT AT FIRST CARD CHARACTER IN RAM (START SENTINEL) ; START PARITY AND LRC CHECK (LONGITUDINAL REDUNDANCY CHECK CHARACTER). CK0: CALL CK1 ;GO TEST A CHARACTER CJNZ A,0FH,CK0 ;COMPARE ACCUMULATOR TO END SENTINEL, GO TO CK0 IF NOT ES ;IF IT'S A END SENTINEL THE PROGRAM DROPS THROUGH CALL CK1 ;GO UPDATE THE LRC CHARACTER MOV A,R2 ;MOVE REGISTER 2 TO THE ACCUMULATOR, GET THE LRC SUM JNZ ERROR ;IF LRC SUM IS NOT ZERO, THIS EQUALS AN ERROR JB PARITY_FLAG,ERROR ;SKIP TO ERROR IF PARITY FLAG IS SET NOP ;IF THIS POINT IS REACHED THE CARD WAS READ CORRECTLY ;END OF TEST ; CK1--LRC SUBROUTINE ; THIS ROUTINE KEEPS THE RUNNING SUM OF THE LRC IN REGISTER 2 CK1: MOVX A,@R0 ;PUT A CARD CHARACTER FROM RAM INTO THE ACCUMULATOR CALL PARITY_CK ;CHECK FOR ODD PARITY MOVX A,@R0 ;GET THE SAME CHARACTER AGAIN ANL A,#0FH ;ZERO THE FIRST 4 BITS, INCLUDING THE PARITY BIT XCH A,R2 ;EXCHANGE ACCUMULATOR AND REGISTER 2 XRL A,R2 ;"EXCLUSIVE OR" THE ACCUMULATOR WITH REGISTER 2 XCH A,R2 ;EXCHANGE ACCUMULATOR AND REGISTER 2 INC R0 ;POINT AT THE NEXT CHARACTER RET ;RETURN, AT THIS TIME THE RUNNING LRC IS IN REGISTER 2
16
Page 21
Section 4. Error Checking ; PARITY--PARITY SUBROUTINE ; COUNTS THE NUMBER OF 'ONES' IN THE ACCUMULATOR. ; SETS THE 'PARITY ERROR FLAG' IF IT FINDS A CHARACTER WITH AN EVEN NUMBER OF ONE BITS. PARITY_CK: MOV R4,#0 ;INITIALIZE THE 'ONES' BIT COUNTER TO ZERO PARITY1: CLR C ;CLEAR THE CARRY PARITY2: JZ PARITY3 ;SKIP TO PARITY3 IF ACCUMULATOR ZERO, DONE, GO TO PARITY3 RRC A ;ROTATE THE ACCUMULATOR RIGHT, THROUGH THE CARRY JNC PARITY2 ;IF THE CARRY IS 'ZERO', GO TO PARITY2 INC R4 ;OTHERWISE INCREMENT THE '1' COUNTER & GO TO PARITY1 JMP PARITY1 ;GO TO PARITY1 AND CONTINUE PARITY3: MOV A,R4 ;PUT THE 'ONES' COUNT INTO THE ACCUMULATOR JB ACC.0 PARITY4 ;IF BIT 0 IS A 1 (ODD), CHARACTER IS OK, RETURN SETB PARITY_FLAG ;PARITY IS EVEN, SO SET ERROR FLAG PARITY4: RET ;RETURN ERROR: ;THE READ ERROR ROUTINE IS ENTERED AT THIS POINT.
17
Page 22
I/O Interface for TTL Magnetic Stripe Readers
INSERTION READERS While it is possible for the card reader to read data on either the insertion or withdrawal stroke, it should be noted that card reading is most reliable during the card withdrawal stroke. For this reason MagTek recommends that customer’s software be designed to emphasize data capture during the card withdrawal stroke. For the most reliable operation: 1.
Read the card upon insertion. When the card hits the backstop (Card Present will go high), check the data for errors.
2.
If the data contains no errors, output that data, start sentinel first, after the card has been withdrawn.
3.
If an error was detected, clear that data and get ready to read the card again upon withdrawal.
4.
After the card is removed (Card Present will go high), check the data for errors.
5.
If no errors are found, output that data, start sentinel first.
6.
If an error is detected, indicate to the host that an error was detected, indicate to the customer to insert the card again.
18