1. //2006-4-27 13:10
2. //更改为默认 manchester,RF/64,软件可读写EM4469,不能更改设置读卡器参数,可读参数2006-4-27 12:01
3. //不能使用默认读命令
4. //支持PCB端软件:1.EM4469 RFID Development Kit Application Software 2.EM4469 Read Only Application Software
5. //支持卡片:EM4469,EM410X
6.
7. #include "main.h"
8.
9.
10. ////EM4095控制线定义
11. sbit MOD = P1^1;
12. sbit SHD = P1^2;
13. sbit DEMOD_OUT = P3^3;
14. sbit RDY_CLK = P3^4;
15. sbit speak = P1^3;
16.
17. union myunion
18. {
19. uint word;
20. struct
21. {
22. uchar high2;
23. uchar low2;
24. }bytes;
25. };
26.
27.
28. union myunion count_timer2;
29. uchar fwd_1st_pulse = 256 - 20; //20个RF周期
30. uchar field_stop; //next field stop in RF clocks
31. uchar fwd_01_zero = 256 - 20; //complement to fwd_01_stop,20个RF周期
32. uchar fwd_01_one = 256 - 29; //notmod full period '1',29个RF周期
33. uchar fwd_01_stop = 256 - 9; //9个RF周期
34. uchar edge=1; //for manchester usage
35.
36.
37. // 定时器0中断服务程序
38. // 写操作,控制MOD
39. void Timer0_int(void) interrupt 1 using 1
40. {
41. TF0=0; //clear interrupt flag
42. if (fwd_bit_phase == 1)
43. {
44. MOD=1;
45. TR0=0;
46. TH0=0xFF;
47. TL0 = field_stop;
48. TR0=1;
49. field_stop = fwd_01_stop;
50. fwd_bit_phase = 2;
51. return;
52. }
53.
54. MOD=0;
55. TR0=0;
56. if (fwd_bit_phase == 2)
57. {
58. TH0=0xFF;
59. TL0=fwd_01_zero;
60. }
61. else
62. {
63. TH0=0xFF;
64. TL0= fwd_01_one;
65. }
66. TR0=1;
67.
68. if(fwd_bit_sz-- > 0)
69. {
70. if(((*fwd_write_ptr++) & 1) == 1)
71. fwd_bit_phase = 3;
72. else
73. fwd_bit_phase = 1;
74. }
75. else
76. {
77. TR0= 0;
78. ET0=0; //disable T0 interrupt
79. TF0=0;
80. }
81. }
82. //串口中断标志位
83. uchar Rxtemp;
84. bit rx_start;
85. bit rx_finish;
86. bit rx_lenflag;
87. uchar rx_i;
88. uchar rx_len;
89. bit MYTI;
90.
91. //串口中断服务程序
92. void serial(void) interrupt 4 using 3
93. {
94. if(RI)
95. {
96. RI = 0;
97. Rxtemp = SBUF;
98. if(rx_start == 0)
99. {
100. if(Rxtemp == STX)
101. {
102. // clearrx_buff(); //清接收缓冲
103. rx_start = 1;
104. rx_finish = 0;
105. rx_lenflag = 0;
106. rx_i = 0; //接收到的个数
107. rx_len = 0;
108. rx_buff[0] = Rxtemp;
109. rx_i++; //长度+1
110. }
111. return;
112. }
113. if(rx_lenflag == 0)
114. {
115. rx_lenflag = 1;
116. rx_buff[1] = Rxtemp;
117. rx_i++;
118. rx_len = Rxtemp;
119. if(rx_len > MAX_RXNUM)
120. {
121. rx_start = 0;
122. rx_finish = 0;
123. rx_lenflag = 0;
124. }
125. return;
126. }
127. rx_buff[rx_i] = Rxtemp;
128. rx_i++;
129. rx_len--;
130. if(rx_len ==0)
131. {
132. rx_start = 0;
133. rx_finish = 1;
134. rx_lenflag = 0;
135. if(rx_buff[rx_i-1] != ETX)
136. {
137. rx_finish = 0;
138. }
139. }
140. return;
141. }
142. if(TI)
143. {
144. TI = 0;
145. MYTI = 1;
146. }
147. }
148.
149. // ==================================================================
150. void Timer2_int(void) interrupt 5 using 2
151. {
152. if (currentMaxTimeHi != 0xFF)
153. {
154. currentMaxTimeHi = 0xFF;
155. }
156. else
157. {
158. flag_wait=0;
159. ET2=0;
160. }
161. }
162.
163. void main(void)
164. {
165. uchar i;
166. uchar checksum;
167. //使能winbond W78E365内部1K SRAM
168. CHPENR = 0x87;
169. CHPENR = 0x59;
170. CHPCON = (CHPCON|0x10);
171. CHPENR = 0x00;
172.
173. //串口,定时器1,双倍速率,38400bps
174. SCON = 0x50;
175. TMOD = 0x20;
176. //TH1 = 0xf3;TL1 = 0xf3;
177. TH1 = 0xfd;TL1 = 0xfd; // 38400/22.1184M
178. PCON = PCON|0x80;
179. TR1 = 1;
180. ES = 1;
181. TI = 0;RI = 0;
182. EA = 1;
183. C_T2 = 1; //T2脚的负跳变计数,TH2,TL2自动重装
184. //EM4095 初始化
185. MOD = 0;
186. SHD = 0;
187. //串口接收初始化
188. rx_start = 0;
189. rx_finish = 0;
190. rx_lenflag = 0;
191. rx_len = 0; //还要接收的数据个数
192. rx_i = 0; //接收到个数
193. MYTI = 0;
194.
195. //配置读卡器默认值,RF/64,Manchester解码
196. config_delayed = 0;
197. config_lwr = 8;
198. config_raw = 0;
199.
200. halfDataRate = 32;//default values, RF/64
201. MaxCaptureHalfDateRate = halfDataRate + (halfDataRate >> 1); //=48
202. MaxCaptureDateRate = halfDataRate + halfDataRate + (halfDataRate >> 1); //=80
203. lwr = config_lwr;
204. delayed = config_delayed;
205. raw = config_raw;
206. //forward_link_type = 0x01;
207. maxTLogin = 4 + (4 + 9) * 2 * (uint)halfDataRate; //0x0344
208. maxTWrite = 1144 + (4 + 8) * 2 * (uint)halfDataRate;
209. maxTWriteRaw = 1144 + (4 + 5 + 54) * 2 * (uint)halfDataRate;
210. maxTRead = (100) + 4 + (5 + 54) * 2 * (uint)halfDataRate; //3880
211. maxTDisable = maxTLogin;
212. maxTDefaultRead = 2*((lwr-4)*4*8)*2*((uint32)halfDataRate);
213. tpp_period = 4 + 2 * (uint)halfDataRate - 4; //64
214. twr_period = (68 + 64 + 896 + 116) + 2 * (uint)halfDataRate - 4;
215.
216. while(1)
217. {
218. if(rx_finish == 1)//串口完成合法的接收
219. {
220. rx_finish = 0;
221. checksum = rx_buff[1];
222. for(i=2;i<=(rx_buff[1]-1);i++)
223. {
224. checksum ^= rx_buff[i];
225. }
226. if (checksum != rx_buff[rx_buff[1]]) //检查校验和
227. continue;
228. }
229. else c
评论0