rfid data acquisition
TRANSCRIPT
ERG 4910B - Thesis II, 2005-2006
RFID: Data Acquisition
Author: Lee Kin Bong
Student I.D.: 02657852
Supervisor: Professor K.K. Cheng
Associate Examiner: Professor S.P. Wong
A project report presented to the Chinese University of Hong Kong
in partial fulfilment of the Degree of Bachelor of Engineering
Department of Electronic Engineering The Chinese University of Hong Kong
April, 2006
2
Abstract:
RFID, Radio Frequency Identification, is a popular technology nowadays. It will
replace the traditional bar codes soon as it have advantages on large information–carrying
capacity, physically strong, able to recognize from a distance. Most importance is it can
be completely automatic if we can solve the collision problem between tags. This can
save manpower and prevent man-made mistakes if we can achieve that.
In this project, my main job is to build up an anti-collision system between the tags and
the reader. The collision problems are due to all the tags in the environment reply and
send their own serial number to the reader. Therefore, the reader has to classify the serial
number step by step. I have successfully built up the anti-collision arbitration system on
reader side by binary tree method with the aids of the Manchester coding.
3
Acknowledgements
Special thanks to my supervisor, Professor Michael Cheng Kwok Keung (B.Sc., Ph.D.
(London), Sr.MIEEE, MIEE, CEng (IEE)), for his useful advice and support on my
project, “RFID: Data Acquisition”.
4
Content
ABSTRACT: 2
ACKNOWLEDGEMENTS 3
CONTENT 4
INTRODUCTION 6
Forward Link Encoding 9 Pulse Interval Encoding --- Type A 9 Manchester Coding --- Type B 10
Return Link Encoding 11 FM0 --- Type A and B 11
Collision Arbitration 12 ALOHA procedure --- Type A 12 Binary Tree --- Type B 12
Error Detection 13
CRC Procedure --- Type A and B 13
THEORY 15
Hardware 15 Microcontroller 16 Reset Circuit 16 Oscillator Circuit 17 Traffic control Circiut 17 Power Supply Circuit 18 RS-232 interface conversion circuit 19 Circuit Design 20 Component List 21
Software 22
Programming Principle 22
Program Flow 29 1) Reader Program 29 2) Tag Program 31
Serial Communication 32
5
EXPERIMENTAL PROCEDURE AND RESULT 40
Phase 1 --- Reader Program 41
Phase 2 --- Tag Program 45
Phase 3 --- The Anti-Collision System 47
DISCUSSION AND CONCLUSION 57
COST SUMMARY 59
REFERENCE 60
PROGRAM SOURCE CODE 61
The reader program: 61
Tag Program: 68
PHOTO OF CIRCUIT 75
APPENDIX 76
6
Introduction
Radio Frequency Identification (RFID) Systems fall into two basic categories. The
categories are broadly determined by how the tags powered, which in turn reflects the
average transponder price. The transponder categories are:
• Active RFID tags backscatter modulation (battery on board) [cost EU 10 – 40]
• Passive RFID tags backscatter modulation (RF powered) [cost less than EU 2.50]
My project is focus on the passive RFID, which is cheaper but comparably with a
shorter transmitting distance than active one. But with the backscattering technique, it can
still typically achieve 3m transmitting length, which are suitable for most of application.
Also, because of the cost and the size, passive RFID have a potential to replace the bar
code in the future.
Radar can be considered as the technology precursor to RFID. They are both using the
phenomenon of RF reflection. The radar use the time difference between the signal sent
and reflected back to calculate the distance from an object. For RFID, the reflected signal
carries importance information to the reader (e.g. the serial number of the product). This
technique is using the method of backscattering.[1]
7
Like WLAN card, we need to define the standard for the RFID to assure the
communication is universal. There are many standards for RFID, but the common use is
the ISO18000 (Information technology -- Radio frequency identification for item
management). ISO18000 divide into six parts:
ISO18000-1: Reference architecture and definition of parameters to be standardized
ISO18000-2: Parameters for air interface communications below 135 kHz
ISO18000-3: Parameters for air interface communications at 13,56 MHz
ISO18000-4: Parameters for air interface communications at 2,45 GHz
ISO18000-6: Parameters for air interface communications at 860 MHz to 960 MHz
ISO18000-7: Parameters for active air interface communications at 433 MHz
My project follows some of the requirements in ISO18000-6. According to
ISO18000-6, the RFID in to two types: Type A and Type B [2]
Table 1.1 – Comparison of Type A and Type B [2]
8
Figure 1.1 - Interrogator architecture [2]
Figure 1.2 — Type A tag architecture [2] Figure 1.3— Type B tag architecture [2]
For the protocol of reader, there is some points importance:
1) Forward Link Encoding
2) Return Link Encoding
3) Collision arbitration
4) Error Detection
9
Forward Link Encoding
Pulse Interval Encoding --- Type A
Because this coding has the short pulse duration, it can give continuous power
supply. As a result, it is mainly use in Reader to Transponder.
Original Data Signal Sent
Logic 0 A pulse of duration 2t before next pulse
Logic 1 A pulse of duration t before next pulse
Table 1.2a --- Logic table of Pulse Interval code
Figure 1.4a --- Pulse symbol represent different logic
10
Manchester Coding --- Type B
The Machester code is often used for data transmisson from the transponder to the
reader based upon load modulation using a subcarrier. [3] The princple of signal coding is
stated at below table:
Value Sent
Logic 0 0 to 1 (upward transition at bit centre)
Logic 1 1 to 0 (downward transition at bit centre)
Table 1.2b --- Logic table of Manchester code
For example:
Figure 1.4b --- Encoding of 11011000100 in Manchester code
11
Return Link Encoding
FM0 --- Type A and B
FM0 is usually used for the signal receiving. The level is inverted at the start of every bit
period, so that the bit pulse can be more easily reconstructed in the receiver if necessary.
The princple of signal coding is stated at below table:
Value Sent
Logic 0 Changing pulse(“1 to 0” or “0 to 1”)
Logic 1 Constant Pulse
Table 1.3 --- Logic Table for FM0
For example:
Figure 1.5 --- Encoding of 10110001 in FM0
12
Collision Arbitration
ALOHA procedure --- Type A
This is method using the technique of Carrier Sense Multiple Access. The procedure is
used exclusively with read-only transponders, which generally have to transfer only a
small amount of data (serial numbers), this data being sent to the reader in a cyclical
sequence. The data transmission time represents only a fraction of the repetition time, so
there are relatively long pause between transmissions. Furthermore, the repetition times
for the individual transponders differ slightly. There is therefore a certain probability that
two transponders can transmit their data packets at different times and the data packets
will not collide with one another.
Binary Tree --- Type B
The binary tree method uses the principle of tree diagram to filter out the binary serial
number step by step until no collision occurs. I will discuss it later on page 22.
Diagram 1.6 – tree diagram
13
Error Detection
CRC Procedure --- Type A and B
CRC (cyclic redundancy check) procedure was originally used in disk drives, and can
generate a checksum that is reliable enough even for large data quantities. However, it is
also excellently suited for error recognition in data transfer via wire-bound (telephone) or
wireless interface (radio RFID) [3].
The principle of CRC is base on polynomial division. First we need to define the CRC
checksum, which is calculated by the division of a polynomial
We can consider the binary number as polynomial, e.g.
10011 = X^4 + 0^3 + 0^2 + X^1 + X^0
= X^4 + X^1 +1
Let: M - k bits long, F - It is n bits long (n<k)
T - It is k+n bits long P - A pattern of n+1 bits
First we convert all of them to polynomial, and let
T = M*x^n + F
If we divide M*x^n with P, M*x^n/P = Q +R/P
We let the remainder R as F, T = M*x^n +R
T/P = M*x^n/P +R/P = Q + R/P + R/P = Q +(R+R)/P
As binary number added to itself in a modulo 2 field is zero, therefore: T/P = Q no
remainder
14
We can consider:
- M as Original Frame ,
- F as CRC checksum value
- T as Resulting Frame to transmit
- P as generator polynomial
The principle of CRC is to check whether T is divided by P
We have to pre-define the generator polynomial before the system can communicate:
Here is some standard
CRC-8 Generator Polynomial X^8+X^4+X^3+X^2+1
CRC-16/disk controller Generator Polynomial X^16+X^15+X^2+1
CRC-16/CCITT Generator Polynomial X^16+X^12+X^5+1
Table 1.4 --- CRC standard
For my project, I will base on type B requirement. Therefore, the protocol will base
on,
a) Forward Link encoding: Manchester Code
b) Return Link encoding: Manchester Code (for collision detection)
c) Collision Arbitration: Binary Tree
d) Error Detection: Error Check Method of UART
15
Theory
For my project, it includes hardware and software. For hardware part, it includes the
traffic control circuit, MCU and the circuit for RS-232 communication. For software
parts, it includes the control program of MCU.
Figure 2.1 --- Basic Flow of My Project
Hardware
First, I would like to discuss my hardware design. I am focus on the accessory circuit
of MCU and the communication between MCU and computer using the RS-232 interface
at this moment. For the MCU accessory circuit, it includes the reset circuit, the clock
cycle circuit, the travel control circuit and the power supply circuit. Also MCU can’t
communicate by RS-232 interface as they with different logic level (i.e. one use TTL, one
use computer logic). As a result, we need circuit acts as a communication channel.
RF Circuit
RS-232
Receive the ID from tags MCU
Computer
16
Microcontroller
For the MCU, I will choose to use AT89S52 8-bit Microcontroller with the following
main characteristic:
- 8K Bytes In-System Programmable Flash
- 32 Programmable I/O Lines
- Full Duplex UART Serial Channel
Reset Circuit
All microcontrollers need to reset before functioning. Generally speaking, reset time of
microcontroller not less than 5ms.
When the power on, C1 will act as short circuit. As a
result, high voltage (Vcc) drop at R1 => Reset
After C1 will charge up and then finally become open
circuit. Reset will become low voltage.
The circuit can be verify to manual control reset by
adding a switch across the capacitor.
RESET
0
C1
22uF
R1
10k
VCC
Figure 2.3 --- Reset Circuit
Figure 2.2 --- AT89S51 Pin assignment
17
Oscillator Circuit
It is a circuit to provide clock pulse to Microcontroller.
According the specification of AT89S52, I use a crystal
with the frequency 11.0592 MHz with two 39pF load
capacitor need to build the Oscillator Circuit.
Traffic control Circiut
As the reader needs to send signal to the tags and the computer separately, it need to
control the path of transmission. By a control signal from MCU and an AND gate, it can
be achieved easily.
Figure 2.5 --- Transmission Control of reader
P0_0 P0_1 Transmit to
High low Computer
Low High Tag
Table 2.1--- Transmission Control of reader
For UART transmission, it stays at logic high when there is no transmission. As a
result, the reader uses an OR-gate with a control signal to control the transmission. When
TXD
P0_0
P0_1
Tags
Computer
U4A
74LS32
1
23
U4A
74LS32
1
23
Figure 2.4 --- Oscillator Circuit
18
the control input (P0_0/P0_1) is high, that means the transmission is off as the output is
always high. The transmission is on only if the control signal is low.
For the tags side, it has to combine three outputs of tags just like in the usual
environment. So, using OR-gate is a choice. You can imagine if there is a logic high
signal sending from a tag in the environment, the reader will receive a logic high signal
even if there is a tag sending a logic low signal at the same time. The principle is same as
using an OR-gate.
Even through the tag does not sending a signal, it will disturb the transmission as for
UART transmission; it stays at logic high when there is no transmission. Therefore, tags’
output needs to pass through an AND-gate with a control input before get into an
OR-gate. If the tags don’t reply after receiving the signal from reader, set the control
input be low. For other cases, set the control input be high.
Figure 2.6 --- Transmission Control of tag
Power Supply Circuit
As MCU needs a steady power supply and protect it form a large current, a voltage
regulator is needed. The voltage regulator use in the current is L7805CV. It can give a
output voltage 5 + 0.2V if the range of input is 8V to 20V. The output voltage can reach
the VCC requirement of AT89S52 (4.0 to 5.5V)
U3A
74LS08
1
23
U2A
74HC4075
12 98
U3A
74LS08
1
23
U3A
74LS08
1
23
Tag 1 TXD
Tag 1 P0_0
Tag 2 TXD
Tag 2 P0_0
Tag 3 TXD
Tag 3 P0_0
Reader RXD
19
RS-232 interface conversion circuit
The circuit contains the IC MAX232, manufactured by Texas Intrument, which can
perform the translation between TTL logic and RS-232 standard
TTL RS-232 Logic 1 2-5V -15V Logic 0 0-0.8V 15V
Table 2.2 Comparing the TTL logic with RS-232 standard
Here is the reference design:
Figure 2.7 --- reference design for MAX232
RS-232 is simple, universal, well understood and supported but it has some serious
shortcomings as a data interface. The standards to 256kbps or less and line lengths of
15M (50 ft) or less but today we see high speed ports on our home PC running very high
speeds and with high quality cable maxim distance has increased greatly. The rule of
thumb for the length a data cable depends on speed of the data, quality of the cable.
20
Figure 2.8 --- Pin function of RS-232
The data transferring for RS-232 can be asynchronous, which can save one
transmission line comparing to synchronous one. As the data transmission is
asynchronous, we need to define transfer rate first before communication, which is calls
the baud rates. For example Baud Rate = 9600 means the data rate is 9600 bits per one
second
Circuit Design
V15Vdc
C6
40u
C2
1u
V29Vdc
0
0
0
U5
L7805/TO220
1 2VIN VOUT
U3
MAX232
134526
129
1110
138
147
C1+C1-C2+C2-V+V-
R1OUTR2OUT
T1INT2IN
R1INR2IN
T1OUTT2OUT
11.0592
C8
1n
0
R1
1k C3
1u
C5
40u
U1
AT89S53
11121314151617
1819
2122232425262728
29
3031
3233343536373839
40
12345678
9
10
P3.1/TXDP3.2/INT0P3.3/INT1
P3.4/T0P3.5/T1
P3.6/WRP3.7/RD
XTAL2XTAL1
P2.0/A8P2.1/A9
P2.2/A10P2.3/A11P2.4/A12P2.5/A13P2.6/A14P2.7/A15
PSEN
ALE/PROGEA/VPP
P0.7/AD7P0.6/AD6P0.5/AD5P0.4/AD4P0.3/AD3P0.2/AD2P0.1/AD1P0.0/AD0
VCC
P1.0/T2P1.1/T2EXP1.2P1.3P1.4/SSP1.5/MOSIP1.6/MISOP1.7/SCK
RST
P3.0/RXD
C4
1u
U4A
74LS32
1
23
0
C1
1u
U7A
74LS32
1
23
Figure 2.9 Reader Circuit Design
3 5
Tags
21
0
U6A
74LS08
1
23
C11
40u
C11
40u
U1
AT89S53
11121314151617
1819
2122232425262728
29
3031
3233343536373839
40
12345678
9
10
P3.1/TXDP3.2/INT0P3.3/INT1
P3.4/T0P3.5/T1
P3.6/WRP3.7/RD
XTAL2XTAL1
P2.0/A8P2.1/A9
P2.2/A10P2.3/A11P2.4/A12P2.5/A13P2.6/A14P2.7/A15
PSEN
ALE/PROGEA/VPP
P0.7/AD7P0.6/AD6P0.5/AD5P0.4/AD4P0.3/AD3P0.2/AD2P0.1/AD1P0.0/AD0
VCC
P1.0/T2P1.1/T2EXP1.2P1.3P1.4/SSP1.5/MOSIP1.6/MISOP1.7/SCK
RST
P3.0/RXD
11.0592
C9
40u
U3A
74LS08
1
23
V15Vdc
C9
40u
U2A
74HC4075
12 98
R1
1k
U5
L7805/TO220
1 2VIN VOUT
11.0592
0
U1
AT89S53
11121314151617
1819
2122232425262728
29
3031
3233343536373839
40
12345678
9
10
P3.1/TXDP3.2/INT0P3.3/INT1
P3.4/T0P3.5/T1
P3.6/WRP3.7/RD
XTAL2XTAL1
P2.0/A8P2.1/A9
P2.2/A10P2.3/A11P2.4/A12P2.5/A13P2.6/A14P2.7/A15
PSEN
ALE/PROGEA/VPP
P0.7/AD7P0.6/AD6P0.5/AD5P0.4/AD4P0.3/AD3P0.2/AD2P0.1/AD1P0.0/AD0
VCC
P1.0/T2P1.1/T2EXP1.2P1.3P1.4/SSP1.5/MOSIP1.6/MISOP1.7/SCK
RST
P3.0/RXD
11.0592
0
0
U1
AT89S53
11121314151617
1819
2122232425262728
29
3031
3233343536373839
40
12345678
9
10
P3.1/TXDP3.2/INT0P3.3/INT1
P3.4/T0P3.5/T1
P3.6/WRP3.7/RD
XTAL2XTAL1
P2.0/A8P2.1/A9
P2.2/A10P2.3/A11P2.4/A12P2.5/A13P2.6/A14P2.7/A15
PSEN
ALE/PROGEA/VPP
P0.7/AD7P0.6/AD6P0.5/AD5P0.4/AD4P0.3/AD3P0.2/AD2P0.1/AD1P0.0/AD0
VCC
P1.0/T2P1.1/T2EXP1.2P1.3P1.4/SSP1.5/MOSIP1.6/MISOP1.7/SCK
RST
P3.0/RXD0
U4A
74LS08
1
23
V29Vdc
C11
40u
C9
40u
Figure 2.10 Tag Board Circuit Design
Component List
Components Value/Model Number
Microcontroller AT89S52 1 Regulator MAX232
L7805CV 1 1
Logic Gate AND gate 1 Crystal 11.0592MHz 1 Resistor 1k 1 Capacitor 1n
1uF 40uF
1 4 2
Switch 1 RS-232 Socket 1 RS-232 Cable 1
Table 2.3 --- Components List
Reader
22
Software
The Software part is the main part of my project. I will introduce the basic principle of
my program to achieve the anti-collision system first, and then I will go into discuss the
flow of my program
Programming Principle
I will use the case of an area contain three tags to explain the principle of binary tree:
Firstly I have to define some commands for reader to communicate with tags
Command Tags Response Tag’s State after receiving the
command
REQUEST Tags with smaller or equal serial
number will send it back its own
serial number
Remain its state of waiting
REQUEST or SELECT commands
only
SELECT Tags with equal serial number will
send it back its own serial number
Change to state of waiting
CONTROL commands except it
will not response to REQUEST and
SELECT commands
CONTROL Tags will perform specific function
follow the reader request
Remain its state of waiting
CONTROL commands except it
will not response to REQUEST and
SELECT commands
Table 2.4 --- Command List
23
1) Assume there are three tags:
a) Tag 1: 11001111
b) Tag 2: 11100011
c) Tag 3: 11000111
At first step reader will send a REQUEST command to the tags. The REQUEST
command contains a request number. If the tags in the area contain the serial number
smaller or equal to the request number, it will send back its own serial number to the
reader.
Therefore, if we want to check whether there are tags in the area. We need to send a
REQUEST command with a maximum request number (e.g. if the system serves for tags
with 8 bits serial number: the maximum request number = 11111111). As a result, all the
tags should response as they will not have a serial number larger than that. If the reader
can’t receive anything, it will keep sending the maximum REQUEST command until ther
is response.
Figure 2.10 --- Sending the maximum REQUEST command
(Request) 11111111
Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
24
2) When the tags reply together, collisions occur. The Reader will due with the highest
collision bits first.
Figure 2.11 --- Collision occur at bits 5,3,2
3) To handle the collision problem. The reader will send a REQUEST command with
specific request number according to the collision situation. The rule of defining the
request number is:
Bit(compare to the maximum collision bit) Setting
Upper Same as what the reader receive
Equal 0
Lower 1
Table 2.5 --- Rule of defining the request number
According the above rule, the resultant request number of our example is: 11011111.
Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
11001111
11100011
11000111
25
Figure 2.12 --- Send the request number to due with collision at bit 5
4) As Tag 2 has the serial number which larger than the request number, it does not
response to the reader. The reader can filter out Tag 2. In other words, it can filter out the
Tags with 1 at bit 5 of their serial number
Figure 2.13 --- Filter out Tag 2
(Request) 11011111 Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
11001111
11000111
26
5) Using the same principle before and repeat the procedures. The reader will get the
smallest serial number from the environment.
Figure 2.14 --- Send the request signal for collision at bit 3
Figure 2.15 --- Receive the smallest serial number
6) After we can get the serial number without collision, the reader still have to send a
SELECT signal to the tags with the select number (same value as the serial number
received), there are two reasons of doing that:
a) Let the tag to enter the stage of ready to receive CONTROL command
b) If the tag still response to the REQUEST command, we cannot find the other serial
number as the method always find the smallest serial number first.
(Request) 11000111
Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
11000111
27
Only the tag with the same serial number as the select number replies to SELECT
command.
Figure 2.16 --- Send the Request Signal
Tag 3 will then send back its serial number for confirmation. It will now ready to
response to the CONTROL commands to perform specific function. The reader will
check whether the received serial number same as the one received before. If it is, the
reader will send the serial number to computer through the RS-232 interface.
The procedure repeat until all the serial number is get.
(Select)11000111 Tag 1 (11001111)
Tag 2 (11100011)
Tag 3 (11000111)
Reader
Select Number
28
The principle of binary tree I have discussed in introduction. I want to say just a few
more words on this topic related to the collision detection. For the detection of collision
bits, Manchester code acts a very important role on this. Let verify it by the about
example:
Figure 2.17 --- Collision for NRZ coding [3]
From the figure, we can see even there is collision occurs for NRZ coding, MCU can
still receive a data signal from the tags. The serial number returned may neither equal to
any one of the tags
Figure 2.18 --- Collision for Manchester coding [3]
29
Recall the memory for the Manchester coding; the value a bit is defined by the
change in level (negative or positive transition) within a bit window. Logic 0 in this
example is coded by positive transition. Logic 1 is coded by a negative transition. The
“no transition” state is not permissible during data transmission and is recognized as an
error [3]. An error may occur when there are collisions. Therefore, collision is detected.
Program Flow
Beside the reader program, I have also written the program for tag. The tag program is
used to verify whether my reader program function correctly. The program flow is basic
on the theory which stated at above.
1) Reader Program
First, MCU need to initialize condition first before it function. For example we need to
preset the value of global variable and the state of register. Then the MCU will send the
REQUEST signal with the largest request number to the tags. It is because all the tags
will response to this request signal if its serial number is less than it.
30
If there no tags near, MCU will sent the request signal again until there is a reply. If
there are tags replies with collision, the MCU will change the request number and send
again the REQUEST signal until there is no collision. Then, the MCU will send a
SELECT signal to the tags. The tag with the identical tags address will become available
for the processing of CONTROL command. Tag with different addresses will there after
only respond to a REQUEST command. Then the MCU can send the serial number to the
computer through RS-232 for further function.
Figure 2.19 --- Flow of Reader Program
31
2) Tag Program
First, initialize the MCU condition. Then the tags will wait for the REQUEST or
SELECT command. If it received a REQUEST command, compare the serial number
with the request number. If it is larger or equal to the request number, send its own serial
number to reader. Otherwise, it will not reply. Then, wait for the REQUEST or SELECT
signal again.
If the tags receive a SELECT signal with the same serial number as request number, it
will enter a state of waiting the CONTROL signal. It will not response to REQUEST or
SELECT commands anymore.
Figure 2.20 --- Flow of Tag Program
32
Serial Communication
The transmitting and receiving of signal is serial. Therefore we need to use the serial
interface of MCU: UART.
The Universal Asynchronous Receiver/Transmitter (UART) controller is the key
component of the serial communications subsystem of a computer. The UART takes
bytes of data and transmits the individual bits in a sequential fashion. At the destination, a
second UART re-assembles the bits into complete bytes
Asynchronous transmission allows data to be transmitted without the sender having to
send a clock signal to the receiver. Instead, the sender and receiver must agree on timing
parameters in advance and special bits are added to each word which are used to
synchronize the sending and receiving units.
When a word is given to the UART for Asynchronous transmissions, a bit called the
"Start Bit" is added to the beginning of each word that is to be transmitted. The Start Bit
is used to alert the receiver that a word of data is about to be sent, and to force the clock
in the receiver into synchronization with the clock in the transmitter. These two clocks
must be accurate enough to not have the frequency drift by more than 10% during the
transmission of the remaining bits in the word.
33
After the Start Bit, the individual bits of the word of data are sent, with the Least
Significant Bit (LSB) being sent first. Each bit in the transmission is transmitted for
exactly the same amount of time as all of the other bits, and the receiver “looks” at the
wire at approximately halfway through the period assigned to each bit to determine if the
bit is a 1 or a 0. For example, if it takes two seconds to send each bit, the receiver will
examine the signal to determine if it is a 1 or a 0 after one second has passed, then it will
wait two seconds and then examine the value of the next bit, and so on.
The sender does not know when the receiver has “looked” at the value of the bit. The
sender only knows when the clock says to begin transmitting the next bit of the word.
When the entire data word has been sent, the transmitter may add a Parity Bit that the
transmitter generates. The Parity Bit may be used by the receiver to perform simple error
checking. Then at least one Stop Bit is sent by the transmitter.
When the receiver has received all of the bits in the data word, it may check for the
Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used),
and then the receiver looks for a Stop Bit. If the Stop Bit does not appear when it is
supposed to, the UART considers the entire word to be garbled and will report a Framing
Error to the host processor when the data word is read. The usual cause of a Framing
Error is that the sender and receiver clocks were not running at the same speed, or that the
signal was interrupted.
34
Regardless of whether the data was received correctly or not, the UART automatically
discards the Start, Parity and Stop bits. If the sender and receiver are configured
identically, these bits are not passed to the host.
If another word is ready for transmission, the Start Bit for the new word can be sent as
soon as the Stop Bit for the previous word has been sent.
Because asynchronous data is “self synchronizing”, if there is no data to transmit, the
transmission line can be idle.
8051 provides a transmit channel and a receive channel of serial communication. The
transmit data pin (TXD) is specified at P3.1, and the receive data pin (RXD) is at P3.0.
The serial signals provided on these pins are TTL signal levels and must be boosted and
inverted through a suitable converter(MAX232 is used in my project) to comply with
RS232 standard.
All modes are controlled through SCON, the Serial control register. The SCON bits are
defined as SM0, SM1, SM2, REN, TB8, RB8, TI, RI from MSB to LSB. The timers are
controlled using TMOD, the Timer mode register, and TCON, the Timer control register.
35
The address of SCON: 98H. In my program I will set SCON = 0x50
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
SM0 SM1 SM2 REN TB8 RB8 TI RI
0 1 0 1 0 0 0 0
Table 2.6 --- Description of bits in the SCON register
1) SM0 SM1 is for the mode selection:
SM0 SM1 Mode Description Baud Rate
0 0 0 Shift Register Fosc / 12
0 1 1 8 bit UART Variable
1 0 2 9 bit UART Fosc / 64 or Fosc / 32
1 1 3 9 bit UART Variable
Table 2.7 --- Serial Transmission Mode Selection Table
Mode 0
Each transmitted bit is valid on RXD pin for one machine cycle. Reception is initiated as
soon as REN bit is set to 1 and the receive interrupt (RI) bit is cleared. Usually, REN is
set at the beginning of the program to initialize the serial port, then RI is cleared to start a
data input operation. As soon as RI is cleared, the shift clock will be produced on the
TXD pin. At the beginning of the following machine cycle, data will be clocked in from
the RxD line. After the 8th clocking cycle, the data is copied to SBUF and the RI bit is
36
set. It is up to the attached circuitry to provide data on RXD line synchronized by the
clock signal on TXD. Receive and Transmit cannot be done at the same time.
Mode 1
Mode 1 is an 8-bit UART with variable baud rate. 10 bit data are transmitted on TXD or
received on RXD. These consist of a start bit (always 0), eight data bits (LSB first) and
stop bit (always 1). Baud rate is set by timer 1.
Transmission is initiated by writing to SBUF. The shifted data are outputted on the TXD
line beginning with start bit and followed by eight bit data bits then stop bit. The transmit
interrupt (TI) flag is set as soon as the stop bit appears on TXD.
Reception is initiated by a 1 to 0 transition on RXD (assuming REN is 1). The start bit is
skipped and eight data bits are clocked into the serial port shift register. When all eight
bits have been clocked in, the following occur:
1. Ninth bit (stop bit) is clocked into RB8 in SCON
2. SBUF is loaded with eight data bits
3. Receiver interrupt flag (RI) is set
37
Mode 2
Mode 2 is 9-bit UART with fixed baud rate. Eleven bits are transmitted or received: a
start bit, eight data bits, a programmable ninth bit and a stop bit On transmission, the
ninth bit is whatever has been put in TB8 in SCON. On reception, the ninth bit received
is placed in RB8.
Mode 3
Mode 3 is 9-bit UART with variable baud rate. Mode 3 is same as Mode 2 except baud
rate is programmable and provided by Timer 1
In my program I will use Mode 1, as it can the Baud rate is programmable.
2) REN Enables serial reception.
REN = 0 (Cleared by software) disable reception.
REN = 1 (Set by software) enable reception
3) TB8 The 9th data bit that will be transmitted in Modes 2 and 3. Set or clear by
software as desired.
4) SCON.2 / RB8 In modes 2 and 3, the 9th data bit that was received. In Mode 1, if
SM2 = 0, RB8 is the stop bit that was received. In Mode 0, RB8 is not used.
38
5) SCON.1 / Tl Transmit interrupt flag.
Set by hardware at the end of the 8th bit time in Mode 0, or at the beginning of the stop
bit in the other modes, in any serial transmission. It must be cleared by software.
6) SCON.0 / Rl Receive interrupt flag.
Set by hardware at the end of the 8th bit time in Mode 0, or halfway through the stop bit
time in the other modes, in any serial reception (except see SM2). It must be cleared by
software.
Baud Rate Calculation
The transmitting and receiving rate, which is called Baud rate, is controlled by Timer 1
at mode 1. The relation between Baud Rate and Timer1:
SMOD is the bit 7 of PCON, power control register. Set it equal to zero and, as I
mention before, the oscillator frequency equal to 11.0592MHz, the equation become:
As the TH1 must be a positive value, the baud rate can only be 1200, 2400, 4800,
9600.
TH1 = 256 — Baud Rate
228800
TH1 =2
256SMOD
— 384 x (Baud Rate)
1x (Osillator Frequency)
39
Baud Rate/bps Osillator Frequency/MHz SMOD TH1 Value
62.5K 12 1 FFH
19.2K 11.06 1 FDH
9.6K 11.06 0 FDH
4.8K 11.06 0 FAH
2.4K 11.06 0 F4H
1.2K 11.06 0 E8H
300 6 0 CCH
110 6 0 72H
Table 2.8 --- Relation between Baud Rate and TH1 register
In my program, I use 9.6Kbps Baud Rate and using Timer1 interrupt. The setting of the
register becomes:
40
Experimental Procedure and Result
The experiment is needed for me to verify the function of reader program. Also, I have
to develop a tag program as I am going to use MCU acting as the tags for the
demonstration for the real situations when there is collision occur. As a result, an
experiment is also need to verify the tag program.
If the reader program and the tag program functioning like what I have stated in theory
part, the last part is to set up a collision environment. The system contains one reader
(MCU with reader program) and three tags (MCU with tag program). If the reader can get
the serial number of all the three tags, the anti-collision system is done.
Let me divide my project into three phases:
1) Reader Program
2) Tag Program
3) Combine the reader side and tag side --- a complete anti-collision system
After finished each phase, an experiment is carry out to verify everything correct.
41
Phase 1 --- Reader Program
Introduction
It is an experiment to verify the function of reader program. The functions include
Manchester coding and decoding, collision bit detection and the anti-collision system.
Equipment
1) A computer
2) A RS-232 cable
3) Testing Board for MCU with RS-232 interface
4) Testing Program --- PortTest V1.3 [5]
Testing Setup
Figure 3.1 --- Setup for Reader Testing
42
Figure 3.2 --- Interface of PortTest V1.3
Procedure
1) Connect the Pin 11(TXD) of MCU to Pin 11 of MAX232
2) Connect the Pin 10(RXD) of MCU to Pin 12 of MAX232
3) Open the testing program PortTest V1.3
4) Connect power to the testing board
5) Connect the testing board and computer through RS-232 cable
6) Push the reset button
7) See whether the computer can receive a signal FFAAAA (hex). Where FF (hex) is the
request command and AAAA (hex) is the maximum request number by Manchester Form
8) See whether the signal FFAAAA (hex) continue to send if there is no reply
9) Ask the program to send 5656 to the reader
Signal Transmission
Signal Received
43
10) Check whether the reader reply F05656 (hex). Where F0 (hex) is the SELECT
command and 5656 (hex) is the received serial number without collision
11) Send again the 5656 (hex) immediately to the reader if F05656 (hex) is received.
Check whether the reader replies 11(hex), the decoded serial number.
11) Repeats the procedure (9) - (11) by sending different Manchester Code
12) Repeat the procedure (9) by sending Manchester Code at different Bits, check
whether it can detect the collision bit and perform specific action.
Result
A) Receiving Manchester code without collision
I have try several code: 5656, 69A6, 9AA5, A595, AA55
Code sent(hex) Code sent(binary) Decode by calculation
(hex)
Decode by reader
(hex)
5656 0101011001010110 11 11
69A6 0110100110100110 6D 6D
9AA5 1001101010100101 BC BC
A595 1010010110010101 C8 C8
AA55 1010101001010101 F0 F0
Table 3.1 --- Reader Manchester Decode Result
44
B) Manchester Code when Collision
Code sent(binary) Collision bit
(highest) 7 6 5 4 3 2 1 0
Request Number
Sent (by the rule)
Request Number
Sent (by the reader)
7 11 11 11 11 11 11 11 11 7FH 7FH
6 10 11 01 10 10 11 01 11 BFH BFH
5 01 10 11 11 01 11 01 10 5FH 5FH
4 10 01 10 11 11 01 10 01 AFH AFH
3 01 10 01 10 11 01 11 01 57H 57H
2 10 01 10 01 10 11 10 01 ABH ABH
1 01 10 01 10 01 01 11 11 51H 51H
0 10 01 10 01 10 01 10 11 AAH AAH
Table 3.2 --- Reader response on collision
45
Phase 2 --- Tag Program
Introduction
It is an experiment to verify the performance of tag program. It should response to
REQUEST and SELECT commands properly.
Equipment
1) A computer
2) A RS-232 cable
3) Testing Board for MCU with RS-232 interface
4) Testing Program --- PortTest V1.3 [5]
Testing Setup
Figure 3.3 --- Setup for Tag Testing
46
Procedure
1) Connect the Pin 11(TXD) of MCU to Pin 11 of MAX232
2) Connect the Pin 10(RXD) of MCU to Pin 12 of MAX232
3) Open the testing program PortTest V1.3
4) Connect power to the testing board
5) Connect the testing board and computer through RS-232 cable
6) Push the reset button
7) Check the response by sending different commands
Result
Setting the serial number of tag to 1F(hex) by program
Command Request Number/ Select
Number
Tag Reply Tag State
Larger than 1F(hex) Yes
Smaller than 1F(hex) No
REQUEST
Equal to 1F(hex) Yes
Larger than 1F(hex) No
Smaller than 1F(hex) No
Still will response to
REQUEST and SELECT
commands afterwards
SELECT
Equal to 1F(hex) Yes Will not response to
REQUEST and SELECT
commands afterwards
Table 3.3 --- Tag Response
47
Phase 3 --- The Anti-Collision System
Introduction
The system contains three tags with different serial number. Check the reader whether
can get the serial number among these tags.
Equipment
1) A computer
2) A RS-232 cable
3) Testing board for reader MCU with RS-232 interface
4) Testing board for tag MCU with three input OR-gate
5) Testing Program --- PortTest V1.3 [5]
Testing Setup
Figure 3.4 --- Anti-collision Testing
Reader
Tag 1 Tag 2 Tag 3
Or-Gate
48
Procedure
1) On the tags side, connect the output of OR-gate(74HC4075) to Pin 10 (RXD) of
Reader MCU
2) Connect the Pin 11 (TXD) of Reader MCU to Pin 10 (RXD) of all Tag MCU
3) Connect the Pin 11 (TXD) of Reader to Pin 11 of MAX232
4) Connect the testing board for reader to computer through RS232 cable
5) Connect power supply for both testing board with same grounding
6) Push the reset button for tag board
7) Push the reset button for reader board
8) Check the reader whether it can recognize the serial number by four sets of serial
number
Serial number The first and second highest collision bit
Set 1 01111000 (78 H) 10110111 (B7 H) 11111000 (F8 H)
Bit 7 Bit 6
Set 2 10001011 (8B H) 10100100 (A4 H) 10111101 (BD H)
Bit 5 Bit4
Set 3 11100111 (E7 H) 11101011 (EB H) 11101111 (EF H)
Bit 3 Bit 2
Set 4 11001001 (C9 H) 11001010 (CA H) 11001011 (CB H)
Bit 1 Bit 0
Table 3.4 --- Set of tags to test the reader system
As the system can determine the serial number of the tags by the first two highest
collision bits if there are only three tags in the environment, this testing procedure can
confirm the reader have the ability due with collision condition at different bit.
49
Result
Set 1
Tag Serial Number Serial Number in Manchester Form
1 78 H 6A05 H
2 B7 H 9A6A H
3 F8 H AA95 H
Table 3.5 --- The Serial Number of Tags (Set 1)
Result Signal Out Explanation
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply.
FF 6A AA Tag 2 and Tag 3 will filter out as
its serial number is larger.
F0 6A 05 Send the Select Signal to tag 1
with its serial number to make
sure tag 1 will not response to
select and request signal again.
78 Receive the Serial Number from
tag 1 again. Convert to NRZ code
and send to computer.
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply except tag 1
FF 9A AA Tag 3 will be filter out
50
F0 9A 6A Send the Select Signal to tag 2
with its serial number to make
sure tag 2 will not response to
select and request signal again.
BF Receive the Serial Number from
tag 2 again. Convert to NRZ code
and sending to computer.
FF AA AA Select Signal with Maximum
Request Number, but this time
only tag 3 reply
F0 AA 95 Send the Select Signal to tag 3
with its serial number to make
sure tag 3 will not response to
select and request signal again.
F8 Receive the Serial Number from
tag 3 again. Convert to NRZ code
and sending to computer.
FF AA AA Sending Select Signal with
Maximum Request Number
Continuously, because all the tags
are selected so will not response
to the select and request signal
Table 3.6 --- Result for Set 1
51
Set 2
Tag Serial Number Serial Number in Manchester Form
1 8B H 959A H
2 A4 H 9965 H
3 BD H 9AA6 H
Table 3.7 --- Serial Number for Tags (Set 2)
Result Signal Out Explanation
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply.
FF 96 AA Tag 2 and Tag 3 will filter out as
its serial number is larger.
F0 95 9A Send the Select Signal to tag 1
with its serial number to make
sure tag 1 will not response to
select and request signal again.
8B Receive the Serial Number from
tag 1 again. Convert to NRZ code
and send to computer.
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply except tag 1
FF 99 AA
Tag 3 will be filter out
52
F0 99 65 Send the Select Signal to tag 2
with its serial number to make
sure tag 2 will not response to
select and request signal again.
A4 Receive the Serial Number from
tag 2 again. Convert to NRZ code
and sending to computer.
FF AA AA Select Signal with Maximum
Request Number, but this time
only tag 3 reply
F0 9A A6 Send the Select Signal to tag 3
with its serial number to make
sure tag 3 will not response to
select and request signal again.
BD Receive the Serial Number from
tag 3 again. Convert to NRZ code
and sending to computer.
FF AA AA Sending Select Signal with
Maximum Request Number
Continuously, because all the tags
are selected so will not response
to the select and request signal
Table 3.8 --- Result for Set 2
53
Set 3
Tag Serial Number Serial Number in Manchester Form
1 E7 H A96A H
2 EB H A99A H
3 EF H A9AA H
Table 3.9 --- Serial Number for Tags (Set 3)
Result Signal Out Explanation
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply.
FF A9 6A Tag 2 and Tag 3 will filter out as
its serial number is larger.
F0 A9 6A Send the Select Signal to tag 1
with its serial number to make
sure tag 1 will not response to
select and request signal again.
E7 Receive the Serial Number from
tag 1 again. Convert to NRZ code
and send to computer.
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply except tag 1
FF A9 9A
Tag 3 will be filter out
54
F0 A9 9A Send the Select Signal to tag 2
with its serial number to make
sure tag 2 will not response to
select and request signal again.
EB Receive the Serial Number from
tag 2 again. Convert to NRZ code
and sending to computer.
FF AA AA Select Signal with Maximum
Request Number, but this time
only tag 3 reply
F0 A9 AA Send the Select Signal to tag 3
with its serial number to make
sure tag 3 will not response to
select and request signal again.
EF Receive the Serial Number from
tag 3 again. Convert to NRZ code
and sending to computer.
FF AA AA Sending Select Signal with
Maximum Request Number
Continuously, because all the tags
are selected so will not response
to the select and request signal
Table 3.10 --- Result for Set 3
55
Set 4
Tag Serial Number Serial Number in Manchester Form
1 C9 H A596 H
2 CA H A599 H
3 CB H A59A H
Table 3.9 --- Serial Number for Tags (Set 4)
Result Signal Out Explanation
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply.
FF A5 96 Tag 2 and Tag 3 will filter out as
its serial number is larger.
F0 A5 96 Send the Select Signal to tag 1
with its serial number to make
sure tag 1 will not response to
select and request signal again.
C9 Receive the Serial Number from
tag 1 again. Convert to NRZ code
and send to computer.
FF AA AA Select Signal with Maximum
Request Number, all the tags will
reply except tag 1
FF A5 99
Tag 3 will be filter out
56
F0 A5 99 Send the Select Signal to tag 2
with its serial number to make
sure tag 2 will not response to
select and request signal again.
CA Receive the Serial Number from
tag 2 again. Convert to NRZ code
and sending to computer.
FF AA AA Select Signal with Maximum
Request Number, but this time
only tag 3 reply
F0 A5 9A Send the Select Signal to tag 3
with its serial number to make
sure tag 3 will not response to
select and request signal again.
CB Receive the Serial Number from
tag 3 again. Convert to NRZ code
and sending to computer.
FF AA AA Sending Select Signal with
Maximum Request Number
Continuously, because all the tags
are selected so will not response
to the select and request signal
Table 3.10 --- Result for Set 4
57
Discussion and Conclusion
Base On the experiment result, I have made some conclusions.
Phase 1
The results show that the reader program can perform the Manchester decoding. When
the is a collision, the reader can follow the rule of binary tree to send again the suitable
REQUEST command to filter out the serial number contain 1 at collision bit.
Generally, the reader program is success.
Phase 2
The program is performing like the tag, which I have stated at Theory part. It sends its
own serial number to the reader it REQUEST command which request number larger or
equal to its’ is received. After that, it will waiting the REQUEST and SELECT command
again until it receive a SELECT command with the same select number with serial
number. Then, the tags will not response to any SELECT and REQUEST signal again.
Phase 3
In the real situation with little noise and loss by connecting with wire, the reader can
perform the anti-collision what ever the collision is occurred at any bit. The chance for
the reader to recognize the signal become low if the noise effect is serious (e.g. wireless
communication). This can be improved by adding the error correction system and lower
the transmission speed.
58
Further Improvement
1) Adding Error Correction System:
For example, Cyclic Redundancy Check (CRC) and Parity Checking This can
make sure if the reader can recover the signal if which is missing or disturbed.
2) Bi – direction transmission,
After the computer gets the serial number of tags, it can order the tags to perform
some function (e.g. switch on the light) by calling its serial number.
59
Cost Summary
Components Value/Model Unit Cost/HKD Number Cost/HKD
Microcontroller AT89S52 22 1 22 Regulator MAX232
LT7805CV 20 20
1 1
20 20
Logic Gate 74LS08 5 1 5 Quartz Crystal 11.0592MHz 5 1 5 Resistor 1k 0.5 1 1 Capacitor 1n
1uF 40uF
0.5 0.5 0.5
1 4 2
0.5 2 1
Switch 1.2 1 1.2 RS-232 Socket DB9 5 1 5 Multi-function PCB Broad
5 1 5
IC Socket 8 pins 14pins 40 pins
4 8 16
1 4 1
5 32 16
Total Cost: 140.7 Table 5.1 --- Reader Board
Components Value/Model Unit Cost/HKD Number Cost/HKD
Microcontroller AT89S52 22 3 66 Regulator LT7805CV 20 1 20 Logic Gate 74HC4075E 5 1 5 Quartz Crystal 11.0592MHz 5 3 15 Resistor 1k 0.5 3 1.5 Capacitor 1n
1uF 40uF
0.5 0.5 0.5
3 12 6
1.2 6 3
Switch 1.2 3 3.6 Multi-function PCB Broad
5 1 5
IC Socket 8 pins 14 pins 40 pins
4 8 16
6 1 3
24 8 48
Total Cost: 200.3 Table 5.2 --- Tag Board
60
Reference
[1] Steven Shepard “RFID – Radio Frequency Identification”
[2] “ISO/IEC FDIS 18000-6:2003(E)”
[3] Klaus Finkenzeller “RFID Handbook – Fundamentals and Applications in Contactless
Smart Cards and Identification”
[4] Manish Bhuptani, Shahram Moradpour “RFID Field Guide - Deploying Radio
Frequency Identification Systems”
[5] http://big5.china.com/gate/big5/download.china.com/soft/0900/0906/index.html
61
Program Source Code
The reader program:
#include <stdio.h> #include <math.h> #include <regx51.h> void putc(char c); void demanch(); void uart(unsigned short int a); void manch(unsigned short int manch_in); unsigned short int b[8], c[16]; unsigned short int a; int i, j=15, col, col_b, rec_data, rec_data_temp=0; unsigned short int bytedata[2]={0,0}; unsigned short int byte_rec=0; unsigned short int end=0; void main() { unsigned short int con_sig=0xFF; int x, y, z; while(1) { P0_0=0; /*open transmission to tags*/ P0_1=1; byte_rec=0; rec_data=0; SCON = 0x50; /*uart in mode 1 (8 bit), REN=1*/ TMOD = 0x20; /* Timer 1 in mode 2*/ TH1 = 0xA0; /*300 Bds at 11.059MHz*/ TL1 = 0xA0; /*300 Bds at 11.059MHz*/ ES = 1; /*Enable serial interrupt*/ EA =1; /*Enable global interrupt*/ TR1 = 1; /*Timer 1 run*/
62
/*continue sending the request signal until reply*/ while((bytedata[0]==0&&bytedata[1]==0)||(bytedata[0]==1&&bytedata[1]==1)) { putc(0xFF); /*Request command*/ manch(con_sig); /*Request Number*/ for(x=0; x<300; x++) /*wait 0.3 second*/ for(y=0; y<10;y++) for(z=0; z<120; z++); } demanch(); /*Manchester Decode*/ if (col==1) /*If collision occur*/ { switch(col_b) /*Setting the request number for specific collision*/ { case 7: con_sig=0x7F; break; case 6: con_sig=0x3F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 5: con_sig=0x1F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 4: con_sig=0x0F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break;
63
case 3: con_sig=0x07; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 2: con_sig=0x03; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 1: con_sig=0x01; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 0: con_sig=0; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; default: con_sig=0xFF; } } else /*if no collision occur*/ { rec_data_temp=rec_data; con_sig=0xFF; byte_rec=0; rec_data=0; putc(0xF0); /*send the SELECT signal*/ manch(rec_data_temp); for(x=0; x<300; x++) /*delay 0.3 seconds*/ for(y=0; y<10; y++) for(z=0; z<120; z++); demanch();
64
/*send to computer if the serial number received is same as before*/ if (rec_data_temp==rec_data) { P0_0=1; P0_1=0; putc(rec_data); } } } } void putc(char c) /*send 8bit number through UART*/ { SBUF=c; while(!TI); TI=0; } void demanch() /*Manchester Decoding*/ { j=15; rec_data=0; col=0; col_b=0; for (i=15; i>=8; i--) { c[i] = (int)(bytedata[0]/pow(2, (i-8))); bytedata[0] = bytedata[0]%(int)(pow(2, (i-8))); } for (i=7; i>=0; i--) { c[i] = (int)(bytedata[1]/pow(2, i)); bytedata[1] = bytedata[1]%(int)(pow(2, i)); }
65
for (i=7; i>=0; i--) { if (c[j]==1) { if (c[j-1]==0) { b[i]=1; j=j-2; } else /*collision occur*/ { col=1; col_b=i; break; } } else { if (c[j-1]==1) { b[i]=0; j=j-2; } else /*collision occur*/ { col=1; col_b=i; break; } } } if (col==0) { for (i=7; i>=0; i--) rec_data = rec_data + (int)(b[i]*pow(2, i)); } bytedata[0]=0; bytedata[1]=0; }
66
void manch(unsigned short int manch_in) /*Manchester Coing*/ { j=15; for (i=7; i>=0; i--) { b[i] = (int)(manch_in/pow(2, i)); manch_in = manch_in%(int)(pow(2, i)); } for (i=7; i>=0; i--) { if (b[i]==1) { c[j]=1; c[j-1]=0; j=j-2; } else { c[j]=0; c[j-1]=1; j=j-2; } } a=0; for (j=15; j>=0; j--) { a=a+c[j]*(pow(2, j)); } uart(a); }
67
void uart(unsigned short int a) /*send 16bits signal through UART*/ { SBUF = (a>>8); while(TI!=1); TI = 0; SBUF = a; while(TI!=1); TI = 0; } void getc(void) interrupt 4 using 1 /*receive 16bits data through UART*/ { if(RI) { if(byte_rec>=1) { end=1; } bytedata[byte_rec]=SBUF; byte_rec++; RI=0; } }
68
Tag Program:
#include <stdio.h> #include <math.h> #include <regx51.h> void demanch(); void uart(unsigned short int a); void manch(unsigned short int manch_in); void putc(char c); int b[8], i, j=15, k, c[16]; int col, col_b; int rec_data; int bytedata[3]=(0,0,0); int byte_rec=0; int end=0; void main() { unsigned short int sn=0xCB; /*set the serial number*/ int mode=1; P0_0=1; /*open the transmission*/ SCON=0x50; /*UART in mode 1 (8 bit), REN=1*/ TMOD=0x20; /*Timer 1 in mode 2*/ TH1=0xA0; /*300 Bds at 11.059MHz*/ TL1=0xA0; /*300 Bds at 11.059MHz*/ ES=1; /*Enable serial interrupt*/ EA=1; /*Enable global interrupt*/ TR1=1; /*Timer 1 run*/ while (mode==1) { do{ }while(end==0); /*Wait Command*/ P0_0=1; /*open the transmission*/
69
if (bytedata[0]==0xF0) /*if SELECT command received*/ { demanch(); if (sn==rec_data) { P0_0=1; manch(sn); P0_0=0; mode=2; /*enter mode 2, not response to SEL and REQ command*/ }
else /*if the serial number received before and after the SEL signal sent not the same, set the transmission close.
{ P0_0=0; manch(sn); P0_0=1; } bytedata[3]=(0,0,0); byte_rec=0; end=0; } else if (bytedata[0]==0xFF) /*if REQUEST command received*/ { demanch(); if(sn<=rec_data) /*for the case serial number small then the REQ signal,
reply*/ { P0_0=1; manch(sn); } else /*for the case serial number larger then the REQ signal,
reply*/ P0_0=0; /*close the transmission*/ bytedata[3]=(0,0,0); byte_rec=0; end=0; } }
70
while(mode==2) /*After receiving the select signal*/ { do{ }while(end==0); if (bytedata[0]==0xFF) /*if received a request signal, close the transmission,
don’t disturb the other*/ { demanch(); if(sn<=rec_data) { P0_0=0; manch(sn); } else P0_0=0; bytedata[3]=(0,0,0); byte_rec=0; end=0; } } } void putc(char c) { SBUF =c; while(!TI); TI = 0; }
71
void getc(void) interrupt 4 using 1/*get 24 bits data through UART { if(RI) { if(byte_rec>=2) { end=1; } bytedata[byte_rec]=SBUF; byte_rec++; RI=0; } } void demanch() /*Manchester Decoding*/ { j=15; rec_data=0; col=0; col_b=7; for (i=15; i>=8; i--) { c[i] = (int)(bytedata[1]/pow(2, (i-8))); bytedata[1] = bytedata[1]%(int)(pow(2, (i-8))); } for (i=7; i>=0; i--) { c[i] = (int)(bytedata[2]/pow(2, i)); bytedata[2] = bytedata[2]%(int)(pow(2, i)); }
72
for (i=7; i>=0; i--) { if (c[j]==1) { if (c[j-1]==0) { b[i]=1; j=j-2; } else { col=1; col_b=i; break; } } else { if (c[j-1]==1) { b[i]=0; j=j-2; } else { col=1; col_b=i; break; } } } for (i=7; i>=0; i--) rec_data = rec_data + (int)(b[i]*pow(2, i)); }
73
void manch(unsigned short int manch_in) /*Manchester Coding*/ { unsigned short int a; j=15; for (i=7; i>=0; i--) { b[i] = (int)(manch_in/pow(2, i)); manch_in = manch_in%(int)(pow(2, i)); } for (i=7; i>=0; i--) { if (b[i]==1) { c[j]=1; c[j-1]=0; j=j-2; } else { c[j]=0; c[j-1]=1; j=j-2; } } a=0; for (j=15; j>=0; j--) { a=a+c[j]*(pow(2, j)); } uart(a); }
74
void uart(unsigned short int a) /*send 16 bits signal through UART*/ { SBUF = (a>>8); while(TI!=1); TI = 0; SBUF = a; while(TI!=1); TI = 0; }
75
Photo of Circuit
Figure 7.1 --- Reader Broad
Figure 7.2 --- Tag Board
76
Appendix
77
78
79
80
81