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.
Previous article:Using a single chip microcomputer to control the LED on and off
Next article:Design of frequency characteristic tester based on AT89C52
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Understand the performance test of 18650 lithium battery - cycle test
- Sinlinx A64 Linux writes LED driver through device tree (with reference code, not tested)
- EEWORLD University Hall--Analysis of rules and techniques for high-speed PCB design
- LMV321 power supply range problem
- [SAMR21 New Gameplay] 29. WS2812 Application - Rainbow
- Several filtering methods for single chip microcomputer to resist interference by software
- What do you think of Huawei HiSilicon's operation?
- Problems encountered when LCD1602 scroll screen display
- Summary of the differences between SPMSM and IPMSM
- How did I get 296g of energy from Alipay Ant Forest?