📄 cc1100.i
字号:
#line 1 "cc1100.c"
#line 6 "cc1100.c"
#line 1 "C:/icc/include/iom128v.h"
#line 7 "C:/icc/include/iom128v.h"
#line 11 "C:/icc/include/iom128v.h"
#line 14 "C:/icc/include/iom128v.h"
#line 17 "C:/icc/include/iom128v.h"
#line 20 "C:/icc/include/iom128v.h"
#line 7 "cc1100.c"
#line 1 "D:\wsn\冷轧\api/cc1100_reg.h"
#line 8 "cc1100.c"
typedef unsigned char uint8_t ;
typedef unsigned int uint16_t;
unsigned char paTable[8] = {0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0};
unsigned char rxBuffer[32];
unsigned char rd_reg;
unsigned char SEND_DONE=0x00;
#line 35 "cc1100.c"
void SET_CLOCK() {(*(volatile unsigned char *)0x65) |=0x1; }
void CLEAR_CLOCK() {(*(volatile unsigned char *)0x65) &=~(0x1); }
void SET_IN() {(*(volatile unsigned char *)0x65) |=0x2; }
void CLEAR_IN() {(*(volatile unsigned char *)0x65) &=~(0x2); }
void SET_CSN() {(*(volatile unsigned char *)0x35) |=0x4; }
void CLEAR_CSN() {(*(volatile unsigned char *)0x35) &=~(0x4); }
char GET_OUT() { return (((*(volatile unsigned char *)0x35) & 1<<1)!=0);}
char GET_GDO0() { return (((*(volatile unsigned char *)0x32) & 1<<1)!=0);}
extern uint8_t CC1100_sendDone();
extern uint8_t CC1100_receive(uint8_t *msg);
void Dly10us()
{
unsigned char i;
for(i=0;i<10;i++)
{
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
}
void Dly1mS(unsigned int l)
{
unsigned int i,j;
while(l--)
for(i=0;i<54;i++)
for(j=0;j<100;j++);
}
unsigned char SPI_write(unsigned char value)
{
unsigned char i,spi_status,rd_pin;
for(i=0;i<8;i++)
{
if((value&0x80)==0x80)
{
Dly10us();
SET_IN();
}
else
{
CLEAR_IN();
Dly10us();Dly10us();
}
Dly10us();Dly10us();Dly10us();
SET_CLOCK();
Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
value <<=1;
spi_status<<=1;
rd_pin=GET_OUT();
if((rd_pin&0x01)==0x01)
spi_status=spi_status|0x01;
else
spi_status=spi_status&0xfe;
CLEAR_CLOCK();
Dly10us();Dly10us();
}
return(spi_status);
}
unsigned char SPI_read()
{
unsigned char i,value,rd_pin;
for(i=0;i<8;i++)
{
SET_CLOCK();
value <<=1;Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
rd_pin=GET_OUT();
if((rd_pin&0x01)==0x01) value|=0x01;
else value&=0xfe;
Dly10us();Dly10us();
CLEAR_CLOCK();
Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
}
return value;
}
unsigned char spiGetRxTxStatus()
{
unsigned char RxTxstatus;
CLEAR_CSN();
while(GET_OUT());
CLEAR_CLOCK();
RxTxstatus=SPI_write(0x3D);
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
return(RxTxstatus);
}
void halSpiWriteReg(unsigned char addr, unsigned char value)
{
CLEAR_CSN();
while(GET_OUT());
CLEAR_CLOCK();
addr&=0x7F;
SPI_write(addr);
SPI_write(value);
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
}
void halSpiStrobe(unsigned char strobe)
{
CLEAR_CSN();
CLEAR_CLOCK();
while(GET_OUT());
SPI_write(strobe);
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
}
void halSpiWriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
{
unsigned char i,j,value;
CLEAR_CLOCK();
Dly10us();Dly10us();
CLEAR_CSN();
addr|= 0x40;
SPI_write(addr);
CLEAR_IN();
for(j=0;j<count;j++)
{
value=buffer[j];
SPI_write(value);
CLEAR_IN();
for(i=0;i<100;i++);
}
SET_CSN();
}
void CC1100_POR()
{
unsigned int i;
halSpiStrobe(0x36);
SET_CSN();
for(i=0;i<100;i++);
CLEAR_CSN();
for(i=0;i<100;i++);
SET_CSN();
for(i=0;i<2000;i++);
CLEAR_CSN();
while(GET_OUT());
halSpiStrobe(0x30);
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
}
unsigned char halRfSendPacket(unsigned char *txBuffer, unsigned char size)
{
halSpiStrobe(0x3B);
Dly1mS(15);
halSpiWriteBurstReg(0x7F, txBuffer, size);
Dly1mS(15);
halSpiStrobe(0x35);
while(spiGetRxTxStatus()&0x70)
{
Dly1mS(1);
}
SEND_DONE=0x01;
return 0;
}
#line 242 "cc1100.c"
unsigned char halSpiReadReg(unsigned char addr)
{
unsigned char value;
CLEAR_CLOCK();
Dly10us();Dly10us();
CLEAR_CSN();
addr|= 0x80;
SPI_write(addr);
CLEAR_IN();
Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
value=0;
value=SPI_read();
Dly10us();Dly10us();Dly10us();
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
return value;
}
void halSpiReadBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
{
unsigned char i,value;
CLEAR_CLOCK();
Dly10us();Dly10us();
CLEAR_CSN();
addr|= 0xC0;
SPI_write(addr);
CLEAR_IN();
Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
value=0;
for(i=0;i<count;i++)
{
value=SPI_read();
buffer[i]=value;
}
Dly10us();Dly10us();Dly10us();
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
}
unsigned char halSpiReadStatus(unsigned char addr)
{
unsigned char value,rd_pin;
CLEAR_CSN();
while(GET_OUT());
CLEAR_CLOCK();
addr|= 0xC0;
SPI_write(addr);
value=SPI_read();
CLEAR_CLOCK();
CLEAR_IN();
SET_CSN();
return value;
}
void halRfWriteRfSettings()
{
l_setCC1100:
halSpiWriteReg(0x0B, 0x0C);
halSpiWriteReg(0x0C, 0x00);
halSpiWriteReg(0x0D, 0x10);
halSpiWriteReg(0x0E, 0x09);
halSpiWriteReg(0x0F, 0x7B);
halSpiWriteReg(0x10, 0xC6);
halSpiWriteReg(0x11, 0x83);
halSpiWriteReg(0x12, 0x02);
halSpiWriteReg(0x13, 0x22);
halSpiWriteReg(0x14, 0xF8);
halSpiWriteReg(0x0A, 0x05);
halSpiWriteReg(0x15, 0x30);
halSpiWriteReg(0x21, 0x56);
halSpiWriteReg(0x22, 0x10);
halSpiWriteReg(0x18, 0x18);
halSpiWriteReg(0x19, 0x15);
halSpiWriteReg(0x1A, 0x6C);
halSpiWriteReg(0x1B, 0x03);
halSpiWriteReg(0x1D, 0x91);
halSpiWriteReg(0x23, 0xA9);
halSpiWriteReg(0x24, 0x2A);
halSpiWriteReg(0x26, 0x0D);
halSpiWriteReg(0x29, 0x59);
halSpiWriteReg(0x2C, 0x86);
halSpiWriteReg(0x2D, 0x3D);
halSpiWriteReg(0x2E, 0x09);
halSpiWriteReg(0x00, 0x24);
halSpiWriteReg(0x02, 0x06);
halSpiWriteReg(0x07, 0x04);
halSpiWriteReg(0x08, 0x05);
halSpiWriteReg(0x09, 0x00);
halSpiWriteReg(0x06, 0x1F);
halSpiWriteReg(0x16, 0x08);
#line 382 "cc1100.c"
if(halSpiReadReg(0x13)!=0x22)
goto l_setCC1100;
}
TOSH_SIGNAL(SIG_INTERRUPT1)
{
unsigned char packetLength;
packetLength = halSpiReadReg(0xFF);
rxBuffer[0]=packetLength;
if(rxBuffer[0] <= 32)
{
halSpiReadBurstReg(0xFF, &rxBuffer[1], packetLength);
CC1100_receive(&rxBuffer[0]);
}
else
{
halSpiStrobe(0x3A);
}
halSpiStrobe(0x3A);
halSpiStrobe(0x34);
}
uint8_t CC1100_init()
{
uint16_t nnn;
SET_CSN();
CLEAR_CLOCK();
CLEAR_IN();
CC1100_setInterrupt(0x00);
CC1100_POR();
for(nnn=0;nnn<500;nnn++);
halRfWriteRfSettings();
halSpiWriteBurstReg(0x3E, paTable, sizeof(paTable));
CC1100_setInterrupt(0x00);
CC1100_setStrobe(0x36);
return 1;
}
uint8_t CC1100_setStrobe(uint8_t state)
{
halSpiStrobe(state);
Dly1mS(5);
return 1;
}
uint8_t CC1100_setRegister(uint8_t address,uint8_t value)
{
halSpiWriteReg(address,value);
return 1;
}
uint8_t CC1100_readRegister(uint8_t address)
{
rd_reg = halSpiReadReg(address);
return rd_reg;
}
uint8_t CC1100_readStatus(uint8_t address)
{
return halSpiReadStatus(address);
}
uint8_t CC1100_readBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
{
halSpiReadBurstReg(addr, buffer, count);
return 1;
}
uint8_t CC1100_setInterrupt(uint8_t flag)
{
if(flag==0x00)
{
(*(volatile unsigned char *)0x58)=0x02;(*(volatile unsigned char *)0x6A)=0x08;(*(volatile unsigned char *)0x5A)=0x00;(*(volatile unsigned char *)0x59)=0x00;
}
else if(flag==0x01)
{
(*(volatile unsigned char *)0x58)=0x02;(*(volatile unsigned char *)0x6A)=0x08;(*(volatile unsigned char *)0x5A)=0x00;(*(volatile unsigned char *)0x59)=0x02;
halSpiStrobe(0x34);
}
else if(flag==0x02)
{
halSpiStrobe(0x34);
}
return 1;
}
uint8_t CC1100_sendRFburst(uint8_t *txPtr,uint8_t size)
{
CC1100_setInterrupt(0x00);
halSpiStrobe(0x36);
halRfSendPacket(txPtr, size);
if(SEND_DONE==0x01)
{
SEND_DONE=0x00;
CC1100_sendDone(1);
CC1100_setInterrupt(0x01);
}
return 1;
}
#line 501 "cc1100.c"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -