230 likes | 504 Views
Swipe Card Reader w/ Liquid Crystal Display. Embedded Systems Interfacing Laboratory. Overview. Background Task 0 – Clean Up Motor Feedback Lab Task 1 -- Understand Data Stream w/ MSO Task 2 -- Basic ISR w/ Strobe Count and Ones Count Task 3 -- Capture Data with ISR
E N D
Swipe Card Reader w/ Liquid Crystal Display Embedded Systems Interfacing Laboratory
Overview • Background • Task 0 – Clean Up Motor Feedback Lab • Task 1 -- Understand Data Stream w/ MSO • Task 2 -- Basic ISR w/ Strobe Count and Ones Count • Task 3 -- Capture Data with ISR • Task 4 -- Decode, check, and display data/errors
MCR-175-1R Swipe Card Reader Color Signal Explorer-16 BLACK GROUND Vss RED +5V Vdd YELLOW /CARD DETECT RD14 BLUE /DATA RE9 GREEN /STROBE RE8
Task 1 -- Start Sentinel RTZ Encoding 1 2 4 8 P 1 2 4 8 P 1 2 4 8 P 1 2 4 8 P 1 2 4 8 P 1 2 ‘6’ 2 ‘B’ Remember data comes in one bit at a time (per interrupt).
Task 1 -- End Sentinel 1 2 4 8 P 1 2 4 8 P 1 2 4 8 P No Ones CHAR LRC ‘F’
Task 1 -- Encoded Data 6221100…52
Task 2 -- Basic Interrupt Service Routine Template void __attribute__((interrupt,no_auto_psv)) _INT1Interrupt(void) { INT1IF=0; // insert code here } void main(void){ //Initialize ports & interrupt enable bits endless: // Process // Display stb_cnt on bargraph; goto endless; }
Task 2 -- initSwipe • Card detect as input • Data as input • INTCON2bits.INT1EP=? • IFS1bits.INT1IF=0 • IEC1bits.INT1IE=1 • Optional IPL • _IPL < _INT1IP
Task 3 -- Capture Data ERROR LEAD- ING First One CHARAC- TER CD default “00000” NEW STROBE Conversion Complete TRAIL- ING DECODE
Task 3 – STATE_TYPE enum STATE_TYPE {NEW,LEADING,CHARACTER,TRAILING,DECODE,ERROR}; enum STATE_TYPE state=NEW; unsigned char bit_cnt=0; unsigned char char_cnt=0; unsigned char one_cnt=0; unsigned char character; unsigned char buffer[40];
Task 3 -- Switch Statement ••••• switch(state){ case NEW: ••••• break; case LEADING: ••••••• default: state = ERROR; } You write CHARACTER state code
Task 4 -- Parity & LRC Hex Binay Value Value WithoutWithout P 8 4 2 1 Parity Parity Start Sentinel: B 0 1 0 1 1 B 1 0 1 1 1 0 0 0 0 1 1 0 0 0 1 2 0 0 0 1 0 2 0 0 1 0 3 1 0 0 1 1 3 0 0 1 1 End Sentinel: F 1 1 1 1 1F 1 1 1 1 LRC 4 0 0 1 0 0 4 0 1 0 0 0 0 0 0 0 Odd Parity Even Parity Easier yet bitwise “exclusive-or” all including LRC = 0
Task 4 -- Mainline • Display the message “Swipe card…” on first line of LCD • Wait for state to go to DECODE. • Clear display • Display data buffer on first and second line of LCD • Display one of the following on the bargraph • “No errors…” • “Start error…” • “Parity error…”
Task 4 -- Mainline Continued • “Stop error…” • “LRC error…” • Prepare for next card swipe by setting state to NEW. • You can do the four error checks in main or the interrupt service routine.