Application design of contactless bus IC card reader

Publisher:平和宁静Latest update time:2014-11-10 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Overview of IC Card Reader

  There are two types of IC cards that are often used at present: contact IC cards and contactless IC cards. Contact IC cards obtain energy and exchange data from the reader through mechanical contacts; contactless IC cards obtain energy and exchange data from the reader through coil radio frequency induction, so they are also called radio frequency cards. Contact IC cards are currently the most common in society. They have a large storage capacity (in megabytes), strong confidentiality functions (multiple password settings and authentication functions), and can achieve multiple uses of one card. However, the reading and writing operation speed of this type of card is slow and inconvenient to operate. Each time you read and write, you must correctly insert the card into the slot of the reader to complete the data exchange. This is very inconvenient in occasions such as public transportation and attendance where frequent card reading and writing are required. In addition, the contacts of the reader and the contact pins of the IC card on the card are exposed to the outside, which is easy to be damaged and dirty, resulting in poor contact.

  Contactless IC card is produced based on the principle of radio frequency electromagnetic induction. Its reading and writing operation only requires placing the card within a certain distance near the reader/writer to realize data exchange, without any contact. It is very convenient and fast to use and not easy to be damaged. Therefore, it has a wide range of application prospects in public transportation, access control, campus, personnel management of enterprises and institutions, entertainment venues, etc. At present, the radio frequency IC cards introduced in my country mainly include Mifare of PHILIPS and Temic card of ATMEL. The following introduces the implementation method of automatic ticket IC card reader/writer for urban public transportation, mainly based on Mifare card of PHILIPS.

2. Working Principle

  The contactless IC card reader is based on radio frequency identification technology. The reader mainly uses a Mifare card-specific read/write processing chip - MMM micromodule. It is a core device of a small Mifare read/write device with a maximum operating distance of 20 to 30 mm. Its functions include modulation, demodulation, generation of radio frequency signals, security management and anti-collision mechanism. The internal structure is divided into a radio frequency area and an interface area: the radio frequency area contains a modem and a power supply circuit, which is directly connected to the antenna; the interface area has a port connected to the single-chip microcomputer, a transceiver connected to the radio frequency area, a 16-byte data buffer, a ROM for storing 64 pairs of transmission keys, a write-only memory for storing 3 sets of keys, a cipher machine for three verifications and data encryption, an anti-collision module for anti-collision processing and a control unit. This is the core module for wireless communication with radio frequency cards, and is also the key interface chip for the reader to read and write Mifare cards. When the reader is working, it continuously emits a set of electromagnetic waves of fixed frequency (13.6MHz). When a card approaches, there is an LG series resonant circuit in the card, whose frequency is the same as the transmission frequency of the reader. In this way, under the stimulation of the electromagnetic wave, the LG resonant circuit resonates, thereby charging the capacitor. At the other end of this capacitor, there is a unidirectional conductive electronic pump that sends the charge in the capacitor to another capacitor for storage. When the capacitor is charged to 2V, this capacitor acts as a power supply to provide working voltage for other circuits on the card, transmits the data in the card or receives and saves the data sent by the reader.

3. Hardware Composition

  The bus fare collection system has a complex structure and many links. Therefore, the bus contactless IC card reader should include at least three readers: bus card vending machine, bus onboard machine and bus card making machine. Except for the card vending machine requiring a keyboard, the rest of the hardware components are roughly the same. Figure 1 is a schematic diagram of the contactless IC card and its reader hardware circuit, which mainly consists of MMM micromodule, single chip microcomputer, keyboard, display, memory, antenna and monitoring circuit, and TC232 serial communication interface circuit for communicating with PC.
 

(1) Single chip microcomputer system

  The single-chip microcomputer uses 89C52. It has 8KB of ROM, 256 bytes of RAM and 32 I/O ports. Port P1 is connected to the serial device 24C64 and the display and alarm circuits; port P0 is connected to the MMM micromodule and used as a data line; port P2 is used as a 4×4 keyboard; port P3 is used for read-write control and interrupts.

(2) Keyboard circuit

  The keyboard interface circuit uses the P2 port to form a 4×4 structure, with a total of 16 keys. Among them, there are 10 numeric keys, 2 function keys, 1 backspace key and 1 enter key, and 2 keys are temporarily unused. The function keys include query and communication keys.

  Query key: Card salespersons can use this key to query the card sales amount and number of card sales records.

  Communication key: Since the storage capacity of the reader is limited, the data in the reader should be communicated with the PC through the RS-232 serial interface every time the card is sold, so as to play back and clear the data in the reader. After the data is played back to the PC, it is analyzed and processed to form various reports so that the bus company can grasp the card sales situation in a timely manner.

