10_Lab11_supplement_card_reader

10_Lab11_supplement_card_reader - Magnetic Card Reader...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Magnetic Card Reader 王宜楷 國立交通大學電機與控制系 1 XAC 手刷式讀卡頭 黑線是VCC CLS要接地,板子要接8254的card reader 2 XAC 手刷式讀卡頭規格 可讀取 ISO7811/2 規格的磁卡 (如信用卡、提 可讀取 款卡) 刷卡速度: 5 ~ 60 IPS (Inch Per Second) 刷卡速度: 使用電源:DC +5V ± 10% 使用電源: Pin Assignment : Pin 1 : Vcc Vcc 2 : GND GND 3 : CLS Card Loading Signal CLS 3 XAC 手刷式讀卡頭規格 手刷式讀卡頭規格 Pin Assignment : Pin 4 : RCP2 RCP2 5 : RDP2 RDP2 6 : RCP1 RCP1 7 : RDP1 RDP1 4 : RCP3 RCP3 5 : RDP3 RDP3 Reading Clock Pulse (Track 2) Reading Data Pulse (Track 2) Reading Clock Pulse (Track 1) Reading Data Pulse (Track 1) Reading Clock Pulse (Track 3) Reading Data Pulse (Track 3) 4 XAC 手刷式讀卡頭規格 Time Diagram Time CLS RCP RDP Data 1 1 0 1 5 Magnetic Stripe Card Standard Track 2 Character Set: Track BCD 4-bit Character Set plus Parity BCD Bits Bits P b4 b3 b2 b1 Character P b4 b3 b2 b1 Character 1 0 00 0 0 1 0 00 0 0 0 0 00 1 1 0 0 00 1 1 0 0 01 0 2 0 0 01 0 2 1 0 01 1 3 1 0 01 1 3 0 0 10 0 4 0 0 10 0 4 1 0 10 1 5 1 0 10 1 5 1 0 11 0 6 1 0 11 0 6 0 0 11 1 7 0 0 11 1 7 Bits Bits P b4 b3 b2 b1 P b4 b3 b2 b1 0 1 00 0 0 1 00 0 1 1 00 1 1 1 00 1 1 1 01 0 1 1 01 0 0 1 01 1 0 1 01 1 1 1 10 0 1 1 10 0 0 1 10 1 0 1 10 1 0 1 11 0 0 1 11 0 1 1 11 1 1 1 11 1 Character Character 8 8 9 9 Start Sentinel Start Sentinel Separator Separator End Sentinal End Sentinal 6 Magnetic Stripe Card Standard Track 2 Data Format: Track SS PAN FS Additional Data ES LRC SS : Start Sentinel Hex B (1011) SS FS : Field Sentinel Hex D (1101) FS ES : End Sentinel Hex F (1111) ES PAN : Primary Acct. No. (19 digits Max.) PAN LRC : Longitudinal Redundancy Check Character LRC 7 硬體接線: 硬體接線: Vcc 1 RCP2 INT0(P3.2) MCS-51 P2.0 P1.0 4 5 RDP2 MAGNETIC CARD READER 2 8 程式: 程式 OVERFLAG REG STARTFLAG REG 10H 11H .symbols on ORG 00H JMP START ; INTO interrupt vector ORG 03H JMP READDATA 9 START: LOOP: DATAOK: ORG 50H CLR CLR CLR MOV OVERFLAG STARTFLAG P1.0 R0,#05H MOV MOV SETB R1,#40H IE,#10000001B IT0 JNB OVERFLAG,LOOP SETB P1.0 JMP $ ;傳送結束判斷旗標 ;字元開始旗標 ;P1.0 接LED 一開始滅 一開始滅 ;R0 紀錄傳入 bit 數 紀錄傳入 ;data : 5 bits ;存放 data 啟始位址 啟始位址 ;EA=1 ,EX0=1 ;初始設定 1->0 觸發 觸發 ;OVERFLAG=0 表未送 表未送 ;完,LOOP等待 ;LED ON & WAIT RESET 10 10 ;INTERRUPT SERVICE ROUTINE READDATA: JB STARTFLAG,DIN DIN: SETHIGH: SETLOW: JNB P2.0,DIN RETI ;SRATRFLAG !=0 ;表示已經不是第一筆 ;data, 則直接跳DIN 則直接跳 ;P2.0=0 表 data 開始 開始 ;P2.0=1 結束中斷程式 結束中斷程式 SETB STARTFLAG JNB P2.0,SETHIGH JMP SETLOW ;資料正傳遞中 ;P2.0=0,data = 1 ;P2.0=1,data = 0 SETB A.0 JMP JUDGE ;A.0=1 CLR ;A.0=0 A.0 11 11 JUDGE: BACK: JUDGE1: BACK1: DJNZ R0,BACK JMP JUDGE1 ;R0<>0 表示沒抓完 表示沒抓完 ;R0=0 表示DATA OK 表示 RR A RETI MOV R0,#05H SWAP A MOV @R1,A INC R1 CJNE A,#0DH,BACK1 SETB OVERFLAG ;RESET R0 COUNTER ;A翻轉為正確DATA ;放值到相對位置 ;R1+1 RETI 12 12 Start 流 程 圖 OVERFLAG=0 STARTFLAG=0 P1.0=0 (LED OFF) R0=5 (bit counter) R1=40H (start address) IE=10000001B IT0=1 (edge trigger) 0 OVERFLAG 1 P1.0=1 (LED ON) JMP $ 13 13 Interrupt 1 流 程 圖 STARTFLAG 0 STARTFLAG=1 1 P2.0 A.0=0 =0 1 0 P2.0 1 RETI 0 A.0=1 R0=R0-1 ≠0 RR A RETI 14 14 流 程 圖 1 R0=5 SWAP A MOV @R1,A R1=R1+1 yes OVERFLAG=1 A=“0DH” no RETI RETI 15 15 ...
View Full Document

Ask a homework question - tutors are online