four_zhg 发表于 2013-7-31 09:30
上传文件吧,不然有可能分析不出来了
好,我把主文件贴上来吧,其它的太多了!
#include <REG51Si1000.H>
//#include <string.h>
//#include <rtx51tny.h> /* RTX-51 tiny functions & defines */
#include ".\si4432\si4432.h"
#define SYSCLK 24500000UL
#define BAUDRATE 9600
unsigned char commdata[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
xdata unsigned char commdata2[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,
60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,
120,121,122,123,124,125,126,127};
// xdata char commdata3[]={0,1,2,3,4,5,6,7,8,9,10
// };
xdata unsigned char commdata1[64];
static xdata unsigned char i = 1;
unsigned char flag = 0;
/*******************************
º¯Êý˵Ã÷£ºÏµÍ³³õʼ»¯
ÊäÈë²ÎÊý£ºÎÞ
Êä³ö²ÎÊý£ºÎÞ
********************************/
void SysInit( void )
{
//Use Internal Precision Oscillator as SYSCLK
FLSCL = 0x40;
OSCICN = 0x8F;
CLKSEL = 0x00;
//SPI1 Configuration
XBR1 = 0x40;
XBR2 = 0x40;
SPI1CFG = 0x40; //Master Mode Enable
SPI1CN = 0x01; //Enable SPI1
SPI1CKR = 0x3C; //SPI CLOCK RATE = 200KHZ
//Port Configuration
P0SKIP = 0x02; //nIRQ Pin is skipped by the crossbar
P1SKIP = 0x10; //P1.4 Pin is skipped by the Crossbar
P2SKIP = 0x04; //P2.2 Pin is skipped by the Crossbar
//Exinternal Interrupt Configuration
IT01CF = 0x01; //P0.1 as External Interrupt Source
//Timer Configuration
CKCON = 0x04;
PCA0MD &= ~0x40; //WDT Disable
P0MDOUT = 0x10; //P0.4/TX Output is push-pull
XBR0 = 0x01; //UART Output Enable
XBR2 = 0x40; //Crossbar Enable
TMOD = 0x20; //Timer Work in 8-bit Counter/Timer with Auto-Reload
TH1 = -(SYSCLK/BAUDRATE/2/12); // Auto-Reload Value
TL1 = TH1;
TR1 = 1;
SCON0 = 0x10; //Enable UART Receive
//ES0 = 1; //Enable UART Interrupt
EX0 = 1; //Enable External Interrupt
IT0 = 1;
EA = 1;
}
/********************************
º¯Êý˵Ã÷£ºTimer0³õʼ»¯
ÊäÈë²ÎÊý£º¶¨Ê±Ê±¼ä
Êä³ö²ÎÊý£ºÎÞ
********************************/
void Timer0( unsigned int timeval )
{
CKCON = 0x04; //Sysclk/12 as ClockSource
TMOD = 0x01;
TH0 = (65536-timeval*24500/12)/255;
TL0 = (65536-timeval*24500/12)%256;
TR0 = 1;
}
/********************************
º¯Êý˵Ã÷£ºUART ÖжϺ¯Êý
ÊäÈë²ÎÊý£ºÎÞ
Êä³ö²ÎÊý£ºÎÞ
*********************************/
/*void Uart0( void ) interrupt 4
{
if( RI0 == 1 )
{
//temp = SBUF0;
RI0 = 0; //Clear Receive Interrupt Flag
//SBUF0 = temp;
}
if ( TI0 ==1 )
{
TI0 = 0; //Clear Send Interrupt Flag
SBUF0 = commdata1[i++];
if( i >= 24 )
i = 1;
}
}*/
/*******************************
º¯Êý˵Ã÷£ºÊ¹ÄÜRFÖжÏ
ÊäÈë²ÎÊý£ºÎÞ
Êä³ö²ÎÊý£ºÎÞ
********************************/
void rf_ISR_Enable(void)
{
si4432_ISR_Enable();
}
/*******************************
º¯Êý˵Ã÷£ºÍⲿÖжϺ¯Êý
ÊäÈë²ÎÊý£ºÎÞ
Êä³ö²ÎÊý£ºÎÞ
********************************/
void Ext0Inter( void ) interrupt 0
{
volatile unsigned char i;
unsigned char ItStatus3=0,ItStatus4=0,ItStatus5=0;
IE0 = 0;
sreg.ItStatus1 = RF_ReadReg(EZRADIOPRO_INTERRUPT_STATUS_1);
sreg.ItStatus2 = RF_ReadReg(EZRADIOPRO_INTERRUPT_STATUS_2);
ItStatus3 = RF_ReadReg(EZRADIOPRO_DEVICE_STATUS);
ItStatus4 = RF_ReadReg(EZRADIOPRO_OPERATING_AND_FUNCTION_CONTROL_1);
ItStatus5 = RF_ReadReg(EZRADIOPRO_OPERATING_AND_FUNCTION_CONTROL_2);
if ((sreg.ItStatus2 & EZRADIOPRO_ISWDET) == EZRADIOPRO_ISWDET) //Sync Word Detected
{
i = 0;
//return;
}
if ((sreg.ItStatus2 & EZRADIOPRO_IPREAVAL) == EZRADIOPRO_IPREAVAL) //Valid Preamble detected
{
i = 0;
//return;
}
if ((sreg.ItStatus2 & EZRADIOPRO_IPREAINVAL) == EZRADIOPRO_IPREAINVAL) //Invalid Preamble detected
{
i = 0;
//return;
}
if ((sreg.ItStatus1 & EZRADIOPRO_ICRCERROR) == EZRADIOPRO_ICRCERROR) //CRC Error, then drop this package
{
//rf_ReceiveReady();
i = 0;
//si4432_ReadData(commdata);
//SBUF0 = commdata[i++];
return;
}
if ((sreg.ItStatus1 & EZRADIOPRO_IPKVALID) == EZRADIOPRO_IPKVALID) //Valid Packet received
{
flag = 1;
}
/*if ((sreg.ItStatus1 & EZRADIOPRO_IRXFFAFULL) == EZRADIOPRO_IRXFFAFULL) //RX FIFO almost full
{
si4432_ReadData(commdata1);
SBUF0 = commdata1[0];
}*/
}
/*******************************
º¯Êý˵Ã÷£ºRF³õʼ»¯
ÊäÈë²ÎÊý£ºÎÞ
Êä³ö²ÎÊý£ºÎÞ
********************************/
unsigned char rf_Init(void)
{
return si4432_Init();
}
/*******************************
º¯Êý˵Ã÷£º·¢ËÍ»º³åÇøÄÚÈݵ½RFÇø
ÊäÈë²ÎÊý£º»º³åÇøÖ¸Õ룬»º³åÇø³¤¶È
Êä³ö²ÎÊý£ºÎÞ
*******************************/
void rf_sendData(unsigned char *buf, unsigned char len)
{
len = (len <= FIFO_MAXLEN)? len : FIFO_MAXLEN;
si4432_WriteData(buf,len);
}
void main( void )
{
unsigned char temp;
int i,j;
SysInit();
rf_Init();
//while(!rf_Init());
rf_ISR_Enable();
si4432_ReceiveReady();
while(1)
{
//rf_sendData(commdata,20);
if (flag)
{
si4432_ReadData(commdata1);
for(temp=0;temp<24;temp++)
{
SBUF0 = commdata1[temp];
while( !TI0 );
TI0 = 0;
}
flag = 0;
si4432_ReceiveReady();
}
}
} |