(3) Display circuit

  The display part adopts digital display, and uses the serial input BCD code-decimal decoding to drive the display device MC14499 to complete the display interface with the single-chip computer system to display the working status of the reader, the input data or the remaining and error information in the read IC card. This device mainly has a 20-bit shift register, a latch, and a multiplexer. The BCD code output by the multiplexer is decoded by the segment decoder, and then converted into a seven-segment code (abcdefg) and a decimal point DP and sent to the segment driver output.

(4) Memory

  The memory is designed in the reader. The memory uses the 24CXX series serial E2PROM. The card number, card salesperson number, card sales amount, card sales date, total card sales amount and total number of card sales records are mainly stored in the card vending machine; the passenger IC card number, driver number and total number of card swipes are mainly stored in the on-board machine. The display uses MC14499 to drive a 4-bit common cathode digital tube. After normal operation, the reader must be taken to the bus management center at regular intervals to play the information stored in the reader back to the PC for storage and processing. The memory in the reader can use 24C64, which has a storage capacity of 8KB. If necessary, a larger capacity memory such as 24C128 or 24C256 can also be used.

(5) Monitoring circuit

  The monitoring circuit uses the DS1232L chip. It is a watchdog timer, and its functions are: generating a RESET signal to the 89C52 when power is on or off; the watchdog monitors the system to prevent crashes. [page]

(6) Contactless IC card

  The contactless IC card uses Mifare card. Its working frequency is 13.6MHz, and the storage capacity is 1KB divided into 16 zones, with 2 sets of passwords in each zone. The storage area of ​​each zone is independent of each other, so each zone can be used for one purpose (the 0th zone is generally not used) to achieve multiple uses of one card. Due to the strict password verification mechanism of Mifare card, the stored information is relatively reliable and safe, and can be erased and written tens of thousands of times.

  Mifare card has 16 zones, each zone is divided into 4 blocks, each block is 16 bytes. In the card vending machine, zone 1 is used as the user stored value block, where block 0 stores the identity number, blocks 1 to 2 store the value, and block 3 stores two sets of 6-byte passwords and 4-byte read and write access conditions.
 

4. Programming

  The following introduces the software design method mainly based on the card vending machine.

  Considering the safe management of the card sales amount, the bus company must prepare two kinds of IC ticket cards in advance: one is the user IC ticket card, and the other is the ticket IC card for the card seller. The two cards can use the same area code, but the passwords and access conditions are completely different and will not be confused. When the card seller wants to sell the card, he must first go to the bus company to apply for a ticket IC card before he is qualified to sell the card. The ticket IC card stores the card seller's identity number, the maximum amount allowed for card sales, two sets of 6-byte passwords and 4-byte read and write access conditions. When the card seller sells the card, each recharge must subtract the card sales amount from his own ticket IC card and add it to the user's IC card. When the ticket IC card amount is reduced to zero, he must go to the bus company to settle the bill and then record the recharge of the ticket IC card. In this way, the bus company's card sales outlets can be distributed more and not chaotic, and it can also facilitate users to recharge and add cards, which can effectively prevent the loss of funds caused by unclear accounts of ticket sellers. The program mainly includes IC card reading and writing operation program, keyboard scanning program, display program, memory reading and writing program and communication program.

1. Main program

  The main program mainly completes the initialization of system variables, cyclically scans the keyboard, detects the operation of IC cards, and stores and displays the operation results. The 8KB 24C64 is used as a memory in the card vending machine. The main storage contents are: card vending machine number (1 byte), total amount of card sales (3 bytes) and total records (2 bytes). The record of each card sold contains: user card ID (4 bytes), card sale date (2 bytes), card addition amount (1 byte) and card seller number (1 byte). Therefore, a maximum of 1023 card sales records can be stored. The main program flow is shown in Figure 2, and the reader-writer operation flow of the IC card is shown in Figure 3.
 

 

 2. Keyboard Scanner

 

  The keyboard scan uses the inversion method to read the keys: first output zero level from the high 4 bits of port P2, and read the keyboard status from the low 4 bits of port P2; then output zero level from the low 4 bits of port P2, and read the keyboard status from the high 4 bits of port P2. Combining the results of the two reads can get the feature code of the current key (see the TABLE in the program). With this table, you can program and convert them into sequential codes. Use the currently read feature code to sequentially look up the table, and use a unit to record the number of searches. When the feature code is found in the table, its position (that is, the number of searches) is the corresponding sequential code. The corresponding keyboard key search program is as follows:

