📄 function.lst
字号:
C51 COMPILER V7.07 FUNCTION 06/13/2008 13:33:17 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE FUNCTION
OBJECT MODULE PLACED IN function.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE function.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 ///////////////////////////////////////////////////////////////////////////////
2 #include <Mfreg500.h>
3 #include <M500A.h>
4 #include <string.h>
5
6 extern void delay_50us(unsigned char time);
7 // reset struct
8 #define ResetInfo(info) \
9 info.nBytesToSend = 0; \
10 info.nBytesSent = 0; \
11 info.nBytesReceived = 0; \
12 info.nBitsReceived = 0; \
13 info.irqSource = 0; \
14 info.collPos = 0;
15
16
17 // struct definition for a communication channel
18 typedef struct
19 {
20 unsigned char nBytesToSend; // how many bytes to send
21 unsigned char nBytesSent; // how many bytes sent
22 unsigned char nBytesReceived;// how many bytes received
23 unsigned int nBitsReceived; // how many bits received
24 unsigned char irqSource; //
25 unsigned char collPos; // at which position occured a collision
26
27 } MfCmdInfo;
28
29
30 static unsigned char idata MFIFOLength = DEF_FIFO_LENGTH; // actual FIFO length
31
32 // send buffer
33 static volatile unsigned char MSndBuffer[SND_BUF_LEN];
34 // receive buffer
35 static volatile unsigned char MRcvBuffer[RCV_BUF_LEN];
36 // info struct
37 static volatile MfCmdInfo MInfo;
38
39 extern void WriteIO(unsigned char add,unsigned char value);
40 extern unsigned char ReadIO(unsigned char add);
41
42
43 char SetBitMask(unsigned char reg,unsigned char mask) //
44 {
45 1 char idata tmp = 0x0;
46 1
47 1 tmp = ReadIO(reg) | mask;
48 1 WriteIO(reg,tmp);
49 1 return 0x0;
50 1 }
51
52 char ClearBitMask(unsigned char reg,unsigned char mask)
53 {
54 1 char idata tmp = 0x0;
55 1
C51 COMPILER V7.07 FUNCTION 06/13/2008 13:33:17 PAGE 2
56 1 tmp = ReadIO(reg) & ~mask;
57 1 WriteIO(reg,tmp); // clear bit mask
58 1 return 0x0;
59 1 }
60
61
62 void FlushFIFO(void)
63 {
64 1 SetBitMask(RegControl,0x01);
65 1 }
66
67
68 void RC500Config(void)
69 {
70 1
71 1 while ((ReadIO(RegCommand) & 0x3F) == 0x3F); // 接口初始化检查
72 1
73 1 WriteIO(RegPage,0x80);
74 1 while ((ReadIO(RegCommand) & 0x3F) == 0x3F);
75 1
76 1 WriteIO(RegPage,0x00); // 线性地址模式
77 1 WriteIO(RegClockQControl,0x00);
78 1 WriteIO(RegClockQControl,0x40);
79 1 delay_50us(2);
80 1 ClearBitMask(RegClockQControl,0x40);
81 1 WriteIO(RegBitPhase,0xaa);
82 1 WriteIO(RegRxThreshold,0xDF);
83 1 WriteIO(RegRxControl2,0x01);
84 1 WriteIO(RegRxWait,0x05);
85 1 WriteIO(RegFIFOLevel,0x05);
86 1 WriteIO(RegTimerControl,0x00);
87 1 WriteIO(RegTimerClock,0x10);
88 1 WriteIO(RegTimerReload,0x32);
89 1 WriteIO(RegInterruptEn,0x7F);
90 1 ClearBitMask(RegTxControl,0x03);
91 1 delay_50us(20);
92 1 SetBitMask(RegTxControl,0x03);
93 1
94 1 }
95
96
97 char RC500Cmd(unsigned char cmd,
98 volatile unsigned char* send,
99 volatile unsigned char* rcv,
100 volatile MfCmdInfo *info)
101 {
102 1 char idata status = MI_OK;
103 1
104 1 unsigned char irqBits;
105 1 unsigned char lastBits;
106 1 unsigned char irqMask;
107 1 unsigned char nbytes;
108 1 unsigned char cnt;
109 1 unsigned char tmpStatus ;
110 1
111 1 unsigned char irqEn = 0x00;
112 1 unsigned char waitFor = 0x00;
113 1 unsigned char TimeOut = 0x00;
114 1
115 1
116 1 WriteIO(RegInterruptEn,0x7F);
117 1 WriteIO(RegInterruptRq,0x7F);
C51 COMPILER V7.07 FUNCTION 06/13/2008 13:33:17 PAGE 3
118 1 WriteIO(RegCommand,PCD_IDLE);
119 1
120 1 FlushFIFO();
121 1
122 1 switch(cmd)
123 1 {
124 2 case PCD_IDLE: // nothing else required
125 2 irqEn = 0x00;
126 2 waitFor = 0x00;
127 2 break;
128 2 case PCD_WRITEE2: // LoAlert and TxIRq
129 2 irqEn = 0x11;
130 2 waitFor = 0x10;
131 2 break;
132 2 case PCD_READE2: // HiAlert, LoAlert and IdleIRq
133 2 irqEn = 0x07;
134 2 waitFor = 0x04;
135 2 break;
136 2 case PCD_LOADCONFIG: // IdleIRq
137 2 case PCD_LOADKEYE2: // IdleIRq
138 2 case PCD_AUTHENT1: // IdleIRq
139 2 irqEn = 0x05;
140 2 waitFor = 0x04;
141 2 break;
142 2 case PCD_CALCCRC: // LoAlert and TxIRq
143 2 irqEn = 0x11;
144 2 waitFor = 0x10;
145 2 break;
146 2 case PCD_AUTHENT2: // IdleIRq
147 2 irqEn = 0x04;
148 2 waitFor = 0x04;
149 2 break;
150 2 case PCD_RECEIVE: // HiAlert and IdleIRq
151 2 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
152 2 irqEn = 0x06;
153 2 waitFor = 0x04;
154 2 break;
155 2 case PCD_LOADKEY: // IdleIRq
156 2 irqEn = 0x05;
157 2 waitFor = 0x04;
158 2 break;
159 2 case PCD_TRANSMIT: // LoAlert and IdleIRq
160 2 irqEn = 0x05;
161 2 waitFor = 0x04;
162 2 break;
163 2 case PCD_TRANSCEIVE: // TxIrq, RxIrq, IdleIRq and LoAlert
164 2 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
165 2 irqEn = 0x3D;
166 2 waitFor = 0x04;
167 2 break;
168 2 default:
169 2 status = MI_UNKNOWN_COMMAND;
170 2 }
171 1 if (status == MI_OK)
172 1 {
173 2 irqEn |= 0x20;
174 2 waitFor |= 0x20;
175 2 WriteIO(RegInterruptEn,irqEn | 0x80);
176 2 SetBitMask(RegControl,0x02);
177 2
178 2 WriteIO(RegCommand,cmd);
179 2 while (!(info->irqSource & waitFor || TimeOut))
C51 COMPILER V7.07 FUNCTION 06/13/2008 13:33:17 PAGE 4
180 2 {
181 3 while( ReadIO(RegPrimaryStatus) & 0x08)
182 3 {
183 4 irqMask = ReadIO(RegInterruptEn);
184 4 irqBits = ReadIO(RegInterruptRq) & irqMask;
185 4 info->irqSource |= irqBits;
186 4 if (irqBits & 0x01)
187 4 {
188 5 nbytes = MFIFOLength - ReadIO(RegFIFOLength);
189 5 if ((info->nBytesToSend - info->nBytesSent) <= nbytes)
190 5 {
191 6 nbytes = info->nBytesToSend - info->nBytesSent;
192 6 WriteIO(RegInterruptEn,0x01);
193 6 }
194 5 for ( cnt = 0;cnt < nbytes;cnt++)
195 5 {
196 6 WriteIO(RegFIFOData,send[info->nBytesSent]);
197 6 info->nBytesSent++;
198 6 }
199 5 WriteIO(RegInterruptRq,0x01);
200 5 }
201 4 if (irqBits & 0x10)
202 4 {
203 5 WriteIO(RegInterruptRq,0x10);
204 5 WriteIO(RegInterruptEn,0x82);
205 5 if (cmd == PICC_ANTICOLL1)
206 5 {
207 6 WriteIO(RegChannelRedundancy,0x02);
208 6 }
209 5 }
210 4 if (irqBits & 0x0E)
211 4 {
212 5 nbytes = ReadIO(RegFIFOLength);
213 5 for ( cnt = 0; cnt < nbytes; cnt++)
214 5 {
215 6 rcv[info->nBytesReceived] = ReadIO(RegFIFOData);
216 6 info->nBytesReceived++;
217 6 }
218 5 WriteIO(RegInterruptRq,0x0A & irqBits);
219 5 }
220 4 if (irqBits & 0x04)
221 4 {
222 5 WriteIO(RegInterruptEn,0x20);
223 5 WriteIO(RegInterruptRq,0x20);
224 5 irqBits &= ~0x20;
225 5 info->irqSource &= ~0x20;
226 5 WriteIO(RegInterruptRq,0x04);
227 5 }
228 4 if (irqBits & 0x20)
229 4 {
230 5 WriteIO(RegInterruptRq,0x20);
231 5 status = MI_NOTAGERR;
232 5 TimeOut = 1;
233 5 break;
234 5 }
235 4 }
236 3 }
237 2 WriteIO(RegInterruptEn,0x7F);
238 2 WriteIO(RegInterruptRq,0x7F);
239 2 SetBitMask(RegControl,0x04);
240 2
241 2 WriteIO(RegCommand,PCD_IDLE);
C51 COMPILER V7.07 FUNCTION 06/13/2008 13:33:17 PAGE 5
242 2
243 2 if (!(info->irqSource & waitFor))
244 2 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -