Contactless IC card (also known as radio frequency card) is a new technology developed abroad in recent years1. It successfully combines radio frequency identification technology and IC card technology to solve the problem of passive and free Contact Difficulties. The RF card does not require a special power supply; there is no mechanical contact between it and the reader, avoiding contact failures; there are no exposed chips on its surface, it is waterproof, and it is not prone to problems such as electrostatic breakdown and bending damage; there is no problem when using the RF card Positive and negative. In short, contactless IC cards have the characteristics of high reliability, easy use, and fast operation. This article uses non-contact IC card to successfully develop an intelligent prepaid electricity meter.
1 Working Principle
1.1 Working Principle of Contactless IC Card
The contactless IC card system consists of a reader/writer and a contactless IC The card consists of two parts. The application system operates the card through the reader and writer; the card reader communicates with the card at short distance through radio frequency signals and provides energy to the chip on the card; the non-contact IC card responds to the instructions of the reader and writer and reports the processing results. The non-contact IC card obtains high-voltage energy by coupling the coil connected to the IC chip in a specific alternating magnetic field, and then obtains DC current through rectification, thereby obtaining the operating voltage and current. The reader/writer of the non-contact IC card emits an alternating strong magnetic field through the transmitting coil, giving energy to the IC card, writing data through the intermittent and continuous encoding of the magnetic field, and reading the data sent by the IC card through the coil sensing the magnetic field emitted by the IC card. ; The IC card obtains energy through the alternating magnetic field, obtains the data written by the read-write head by checking the discontinuity and continuation of the magnetic field, and encodes and modulates the data according to the set pattern to send the data to the read-write head.
This system uses the SHC1701 RF read-write module developed by Shanghai Huahong Integrated Circuit Company. It is mainly composed of radio frequency and SHC1501 large-scale integrated circuits. It is installed on the PCB board at the same time, and a shielding cover is installed at the same time. It can complete various interactive functions between the reader and the IC card, including modulation/demodulation and encryption. /Decryption, authentication, reading and writing, addition/subtraction, etc., and has an interface with the microprocessor. Its basic structure is shown in Figure 1. The communication content between the contactless IC card and the reader includes reset response, anti-collision, card selection, mutual authentication, operation of data blocks and suspension.
1.2 The working principle of prepaid electricity meters
Prepaid electricity meters can be divided into two types: electronic and electromechanical. The difference between them lies in the different electric energy conversion components. The former performs A/D conversion of voltage and current, and then multiplies and accumulates the sampled values ??to obtain the number of electricity consumed by the user; the latter borrows the movement of the original induction meter and reads the number of turns of the turntable through a photoelectric sensor to obtain the user's electricity consumption. The amount of electricity consumed. In order to save costs, an electromechanical watt-hour meter is selected.
This system uses AT89C52 as the host, and installs a pair of infrared transmitting and receiving tubes on the original ordinary single-phase electricity meter to count the number of turns of the turntable. The host completes the recording, accumulation, and calculation of the user's power consumption. Display and control functions. Equipped with a contactless IC card, it completes the conversion of currency degrees and the information transmission of electricity quantity from the power supply management department to the user.
The working principle of this system is:
1. When a user brings an IC card to the power supply department to pay for electricity, the power supply department places the user's IC card in a reader connected to the PC. On the writer, the card writing program writes a certain amount of electricity that matches the amount paid by the user on the IC card.
2 The user takes the IC card home and swipes the card over the reader-writer of the prepaid electricity meter at home. The electricity in the card is read by the host and is compared with the original remaining energy in the prepaid electricity meter. Degrees are added. Since the machine uses a backup battery, there is no fear of data loss due to power outage.
3. When the electric meter dial rotates, the infrared transmitting and receiving tube converts the dial number into electrical pulses and sends them to the microcontroller. The microcontroller records the number of revolutions of the dial. When the number of revolutions is equal to the meter constant, the remaining electricity in the memory is subtracted by one degree under the control of the microcontroller.
4. The microcontroller monitors whether the remaining electricity in the memory is less than 15 degrees at any time. If so, the LED indicator will light up to warn that the power consumption is about to be exhausted, prompting the user to take the card to the power supply department to purchase electricity again.
5 When the microcontroller finds that the remaining power in the user's meter is completely used up, the control relay cuts off the user's power supply.
6 The electronic card is configured according to one table and one card, and the memory contains the corresponding card number and user number, as well as the transmission key of the IC card. When the user puts the IC card on the reader-writer of the power supply department, the PC writes the purchased electricity for the user, records the card number, date and corresponding amount, and writes them into the database, so that the power supply department The user's electricity purchase status can be queried on the PC at any time, realizing the management modernization of the power supply management department.
7. The system uses VB communication control to communicate with the microcontroller through RS232. The microcomputer realizes the control of the microcontroller through pre-agreed characters. For example, the management center of the community regularly reads the used electricity and remaining electricity of the user's electricity meter through the RS232 serial communication port, and makes a database for storage. The power supply department can access and manage the data collected by the community through the Internet, thereby realizing a networked management method for the power supply management department.
8 This device is a secondary instrument, and its accuracy mainly depends on the primary instrument. As long as the dial rotates normally, the secondary instrument will not introduce errors.
2 Hardware circuit
The hardware circuit structure diagram of the non-contact IC card prepaid electricity meter is shown in Figure 2. The main control unit in the picture uses AT89C52 microcontroller, which has 8K bytes of flash memory (FLASH) and does not require external program memory (EPROM). External circuits mainly include: four-digit LED display circuit, electric meter dial detection circuit, relay circuit for controlling power supply, ringing control circuit, RS232 serial communication circuit, watchdog reset circuit, power control circuit and non-contact IC card control circuit SHC1701 read and write module.
The SHC1701 RF module is the core unit of the IC card reader and writer. It consists of the SHC1501 dedicated circuit and RF circuit, etc., covering all access operations to the non-contact IC card SHC1101. The interface between the IC card read-write module and display circuit and the microcontroller is shown in Figure 3. In the figure, a 4-digit positive anode dynamic digital display tube is used. The display characters are sent from the P0 port of the microcontroller to the latch 74LS374 for latching, and then the display driver chip ULN2003 drives the digital tube display, and P1.0~P1.3 controls them respectively. Dynamic display of each bit. The display circuit is used to display the available electricity. When an error occurs while reading the card, an error message will be displayed. When making a deposit at the power supply department, the amount of electricity stored in the electricity card will be displayed.
The pulse signal generated by the electric meter turntable reading head (infrared transmitting and receiving tube) is output to the P1.4 port of the microcontroller through a NOT gate, and the microcontroller monitors the P1.4 port in real time.
The RS232 serial communication circuit uses the MAX232 chip to realize data exchange between the microcontroller and the microcomputer. The microcomputer mainly uses VB communication control to communicate with the microcontroller through RS232, and controls the microcontroller through pre-agreed characters.
When the electricity in the machine is used up, the microcontroller sets port P1.5 to low level, and the relay control circuit cuts off the user's power supply.
The watchdog circuit is composed of a 4538 monostable circuit. When initially powered on, the CLR terminal is low, causing the output Q to be low, thereby resetting the system. During normal operation, the microcontroller emits a low-level pulse during each main program cycle to trigger the monostable; when the program is disturbed and runs away, the monostable is reset because it cannot obtain the trigger pulse. At this time, the output terminal Q=0 , to reset the system
The ringing control circuit consists of a buzzer, two transistors and a resistor. When the P1.7 terminal of the microcontroller sends a high level, the buzzer is triggered. In order to ensure that the system can work normally during a power outage, two sets of power supplies are used to power the system. One set is to transform, rectify and stabilize the 220V/50Hz mains power to obtain 5V DC power, and the other set is to obtain 5V DC power from the 12V/4A convertible power supply. The rechargeable battery obtains 5V DC power through chopping, voltage reduction and voltage stabilization. It is generally powered by mains power and charges rechargeable batteries. When the mains power fails, it is powered by the battery. The 12V/4A rechargeable battery can make the system work continuously for more than 24 hours.
3 Software Design
The program of this non-contact IC card prepaid electricity meter adopts a modular design. The entire system consists of the user-side electricity meter billing program and power supply. It consists of two parts: department deposit and management procedures. Each part of the program is composed of two parts: the microcontroller system program and the VB user interface program. The microcontroller program and the VB program use VB's communication control MSComm to communicate through RS232. The communication protocol uses query commands based on ASCII codes and interrupts to send and receive characters. The microcomputer controls the microcontroller through pre-agreed characters, and the microcontroller executes different microcontroller subroutines by judging different characters sent by the microcomputer. 3.1 User-side electricity meter billing program
3.1.1 Main functions of the microcontroller system program
(1) Reading valid non-contact IC card function. Perform anti-collision, password authentication, card number authentication and other operations on the card, read out the data stored in the card, and then clear the card and stop it.
(2) Complete the pre-charging function of the electricity meter. The electrical energy read out from the IC card is added to the remaining electrical energy in the memory of the microcontroller and stored back into the memory.
(3) Display function. The system scans periodically and dynamically displays the remaining electricity in the machine. In addition, when an error occurs in reading or writing the IC card, an error message is displayed.
(4) Serial communication interruption function. When the microcomputer sends a collection command to the microcontroller, the microcontroller executes the serial communication interrupt service subroutine. After passing the user number authentication, it sends back the user's power consumption and remaining power to the microcomputer, and then interrupts and returns.
(5) Electricity counting function. The system monitors the pulse signal from the meter turntable reading head (infrared transmitting and receiving tube) in real time. When the pulse signal changes from high level to low level, the counter COUNT increases by 1; and when the COUNT value is equal to the meter constant (rev/degree) , the remaining electricity quantity is decreased by 1, the electricity consumption is increased by 1, and COUNT is cleared at the same time.
(6) Alarm power-off function. When the remaining electricity in the machine is less than 15 kilowatt-hours, the LED indicator will light up to warn that the electricity consumption is almost exhausted, prompting the user to take the card to the power supply department to purchase electricity again. When the remaining power in the user's meter is completely used up, the control relay cuts off the user's power supply. Users can only continue to supply power after depositing the electricity consumption again.
The microcontroller system program consists of the main monitoring program, IC card processing subroutine, energy counting subroutine, serial interrupt service subroutine, etc. The block diagrams are shown in Figure 4a, b, c, and d respectively.
3.1.2 Main functions of VB user interface program
(1) Display. According to the entered user number, the corresponding user information is displayed.
(2) Collection. The user number is sent to the microcontroller through the communication control. After the microcontroller authenticates the user number, it returns the user's power consumption and remaining power.
(3) Write. The collected data, plus the user number and date, are written into the database for query.
(4) View. View the electricity consumption and remaining electricity consumption of each user in the current month; view all electricity usage.
3.2 Deposit and management procedures of the power supply department
3.2.1 Main functions of the single-chip computer system program
(1) System initialization settings. Set the register address, interrupt source entry, load the IC card authentication password, and set the working mode of the serial port, timer 0 and timer 1, etc.
(2) Receive control characters sent from the microcomputer. Execute the serial interrupt service subroutine. If the control character is R, perform card inquiry, anti-collision, card selection, authentication and other operations on the IC card, and return the card number to the microcomputer; if the control character is W, the number of electricity purchased by the user will be Write the IC card, then read the written electricity number, and then stop the card.
(3) Display function. Displays the electricity quantity stored in the IC card. When there is any error during the operation of the IC card, an error message will be displayed to prompt the user.
The program consists of the main monitoring program and the serial interrupt service subroutine. Their block diagrams are shown in Figure 5a and b.
3.2.2 Main functions of VB user interface program
(1) IC card deposit function. The user takes the card to the power supply department to make a deposit. The staff puts the card on the reader and writer and presses the "read card" button. The microcomputer sends the character "R" to the microcontroller. The microcontroller executes the corresponding interrupt processing and returns the card number. The system returns the card number based on the returned card number. The corresponding user information is displayed. After confirming that it is correct, the amount paid by the user is entered, and the system automatically converts it into the amount of electricity. Press the "Deposit" button to store the amount of electricity into the IC card, and at the same time, the relevant information of the deposit is written into the database for future reference. Query.
(2) Query function. To query user information, IC card information and the user's electricity consumption, you can selectively query based on the entered user number or electricity card number.
(3) Maintenance function. Maintenance of the database includes adding new records, deleting unnecessary records, and updating existing records. The database used in this system is established by MSAccess and is associated with the user interface through VB's data object control. All operations on data update the associated database in real time.
This article combines contactless IC card technology with computer technology to develop a multi-functional electricity metering and charging device. This system realizes the electronic charging of electricity, changes the unreasonable situation of charging first after using electricity, and promotes the scientific management of electricity metering and charging. This device utilizes the functions and structure of the old mechanical watch, reduces the cost of modification, and is suitable for popularization and use.