KEY: MOV P2,#0FH ;Use the inversion method to check the keyMOV
A,P2
ANL A,#0FH
MOV B,A
MOV P2,#0F0H
MOV A,P2
ANL A,#0F0H
ORL A,B
CJNE A,#0FFH,KEY1
RET ;No key is pressedKEY1
: MOV B,A ;A key is pressed, store the key codeMOV
DPTR,#TABLE
MOV R3,#0FFH ;Initialize the storage sequence code
unitKEY2: INC R3
MOV A,R3
MOVC A,@A+DPTR
CJNE A,B,KEY3 ;Judge the key code and find the sequence
codeMOV A,R3 ;If the key code is found, store the sequence codeRET
KEY3
: CJNE A,#0FFH,KEY2 ;Judge whether the search is completedRET
;The search is completed, but the key code is not found, and it is processed as no key is pressedTABLE
: DB 77H,7BH,0BBH ;Key feature code
tableDB 0DBH,7DH,0BDH
DB 0DDH,7EH,0BEH
DB 0DEH,0B7H,0D7H
DB 0EEH,0EDH,0EBH
DB 0E7H,0C7H,0FFH

3. Display Program

  According to Figure 1, in the display circuit, the three I/O lines (P1.0, P1.1, P1.2) of the P1 port are used to provide the clock signal (CLK), serial data (DA) and enable signal (EN) respectively. MC14499 can receive 20 bits of serial input data each time. The first 4 bits are used to control the decimal point display of the digital tube, and the last 16 bits are the BCD code input data of the 4 digital tubes. Before each frame of data is transmitted, EN must be set to 0; then 20 bits of data are transmitted, and after the data is transmitted, EN is set to 1. The display program is as follows:

DISP: CLR P1.0 ; Clear CLK
CLR P1.2 ; Clear EN
MOV R2,#04 ; Set the number of bits to be transferred
MOV A,#00
LCALL W14499 ; Display the transferred number
MOV A,@R1 ; Read the number to be displayed
MOV R2,#08 ; Set the number of bits to be transferred
LCALL W14499
INC R1
MOV A,@R1
MOV R2,#08 ; Set the number of bits to be transferred
LCALL W14499
SETB P1.2 ; Set EN bit
RET
W14499: SETB P1.0 ; Clear CLK
RLC A ; Prepare to display the number bit by bit
MOV P1.1,C ; Move the number into DA
CLR P1.0 ; Clear CLK
DJNZ R2,W14499
RET


4.Serial E2PROM reading and writing procedures

  24C64 is an E2PROM of I2C bus. SCL is a 400kHz clock line, SDA is a bidirectional data line, A2, A1, A0 are chip select addresses, that is, up to 8 serial E2PROM chips can be connected in parallel on the I2C bus. The operation mode of E2PROM is determined by the read-write control command word, as shown in Figure 4. Among them, "1010" is a 4-bit read-write control code, R/W is the read-write control bit: "0" is a write operation, and "1" is a read operation. Therefore, combined with Figure 1, it can be seen that A2H is a write control command word, and A3H is a read control command word. [page]
 


  For memory write operation, first, the microcontroller sends a START command to 24C64 to generate a start condition. Then, send a write command control word (such as A2H). When 24C64 receives the command, it enters a write cycle, and then the microcontroller sends the storage address, that is, determines which address the data is written to the memory. Subsequently, the microcontroller sends the data to be stored to the SDA data line. At the end of the write cycle, the microcontroller sends a stop bit (STOP).

  For memory read operations, first, the microcontroller sends a START command to 24C64 to generate a start condition. Then it sends a write command control word (such as A2H). When 24C64 receives the command, it enters a write cycle, and then the microcontroller sends the storage address. After the storage address is successfully sent, the microcontroller sends another START command to 24C64 to generate a start condition, and then sends a read command control word (A3H). When 24C64 receives the command, it enters a read cycle, and the microcontroller reads the data in the specified storage address from the SDA data line. At the end of the read cycle, the microcontroller sends another stop bit (STOP). (Program omitted)

  It is worth noting that when operating the memory, each time a byte is read or written, the microcontroller must send an acknowledge bit (ACK) to release the SDA data line so that the memory can continue to receive data.

5. Communication Procedures

  In the reader/writer, the communication between the single-chip microcomputer and the PC is mainly realized by TC232 to realize the conversion between TTL level (0~5V) and RS232 level (+10~-10V) (see Figure 1 for the circuit) to complete the transmission of the card sales record saved by the card vending machine. The communication format is set as: serial working mode 1, baud rate 9600baud, 1 start bit, 8 data bits, 1 stop bit, and checksum mode. In the reader/writer, the single-chip microcomputer program can be programmed in C language. C language has rich library functions, fast operation speed, high compilation efficiency, good portability, strong readability of software, and is easy to improve and expand (program omitted).

  In order to improve the adaptability of the public transportation system, including various special requirements of users, anti-interference, and resistance to harsh environments, in addition to the use of monitoring circuits in hardware, instruction redundancy and software traps are also adopted in software.

Reference address:Application design of contactless bus IC card reader

Previous article:Using a single chip microcomputer to control the LED on and off
Next article:Design of frequency characteristic tester based on AT89C52

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号