📄 rf_manchester.lst
字号:
229 5 mcsbuf.Pro=0xff;
230 5 return(1);
231 5 }
232 4 else
233 4 {
234 5 mcsbuf.Pro=0x11;
235 5 return(2); //如果前一位数据已经处理完毕,则从新开始纪录数据便于下次处理
236 5 }
237 4 }
238 3 else
239 3 {
240 4 mcsbuf.Head=mcsHeadNull;
241 4 return(3); //在没有确定起始检测位时所有数据不予理会
C51 COMPILER V7.50 RF_MANCHESTER 05/31/2006 22:17:06 PAGE 5
242 4 }
243 3 }
244 2 else if((High_Timer<MinHalfLevel)||(High_Timer>MaxAllLevel))
245 2 {
246 3 mcsbuf.Head=mcsHeadNull;
247 3 return(3); //在没有确定起始检测位时所有数据不予理会
248 3 }
249 2 }
250 1 }
251
252
253
254 /*--------------------------------------------------------------------------------
255 函数: Push_Data(uchar PDData)
256 功能: 检测的数据保存
257 引用值:uchar PDData:1 or 0
258 返回值:无
259 --------------------------------------------------------------------------------*/
260 void Push_Data(uchar PDData)
261 {
262 1 i=DataHeadbuf.intHigh+DataHeadbuf.intLow;
263 1 if(i<=55)
264 1 {
265 2 i=(i-1)%8;
266 2 if(PDData==0x01)
267 2 {
268 3 switch(i)
269 3 {
270 4 case 0:pBuf0=1; break;
271 4 case 1:pBuf1=1; break;
272 4 case 2:pBuf2=1; break;
273 4 case 3:pBuf3=1; break;
274 4 case 4:pBuf4=1; break;
275 4 case 5:pBuf5=1; break;
276 4 case 6:pBuf6=1; break;
277 4 case 7:pBuf7=1; break;
278 4 }
279 3 }
280 2 else if(PDData==0x00)
281 2 {
282 3 switch(i)
283 3 {
284 4 case 0:pBuf0=0; break;
285 4 case 1:pBuf1=0; break;
286 4 case 2:pBuf2=0; break;
287 4 case 3:pBuf3=0; break;
288 4 case 4:pBuf4=0; break;
289 4 case 5:pBuf5=0; break;
290 4 case 6:pBuf6=0; break;
291 4 case 7:pBuf7=0; break;
292 4 }
293 3 }
294 2 i=DataHeadbuf.intHigh+DataHeadbuf.intLow-1;
295 2 i=i/8;
296 2 RecvBuf[i]=pBuf;
297 2 }
298 1
299 1 i=DataHeadbuf.intHigh+DataHeadbuf.intLow;
300 1 if(i==55) //数据读取完毕,发送
301 1 {
302 2 for(i=0;i<7;i++)
303 2 {
C51 COMPILER V7.50 RF_MANCHESTER 05/31/2006 22:17:06 PAGE 6
304 3 Send_Data(RecvBuf[i]);
305 3 }
306 2 i=Calibration();
307 2 if(i)
308 2 for(i=0;i<7;i++)
309 2 {
310 3 Send_Data(RecvBuf[i]);
311 3 RecvBuf[i]=0x55;
312 3 }
313 2
314 2 i=P2;
315 2 P2=~i;
316 2 OS_Status=Start_Find; //发送完毕,置位从新检测
317 2 DataHeadbuf.intHigh=0;
318 2 DataHeadbuf.intLow=0;
319 2 mcsbuf.Head=mcsHeadNull;
320 2 }
321 1 }
322
323
324 /*--------------------------------------------------------------------------------
325 函数:
326 功能:
327 引用值:
328 返回值:
329 --------------------------------------------------------------------------------*/
330 uchar Calibration(void)
331 {
332 1 temp1=RecvBuf[0] & 0x1F;
333 1 temp2=(temp1 & 0x10)>>4;
334 1 temp1=temp1& 0x0F;
335 1 if(temp2!=Adj[temp1])
336 1 return(0); //校验失败1
337 1
338 1 RecvBuf[0]=(RecvBuf[0] & 0xF0) | temp1;
339 1
340 1 temp1=RecvBuf[0]>>5 | (RecvBuf[1] & 0x03 )<<3;
341 1 temp2=(temp1 & 0x10)>>4;
342 1 temp1=temp1& 0x0F;
343 1 if(temp2!=Adj[temp1])
344 1 return(0); //校验失败2
345 1
346 1 RecvBuf[0]=(RecvBuf[0] & 0x0F) | temp1<<4;
347 1
348 1 temp1=(RecvBuf[1]>>2) & 0x1F;
349 1 temp2=(temp1 & 0x10)>>4;
350 1 temp1=temp1& 0x0F;
351 1 if(temp2!=Adj[temp1])
352 1 return(0); //校验失败3
353 1
354 1 RecvBuf[1]=(RecvBuf[1] & 0xF0) | temp1;
355 1
356 1 temp1=RecvBuf[1]>>7 | (RecvBuf[2] & 0x0F)<<1;
357 1 temp2=(temp1 & 0x10)>>4;
358 1 temp1=temp1& 0x0F;
359 1 if(temp2!=Adj[temp1])
360 1 return(0); //校验失败4
361 1
362 1 RecvBuf[1]=(RecvBuf[1] & 0x0F) | temp1<<4;
363 1
364 1 temp1=(RecvBuf[2]>>4 & 0x0F)| (RecvBuf[3] & 0x01)<<4;
365 1 temp2=(temp1 & 0x10)>>4;
C51 COMPILER V7.50 RF_MANCHESTER 05/31/2006 22:17:06 PAGE 7
366 1 temp1=temp1& 0x0F;
367 1 if(temp2!=Adj[temp1])
368 1 return(0); //校验失败5
369 1
370 1 RecvBuf[2]=(RecvBuf[2] & 0xF0) | temp1;
371 1
372 1 temp1=RecvBuf[3]>>1 & 0x1F;
373 1 temp2=(temp1 & 0x10)>>4;
374 1 temp1=temp1& 0x0F;
375 1 if(temp2!=Adj[temp1])
376 1 return(0); //校验失败6
377 1
378 1 RecvBuf[2]=(RecvBuf[2] & 0x0F) | temp1<<4;
379 1
380 1 temp1=((RecvBuf[3]>>6) & 0x03) | ((RecvBuf[4] <<2) & 0x1c);
381 1 temp2=(temp1 & 0x10)>>4;
382 1 temp1=temp1& 0x0F;
383 1 if(temp2!=Adj[temp1])
384 1 return(0); //校验失败7
385 1
386 1 RecvBuf[3]=(RecvBuf[3] & 0xF0) | temp1;
387 1
388 1 temp1=RecvBuf[4]>>3;
389 1 temp2=(temp1 & 0x10)>>4;
390 1 temp1=temp1& 0x0F;
391 1 if(temp2!=Adj[temp1])
392 1 return(0); //校验失败8
393 1
394 1 RecvBuf[3]=(RecvBuf[3] & 0x0F) | temp1<<4;
395 1
396 1 temp1=RecvBuf[5] & 0x1F;
397 1 temp2=(temp1 & 0x10)>>4;
398 1 temp1=temp1& 0x0F;
399 1 if(temp2!=Adj[temp1])
400 1 return(0); //校验失败9
401 1
402 1 RecvBuf[4]=(RecvBuf[4] & 0xF0) | temp1;
403 1
404 1 temp1=RecvBuf[5]>>5 | (RecvBuf[6] & 0x03 )<<3;
405 1 temp2=(temp1 & 0x10)>>4;
406 1 temp1=temp1& 0x0F;
407 1 if(temp2!=Adj[temp1])
408 1 return(0); //校验失败2
409 1
410 1 RecvBuf[4]=(RecvBuf[4] & 0x0F) | temp1<<4;
411 1
412 1 RecvBuf[5]=(RecvBuf[6]>>2) & 0x0F;
413 1
414 1 temp1=0;
415 1 for(i=0;i<5;i++)
416 1 {
417 2 temp1=temp1^(RecvBuf[i] & 0x01)^((RecvBuf[i] & 0x10) >>4);
418 2 }
419 1 temp2=RecvBuf[5]&0x01;
420 1 if(temp1!=temp2)
421 1 return(0);
422 1
423 1 temp1=0;
424 1 for(i=0;i<5;i++)
425 1 {
426 2 temp1=temp1^((RecvBuf[i] & 0x02)>>1)^((RecvBuf[i] & 0x20) >>5);
427 2 }
C51 COMPILER V7.50 RF_MANCHESTER 05/31/2006 22:17:06 PAGE 8
428 1 temp2=(RecvBuf[5]&0x02)>>1;
429 1 if(temp1!=temp2)
430 1 return(0);
431 1
432 1 temp1=0;
433 1 for(i=0;i<5;i++)
434 1 {
435 2 temp1=temp1^((RecvBuf[i] & 0x04)>>2)^((RecvBuf[i] & 0x40) >>6);
436 2 }
437 1 temp2=(RecvBuf[5]&0x04)>>2;
438 1 if(temp1!=temp2)
439 1 return(0);
440 1
441 1 temp1=0;
442 1 for(i=0;i<5;i++)
443 1 {
444 2 temp1=temp1^((RecvBuf[i] & 0x08)>>3)^((RecvBuf[i] & 0x80) >>7);
445 2 }
446 1 temp2=(RecvBuf[5]&0x08)>>3;
447 1 if(temp1!=temp2)
448 1 return(0);
449 1
450 1 return(1);
451 1 }
452
453
454 /*--------------------------------------------------------------------------------
455 函数: HeadFindHandle(uchar HFHData)
456 功能: 数据起始字头判断(找出9个连续的1)
457 引用值:uchar HFHData:由Manchster()解码出的数据(0,1,2,3)
458 返回值:无
459 --------------------------------------------------------------------------------*/
460 void HeadFindHandle(uchar HFHData)
461 {
462 1 if(HFHData==1)
463 1 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -