⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cc1020pic.lst

📁 cc1020+atmega8子程序 用于无线收发模块
💻 LST
📖 第 1 页 / 共 2 页
字号:
     1: /****************************************************************************/
     2: /* Microcontroller (PIC) software library for CC1020 application            */
     3: /*                                                                          */
     4: /* File:      cc1020pic.c                                                   */
     5: /*                                                                          */
     6: /* Microcontroller:                                                         */
     7: /*          Microchip PIC16F876                                             */
     8: /*                                                                          */
     9: /* Written for the IAR PIC16 compiler                                       */
    10: /*                                                                          */
    11: /* Author:  Arne Rogndalen, Design Engineer, Chipcon                        */
    12: /*          Torgeir Sundet, FAE Software, Chipcon                           */
    13: /*                                                                          */
    14: /* Contact: Chipcon AS +47 22 95 85 44                                      */
    15: /*          support@chipcon.com                                             */
    16: /*                                                                          */
    17: /****************************************************************************/
    18: 
    19: /****************************************************************************/
    20: /* This library contains functions for configuring the CC1020. These        */
    21: /* routines use bit-banging to program the CC1020, faster configuration is  */
    22: /* possible by using a synchronous serial port such as a SPI interface.     */
    23: /* The header file "modemhw.h" contains definitions for the various I/O     */
    24: /* pins, the user should make a similar file to name the pins used to       */
    25: /* communicate with the CC1020. Routines to read and write the calibration  */
    26: /* values in the CC1020 are provided, they are not used in this reference   */
    27: /* application, but are useful in other applications, most notably          */
    28: /* frequency-agile and frequency hopping applications. See application      */
    29: /* note AN009 for more information.                                         */
    30: /* The routines in this file will have to be adapted depending on the MCU   */
    31: /* and compiler used. The method used for shifting data in and out may have */
    32: /* to be changed if the bit ordering for bitfields is different from the    */
    33: /* IAR PIC compiler.                                                        */
    34: /*                                                                          */
    35: /* Configuration routines are included in two versions: one using general   */
    36: /* I/O ports ("bit-banging"), and one using the built-in SPI interface of   */
    37: /* the PIC16F876. If possible, the SPI version should be used, as this is   */
    38: /* much faster. The SPI versions are used if the symbol "SPI" is defined,   */
    39: /* otherwise the general I/O-based version is used.                         */
    40: /****************************************************************************/
    41: 
    42: /*                                                                           *
    43:  * Revision history:                                                         *
    44:  *                                                                           *
    45:  * $Log: cc1020pic.c,v $
    46:  * Revision 1.7  2005/11/22 15:25:36  tos
    47:  * Removed osbolete code (AGC freeze).
    48:  *
    49:  * Revision 1.6  2005/11/22 14:31:40  tos
    50:  * Mods:
    51:  * - Finalised support for Errata Note 04.
    52:  * - Tydied-up implementation of RSSI measurement.
    53:  *
    54:  * Revision 1.5  2005/04/21 14:14:08  tos
    55:  * Modified calibration function according to Errata Note 04.
    56:  * Synchronised implementation of RSSI function with corresponding application note AN030.
    57:  *
    58:  * Revision 1.4  2004/03/23 16:44:23  tos
    59:  * Introduced RSSI measurement (based on algorithm in SmartRF Studio).
    60:  *
    61:  * Revision 1.3  2003/12/16 14:58:58  tos
    62:  * Removed 5 msec delay/wait before LOCK monitor.
    63:  *
    64:  * Revision 1.2  2003/09/17 15:58:02  tos
    65:  * Mod's:
    66:  * - tuned AFC_CONTROL for optimum preamble performance.
    67:  * - turn on TX before PA is increased.
    68:  *
    69:  * Revision 1.1  2003/07/31 13:17:16  tos
    70:  * Initial version in CVS.
    71:  *
    72:  *
    73:  *                                                                           *
    74:  ****************************************************************************/
    75: 
    76: 
    77: #include "io16f876.h"
    78: #include "CC1020.h"
    79: #include "modemhw.h"
    80: 
    81: 
    82: /****************************************************************************/
    83: /*  This routine sends new configuration data to the CC1020                 */
    84: /****************************************************************************/
    85: 
    86: void ConfigureCC1020(char Count, short Configuration[])
    87: {
    88:   short val;
    89:   char i;
    90:   
    91:   for (i=0;i<Count;i++) {
    92:     val=Configuration[i];
    93:     WriteToCC1020RegisterWord(val);
    94:   }
    95:    
    96: }
    97: 
    98: /****************************************************************************/
    99: /* SPI versions of configuration routines. The SPI interface must be        */
   100: /* initialised correctly before use                                         */
   101: /****************************************************************************/
   102: 
   103: #ifdef SPI
   104: 
   105: 
   106: /****************************************************************************/
   107: /*  This routine sets up the CC1020 for SPI transfer                        */
   108: /****************************************************************************/
   109: 
   110: void SetupCC1020ForSPI(void)
   111: {
   112:   SSPSTAT=0x40; 
   113:   SSPCON=0x20;
   114: }
   115: 
   116: /****************************************************************************/
   117: /*  This routine writes to a single CC1020 register                         */
   118: /****************************************************************************/
   119: 
   120: void WriteToCC1020Register(char addr, char data)
   121: {
   122:   char dummy;
   123: 
   124:   PSEL=0;
   125:    
   126:   dummy=SSPBUF;
   127:   SSPBUF=(addr<<1)|0x01; // Write address to CC1020, write bit is always 1
   128:  
   129:   // Wait until data is written 
   130:   while (BF==0);    
   131: 
   132:   dummy=SSPBUF;  
   133:   SSPBUF=data;
   134:   while (BF==0);
   135: 
   136:   PSEL=1;
   137: }
   138: 
   139: /****************************************************************************/
   140: /*  This routine writes to a single CC1020 register, with data and address  */
   141: /*  given in the same variable                                              */
   142: /****************************************************************************/
   143: 
   144: void WriteToCC1020RegisterWord(short addranddata)
   145: {
   146:   char dummy;
   147:   
   148:   union {
   149:     unsigned short data;
   150:     struct {
   151:       char LowByte;
   152:       char HighByte;
   153:     };
   154:   };
   155: 
   156:   data=addranddata;
   157:   PSEL=0;
   158:    
   159:   dummy=SSPBUF;
   160:   SSPBUF=LowByte|0x01; // Write address to CC1020, write bit is always 1
   161:  
   162:   // Wait until data is written 
   163:   while (BF==0);    
   164:   
   165:   dummy=SSPBUF;  
   166:   SSPBUF=HighByte;
   167:   while (BF==0);
   168: 
   169:   PSEL=1;
   170: }
   171: 
   172: /****************************************************************************/
   173: /*  This routine reads from a single CC1020 register                        */
   174: /****************************************************************************/
   175: 
   176: char ReadFromCC1020Register(char addr)
   177: {
   178:   char Value;
   179: 
   180:   PSEL=0;
   181:   Value=SSPBUF;
   182:   SSPBUF=(addr<<1)&0xFE; // Write address to CC1020, write bit is always 0
   183:   
   184:   // Wait until data is written 
   185:   while (BF==0);
   186:   SSPOV=0;
   187:   
   188:   // Switch direction 
   189:   PDI=1;
   190:   TRISC|=0x20; // Set up PDATAOUT as an input
   191:   
   192:   SSPBUF=0xFF; // Dummy write 
   193:   
   194:   while (BF==0);
   195:   Value=SSPBUF;
   196:   
   197:   TRISC&=~0x20; // Set PDATAOUT as an output 
   198: 
   199:   PSEL=1;
   200:   return Value;
   201: }
   202: 
   203: #else  
   204: 
   205: /****************************************************************************/
   206: /* General I/O pin "bit-bashing" versions of configuration routines.        */
   207: /****************************************************************************/
   208: 
   209: /****************************************************************************/
   210: /*  This routine writes to a single CC1020 register                         */
   211: /****************************************************************************/
   212: 
   213: void WriteToCC1020Register(char addr, char data)
   214: {
   215:   short val;
   216:   
   217:   val=(short) (addr&0x7F)<<9 | (short) data &0x00FF;
   218:   WriteToCC1020RegisterWord(val);
   219: }
   220: 
   221: /****************************************************************************/
   222: /*  This routine writes to a single CC1020 register, with address and data  */
   223: /*  given in the same variable                                              */
   224: /****************************************************************************/
   225: 
   226: void WriteToCC1020RegisterWord(short addranddata)
   227: {
   228:   char  BitCounter;
   229:   char Low;
   230:   char High;
   231:   union {
   232:     unsigned short data;
   233:     struct
   234:     {
   235:       char LowByte;
   236:       char HighByte;
   237:     };
   238:   };
   239:   
   240:   PSEL=1;
   241: 
   242:   data=addranddata;
   243: 
   244:   PSEL=0;
   245:     
   246:   Low=LowByte;
   247: 
   248:   // Send address bits 
   249:   for (BitCounter=0;BitCounter<7;BitCounter++)
   250:   {
   251:     PCLK=0;
   252:     PDI=((Low&0x80)>>7);
   253:     Low=Low<<1;
   254:     PCLK=1;
   255:   }
   256:   // Send read/write bit 
   257:   // Ignore bit in data, always use 1 
   258:   
   259:   PCLK=0;
   260:   PDI=1;
   261:   PCLK=1;
   262:   PCLK=0;
   263: 
   264:   High=HighByte;
   265: 
   266:   // Send data bits 
   267:   for (BitCounter=0;BitCounter<8;BitCounter++)
   268:   {
   269:     PCLK=0;
   270:     PDI=((High&0x80)>>7);
   271:     High=High<<1;
   272:     PCLK=1;
   273:   }
   274:   PCLK=0;
   275: 
   276:   PSEL=1;
   277: }
   278: 
   279: /****************************************************************************/
   280: /*  This routine reads from a single CC1020 register                        */
   281: /****************************************************************************/
   282: 
   283: char ReadFromCC1020Register(char addr)
   284: {
   285:   char BitCounter;
   286:   char Byte;
   287: 
   288:   PSEL=1;
   289:   
   290:   Byte=addr<<1;
   291:   PSEL=0;
   292:     
   293:   // Send address bits
   294:   for (BitCounter=0;BitCounter<7;BitCounter++)
   295:   {
   296:     PCLK=0;
   297:     PDI=((Byte&0x80)>>7);
   298:     Byte=Byte<<1;
   299:     PCLK=1;
   300:   }
   301:   // Send read/write bit 
   302:   // Ignore bit in data, always use 0 
   303:   
   304:   PCLK=0;
   305:   PDI=0;
   306:   PCLK=1;
   307:  
   308:   PCLK=0;
   309:     
   310:   // Receive data bits 
   311:   
   312:   PDI=1;
   313:    
   314:   TRISC|=0x20; // Set up PDATA as an input
   315:     
   316:   for (BitCounter=0;BitCounter<8;BitCounter++)
   317:   {
   318:     PCLK=1;
   319:     Byte=Byte<<1;
   320:     Byte=Byte|PDO;
   321:     PCLK=0;
   322:   }
   323:   
   324:   TRISC&=~0x20; // Set up PDATA as an output again
   325:   
   326:   PSEL=1;
   327: 
   328:   return Byte;
   329: }
   330: 
   331: #endif
   332:   
   333: /****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -