📄 send.lst
字号:
307 2 }
308 1 SCS = 1;
309 1 }
310
311 /************************************************************************
312 ** A7125_ReadReg
313 ************************************************************************/
314 Uint8 A7125_ReadReg(Uint8 addr)
315 {
316 1 Uint8 i;
317 1 Uint8 tmp;
318 1
319 1 SCS = 0;
320 1 addr |= 0x40; //bit cmd=0,r/w=1
321 1 for(i = 0; i < 8; i++)
322 1 {
323 2
324 2 if(addr & 0x80)
325 2 SDIO = 1;
326 2 else
327 2 SDIO = 0;
328 2
329 2 _nop_();
330 2 SCK = 1;
331 2 _nop_();
332 2 SCK = 0;
333 2
334 2 addr = addr << 1;
335 2 }
336 1
337 1 _nop_();
338 1 SDIO = 1;
339 1
340 1 //read data
341 1 for(i = 0; i < 8; i++)
342 1 {
343 2 if(SDIO)
344 2 tmp = (tmp << 1) | 0x01;
345 2 else
346 2 tmp = tmp << 1;
347 2
348 2 SCK = 1;
349 2 _nop_();
350 2 SCK = 0;
351 2 }
352 1 SCS = 1;
353 1 return tmp;
354 1 }
355
356
357 /*********************************************************************
358 ** Strobe Command
359 *********************************************************************/
360 void StrobeCmd(Uint8 src)
361 {
362 1 Uint8 i;
363 1
364 1 SCS = 0;
365 1 for(i = 0; i < 8; i++)
C51 COMPILER V9.01 SEND 02/25/2011 12:31:38 PAGE 7
366 1 {
367 2 if(src & 0x80)
368 2 SDIO = 1;
369 2 else
370 2 SDIO = 0;
371 2
372 2 _nop_();
373 2 SCK = 1;
374 2 _nop_();
375 2 SCK = 0;
376 2 src = src << 1;
377 2 }
378 1 SCS = 1;
379 1 }
380
381 /************************************************************************
382 ** ByteSend
383 ************************************************************************/
384 void ByteSend(Uint8 src)
385 {
386 1 Uint8 i;
387 1
388 1 for(i = 0; i < 8; i++)
389 1 {
390 2 if(src & 0x80)
391 2 SDIO = 1;
392 2 else
393 2 SDIO = 0;
394 2
395 2 _nop_();
396 2 SCK = 1;
397 2 _nop_();
398 2 SCK = 0;
399 2 src = src << 1;
400 2 }
401 1 }
402
403 /************************************************************************
404 ** WriteID
405 ************************************************************************/
406 void A7125_WriteID(void)
407 {
408 1 Uint8 i;
409 1 Uint8 addr;
410 1
411 1 addr = IDCODE_REG; //send address 0x06, bit cmd=0, r/w=0
412 1 SCS = 0;
413 1 ByteSend(addr);
414 1 for (i=0; i < 4; i++)
415 1 ByteSend(ID_Tab[i]);
416 1 SCS = 1;
417 1 }
418
419 /************************************************************************
420 ** Reset_RF
421 ************************************************************************/
422 void A7125_Reset(void)
423 {
424 1 A7125_WriteReg(MODE_REG, 0x00); //reset RF chip
425 1 }
426 /*********************************************************************
427 ** CHGroupCal
C51 COMPILER V9.01 SEND 02/25/2011 12:31:38 PAGE 8
428 *********************************************************************/
429 void CHGroupCal(Uint8 ch)
430 {
431 1 Uint8 tmp;
432 1 Uint8 vb,vbcf;
433 1 Uint8 vcb,vccf;
434 1
435 1 A7125_WriteReg(PLL1_REG, ch);
436 1 A7125_WriteReg(CALIBRATION_REG, 0x1C);
437 1 do
438 1 {
439 2 tmp = A7125_ReadReg(CALIBRATION_REG);
440 2 tmp &= 0x1C;
441 2 }
442 1 while (tmp);
443 1
444 1 //for check
445 1 tmp = A7125_ReadReg(VCOCAL1_REG);
446 1 vb = tmp & 0x07;
447 1 vbcf = (tmp >>3) & 0x01;
448 1
449 1 tmp = A7125_ReadReg(VCOCCAL_REG);
450 1 vcb = tmp & 0x0F;
451 1 vccf= (tmp >> 4) & 0x01;
452 1
453 1 if (vbcf || vccf)
454 1 Err_State();//error
455 1 }
456
457 /*********************************************************************
458 ** calibration
459 *********************************************************************/
460 void A7125_Cal(void)
461 {
462 1 Uint8 tmp;
463 1 Uint8 fb,fbcf,fcd;
464 1 Uint8 dvt;
465 1
466 1 //calibration RSSI,IF procedure
467 1 StrobeCmd(CMD_PLL);
468 1 A7125_WriteReg(CALIBRATION_REG, 0x03);
469 1 do
470 1 {
471 2 tmp = A7125_ReadReg(CALIBRATION_REG);
472 2 tmp &= 0x03;
473 2 }
474 1 while (tmp);
475 1
476 1 //calibration VCO dev,VBC,VCC procedure
477 1
478 1 CHGroupCal(30); //calibrate channel group Bank I
479 1 CHGroupCal(90); //calibrate channel group Bank II
480 1 CHGroupCal(150); //calibrate channel group Bank III
481 1 StrobeCmd(CMD_STBY); //return to STBY state
482 1
483 1 //for check
484 1 tmp = A7125_ReadReg(IFCAL1_REG);
485 1 fb = tmp & 0x0F;
486 1 fbcf = (tmp >>4) & 0x01;
487 1
488 1 tmp = A7125_ReadReg(IFCAL2_REG);
489 1 fcd = tmp & 0x1F;
C51 COMPILER V9.01 SEND 02/25/2011 12:31:38 PAGE 9
490 1
491 1 tmp = A7125_ReadReg(VCOCAL2_REG);
492 1 dvt = tmp;
493 1
494 1 if (fbcf)
495 1 Err_State(); //error
496 1 }
497
498 /*********************************************************************
499 ** A7125_Config
500 *********************************************************************/
501 void A7125_Config(void)
502 {
503 1 Uint8 i;
504 1
505 1 //0x00 mode register, for reset
506 1 //0x05 fifo data register
507 1 //0x06 id code register
508 1 //0x24 IF calibration II, only read
509 1
510 1 for ( i=0x01; i<=0x38; i++ )
511 1 {
512 2 if ( (i==0x05) || (i==0x06) || (i==0x24) )
513 2 continue;
514 2
515 2 A7125_WriteReg( i, A7125Config[i] );
516 2 }
517 1 }
518
519 /*********************************************************************
520 ** initRF
521 *********************************************************************/
522 void initRF(void)
523 {
524 1 //init io pin
525 1 SCS = 1;
526 1 SCK = 0;
527 1 SDIO = 1;
528 1 GIO1 = 1;
529 1 GIO2 = 1;
530 1
531 1 A7125_Reset(); //reset A7125 RF chip
532 1 A7125_WriteID(); //write ID code
533 1 A7125_Config(); //config A7125 chip
534 1 A7125_Cal(); //calibration IF,vco, vcoc
535 1 }
536
537 //**********************************************************************
538 // WriteFIFO
539 //**********************************************************************
540 void WriteFIFO(Uint8 length)
541 {
542 1 Uint8 i;
543 1 A7125_WriteReg( FIFO1_REG, length-1); // set FIFO length
544 1 StrobeCmd(CMD_TFR); // Reset TX FIFO point
545 1
546 1 SCS=0;
547 1 ByteSend(FIFO_REG);
548 1 for(i=0; i <length; i++)
549 1 ByteSend(PN9_Tab[i]);
550 1 SCS=1;
551 1 }
C51 COMPILER V9.01 SEND 02/25/2011 12:31:38 PAGE 10
552 //**********************************************************************
553 Uint8 ByteRead(void)
554 {
555 1 Uint8 i,tmp;
556 1
557 1 SDIO = 1; //sdio pull high
558 1 for(i = 0; i < 8; i++)
559 1 {
560 2 if(SDIO)
561 2 tmp = (tmp << 1) | 0x01;
562 2 else
563 2 tmp = tmp << 1;
564 2 SCK = 1;
565 2 _nop_();
566 2 SCK = 0;
567 2 }
568 1 return tmp;
569 1 }
570 //**********************************************************************
571 // ReadFIFO
572 //**********************************************************************
573 void ReadFIFO(Uint8 length)
574 {
575 1 Uint8 i;
576 1
577 1 SCS = 0;
578 1 ByteSend(FIFO_REG | 0x40);
579 1 for(i = 0; i <length; i++)
580 1 RfBuf[i] = ByteRead();
581 1 SCS=1;
582 1 }
583 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
584 // DELAY 1MS FUNCTION //
585 // USER NEED CHANGE THIS FUNCTION TO FIT SYSTEM. //
586 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
587 void Delay1ms(Uint16 n)
588 {
589 1 Uint8 i, j;
590 1 while(n--)
591 1 {
592 2 for(j = 0; j < 6; j ++)
593 2 {
594 3 for(i = 0; i < 235; i ++)
595 3 {
596 4 _nop_();
597 4 _nop_();
598 4 _nop_();
599 4 _nop_();
600 4 }
601 3 }
602 2 }
603 1 }
604
605
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 731 ----
CONSTANT SIZE = 182 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 10
C51 COMPILER V9.01 SEND 02/25/2011 12:31:38 PAGE 11
IDATA SIZE = 65 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -