?? cc1020pic.c
字號:
/****************************************************************************/
/* Microcontroller (PIC) software library for CC1020 application */
/* */
/* File: cc1020pic.c */
/* */
/* Microcontroller: */
/* Microchip PIC16F876 */
/* */
/* Written for the IAR PIC16 compiler */
/* */
/* Author: Arne Rogndalen, Design Engineer, Chipcon */
/* Torgeir Sundet, FAE Software, Chipcon */
/* */
/* Contact: Chipcon AS +47 22 95 85 44 */
/* support@chipcon.com */
/* */
/****************************************************************************/
/****************************************************************************/
/* This library contains functions for configuring the CC1020. These */
/* routines use bit-banging to program the CC1020, faster configuration is */
/* possible by using a synchronous serial port such as a SPI interface. */
/* The header file "modemhw.h" contains definitions for the various I/O */
/* pins, the user should make a similar file to name the pins used to */
/* communicate with the CC1020. Routines to read and write the calibration */
/* values in the CC1020 are provided, they are not used in this reference */
/* application, but are useful in other applications, most notably */
/* frequency-agile and frequency hopping applications. See application */
/* note AN009 for more information. */
/* The routines in this file will have to be adapted depending on the MCU */
/* and compiler used. The method used for shifting data in and out may have */
/* to be changed if the bit ordering for bitfields is different from the */
/* IAR PIC compiler. */
/* */
/* Configuration routines are included in two versions: one using general */
/* I/O ports ("bit-banging"), and one using the built-in SPI interface of */
/* the PIC16F876. If possible, the SPI version should be used, as this is */
/* much faster. The SPI versions are used if the symbol "SPI" is defined, */
/* otherwise the general I/O-based version is used. */
/****************************************************************************/
/* *
* Revision history: *
* *
* $Log: cc1020pic.c,v $
* Revision 1.3 2003/12/16 14:58:58 tos
* Removed 5 msec delay/wait before LOCK monitor.
*
* Revision 1.2 2003/09/17 15:58:02 tos
* Mod's:
* - tuned AFC_CONTROL for optimum preamble performance.
* - turn on TX before PA is increased.
*
* Revision 1.1 2003/07/31 13:17:16 tos
* Initial version in CVS.
*
*
* *
****************************************************************************/
#include "io16f876.h"
#include "CC1020.h"
#include "modemhw.h"
/****************************************************************************/
/* This routine sends new configuration data to the CC1020 */
/****************************************************************************/
void ConfigureCC1020(char Count, short Configuration[])
{
short val;
char i;
for (i=0;i<Count;i++) {
val=Configuration[i];
WriteToCC1020RegisterWord(val);
}
}
/****************************************************************************/
/* SPI versions of configuration routines. The SPI interface must be */
/* initialised correctly before use */
/****************************************************************************/
#ifdef SPI
/****************************************************************************/
/* This routine sets up the CC1020 for SPI transfer */
/****************************************************************************/
void SetupCC1020ForSPI(void)
{
SSPSTAT=0x40;
SSPCON=0x20;
}
/****************************************************************************/
/* This routine writes to a single CC1020 register */
/****************************************************************************/
void WriteToCC1020Register(char addr, char data)
{
char dummy;
PSEL=0;
dummy=SSPBUF;
SSPBUF=(addr<<1)|0x01; // Write address to CC1020, write bit is always 1
// Wait until data is written
while (BF==0);
dummy=SSPBUF;
SSPBUF=data;
while (BF==0);
PSEL=1;
}
/****************************************************************************/
/* This routine writes to a single CC1020 register, with data and address */
/* given in the same variable */
/****************************************************************************/
void WriteToCC1020RegisterWord(short addranddata)
{
char dummy;
union {
unsigned short data;
struct {
char LowByte;
char HighByte;
};
};
data=addranddata;
PSEL=0;
dummy=SSPBUF;
SSPBUF=LowByte|0x01; // Write address to CC1020, write bit is always 1
// Wait until data is written
while (BF==0);
dummy=SSPBUF;
SSPBUF=HighByte;
while (BF==0);
PSEL=1;
}
/****************************************************************************/
/* This routine reads from a single CC1020 register */
/****************************************************************************/
char ReadFromCC1020Register(char addr)
{
char Value;
PSEL=0;
Value=SSPBUF;
SSPBUF=(addr<<1)&0xFE; // Write address to CC1020, write bit is always 0
// Wait until data is written
while (BF==0);
SSPOV=0;
// Switch direction
PDI=1;
TRISC|=0x20; // Set up PDATAOUT as an input
SSPBUF=0xFF; // Dummy write
while (BF==0);
Value=SSPBUF;
TRISC&=~0x20; // Set PDATAOUT as an output
PSEL=1;
return Value;
}
#else
/****************************************************************************/
/* General I/O pin "bit-bashing" versions of configuration routines. */
/****************************************************************************/
/****************************************************************************/
/* This routine writes to a single CC1020 register */
/****************************************************************************/
void WriteToCC1020Register(char addr, char data)
{
short val;
val=(short) (addr&0x7F)<<9 | (short) data &0x00FF;
WriteToCC1020RegisterWord(val);
}
/****************************************************************************/
/* This routine writes to a single CC1020 register, with address and data */
/* given in the same variable */
/****************************************************************************/
void WriteToCC1020RegisterWord(short addranddata)
{
char BitCounter;
char Low;
char High;
union {
unsigned short data;
struct
{
char LowByte;
char HighByte;
};
};
PSEL=1;
data=addranddata;
PSEL=0;
Low=LowByte;
// Send address bits
for (BitCounter=0;BitCounter<7;BitCounter++)
{
PCLK=0;
PDI=((Low&0x80)>>7);
Low=Low<<1;
PCLK=1;
}
// Send read/write bit
// Ignore bit in data, always use 1
PCLK=0;
PDI=1;
PCLK=1;
PCLK=0;
High=HighByte;
// Send data bits
for (BitCounter=0;BitCounter<8;BitCounter++)
{
PCLK=0;
PDI=((High&0x80)>>7);
High=High<<1;
PCLK=1;
}
PCLK=0;
PSEL=1;
}
/****************************************************************************/
/* This routine reads from a single CC1020 register */
/****************************************************************************/
char ReadFromCC1020Register(char addr)
{
char BitCounter;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -