1 | // *******************************************************************************
|
2 |
|
3 | // Routine to synchronize bit periods in a Manchester encoded stream
|
4 |
|
5 | // Always sync to rising edge
|
6 |
|
7 | // ******************************************************************************/
|
8 |
|
9 | unsigned char U2270_Manchester2TSync(void)
|
10 |
|
11 | {
|
12 |
|
13 | unsigned char level;
|
14 |
|
15 | RFIDTimerFlag = 0; // Clear Timer Flag
|
16 |
|
17 | while(!RFIDTimerFlag); // Wait for next edge
|
18 |
|
19 |
|
20 |
|
21 | level = (PIND & 0x10); // Check logic level of data line
|
22 |
|
23 | level = (PIND & 0x10); // Redundancy check
|
24 |
|
25 |
|
26 |
|
27 | // Make sure edge time is a Manchester long time //
|
28 |
|
29 | if(RdTime > U2270_LongL && RdTime < U2270_LongH && level == 0 )
|
30 |
|
31 | {
|
32 |
|
33 | PORTF &= ~0x02;
|
34 |
|
35 | Timer_delay_us(2);
|
36 |
|
37 | PORTF |= 0x02;
|
38 |
|
39 | return 1; // Logic value of current bit
|
40 |
|
41 | }
|
42 |
|
43 | else return SeqTermErr; // Edge time and level error
|
44 |
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 | // *******************************************************************************
|
50 |
|
51 | // Routine to decode a Manchester bit
|
52 |
|
53 | // Pass in the previous bit logic value
|
54 |
|
55 | // ******************************************************************************/
|
56 |
|
57 | unsigned char U2270_ManchesterDecode(unsigned char cBit)
|
58 |
|
59 | {
|
60 |
|
61 | RFIDTimerFlag = 0; // Clear Timer Flag
|
62 |
|
63 | while(!RFIDTimerFlag); // Wait for next edge
|
64 |
|
65 |
|
66 |
|
67 | // Check edge time and determine next Logic value //
|
68 |
|
69 | if(RdTime > U2270_LongL && RdTime < U2270_LongH && cBit == 1){return 0;}
|
70 |
|
71 | else if(RdTime > U2270_LongL && RdTime < U2270_LongH && cBit == 0){return 1;}
|
72 |
|
73 | else if(RdTime > U2270_ShortL && RdTime < U2270_ShortH) // Next edge time is short
|
74 |
|
75 | {
|
76 |
|
77 | RFIDTimerFlag = 0; // Clear Timer flag
|
78 |
|
79 | while(!RFIDTimerFlag); // Wait for next edge
|
80 |
|
81 | if(RdTime > U2270_ShortL && RdTime < U2270_ShortH && cBit == 1){return 1;}
|
82 |
|
83 | else if(RdTime > U2270_ShortL && RdTime < U2270_ShortH && cBit == 0){return 0;}
|
84 |
|
85 | else
|
86 |
|
87 | {
|
88 |
|
89 | //PORTF &= ~0x02;
|
90 |
|
91 | //PORTF |= 0x02;
|
92 |
|
93 | return BitErr; // Un-paired short time between two long times
|
94 |
|
95 | }
|
96 |
|
97 | }
|
98 |
|
99 | else {return BitErr;} // Edge time outside limits
|
100 |
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 | // *******************************************************************************
|
106 |
|
107 | // Routine to decode a BiPhase bit
|
108 |
|
109 | // ******************************************************************************/
|
110 |
|
111 | unsigned char U2270_BiPhaseDecode(void)
|
112 |
|
113 | {
|
114 |
|
115 | RFIDTimerFlag = 0; // Clear Timer Flag
|
116 |
|
117 | while(!RFIDTimerFlag); // Wait for next edge
|
118 |
|
119 |
|
120 |
|
121 | // Check edge time and determine next Logic value //
|
122 |
|
123 | if(RdTime > U2270_LongL && RdTime < U2270_LongH){return 1;}
|
124 |
|
125 | else if(RdTime > U2270_ShortL && RdTime < U2270_ShortH) // Next edge time is short
|
126 |
|
127 | {
|
128 |
|
129 | RFIDTimerFlag = 0; // Clear Timer flag
|
130 |
|
131 | while(!RFIDTimerFlag); // Wait for next edge
|
132 |
|
133 | if(RdTime > U2270_ShortL && RdTime < U2270_ShortH){return 0;}
|
134 |
|
135 | else
|
136 |
|
137 | {
|
138 |
|
139 | return BitErr; // Un-paired short time between two long times
|
140 |
|
141 | }
|
142 |
|
143 | }
|
144 |
|
145 | else {return BitErr;} // Edge time outside limits
|
146 |
|
147 | }
|
148 |
|
149 |
|
150 |
|
151 | // *******************************************************************************
|
152 |
|
153 | // Routine to find Decode the Dual Pattern Bit
|
154 |
|
155 | // ******************************************************************************/
|
156 |
|
157 | unsigned char U2270_DualPatternDecode(void)
|
158 |
|
159 | {
|
160 |
|
161 | RFIDTimerFlag = 0; // Clear Timer Flag
|
162 |
|
163 | while(!RFIDTimerFlag); // Wait for next edge
|
164 |
|
165 |
|
166 |
|
167 | // Check edge time and determine next Logic value //
|
168 |
|
169 | if(RdTime > U2270_ShortL-30 && RdTime < U2270_ShortH+20)
|
170 |
|
171 | {
|
172 |
|
173 | RFIDTimerFlag = 0; // Clear Timer flag
|
174 |
|
175 | while(!RFIDTimerFlag); // Wait for next edge
|
176 |
|
177 | if(RdTime > U2270_ShortL-20 && RdTime < U2270_ShortH+20){return 1;}
|
178 |
|
179 | else {return BitErr;} // Un-paired short time between two long times
|
180 |
|
181 | }
|
182 |
|
183 | else if(RdTime > U2270_LongL && RdTime < U2270_LongH+30)
|
184 |
|
185 | {
|
186 |
|
187 | RFIDTimerFlag = 0; // Clear Timer flag
|
188 |
|
189 | while(!RFIDTimerFlag); // Wait for next edge
|
190 |
|
191 | return 0;
|
192 |
|
193 | }
|
194 |
|
195 | else {return BitErr;} // Edge time outside limits
|
196 |
|
197 | }
|