基于430單片機(jī)的NRF905收發(fā)驅(qū)動(dòng)程序
作者:
時(shí)間:2016-11-27
來(lái)源:網(wǎng)絡(luò)
收藏
void RF905_Read(U8 RFcmd,U8 //RFdata)
{
U8 i,len;
switch(RFcmd)
{
case RTA: len=4; break;
case RRC: len=16; break;
case RTP:
case RRP: len=RFRxLen; break;
default: len=0;
}
CE905_0; /// Spi enable for write a spi command ///
SpiWriteByte(RFcmd);
for(i=0;i
CE905_1;
}
void RF905_Write(U8 RFcmd,U8 //RFdata)
{
U8 i,len;
switch(RFcmd)
{
case WTA: len = 4; break;
case WRC: len = 16; break;
case WTP: len = RFRxLen; break;
default: len = 0;
}
CE905_0; /// Spi enable for write a spi command ///
SpiWriteByte(RFcmd);
for(i=0;i/// len Bytes Data ///
CE905_1; // Disable Spi
}
U32 msec_cont = 0;//10毫秒鐘基數(shù)
U8 msec=0;//10毫秒鐘
U8 sec=0;//秒鐘
U8 min=0;//分鐘
U8 old_min;
U8 K1DwCnt, K2DwCnt;
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
msec ++;
msec_cont ++;
if(KEY1)
{
if((++K1DwCnt) > KeyDwTimes){K1DwCnt = KeyDwTimes;}
}
else
{
if(K1DwCnt >= 3)
K1DwCnt -= 3;
else
K1DwCnt = 0;
}
if(KEY2)
{
if((++K2DwCnt) > KeyDwTimes){K2DwCnt = KeyDwTimes;}
}
else
{
if(K2DwCnt >= 3)
K2DwCnt -= 3;
else
K2DwCnt = 0;
}
if((msec == 100) | (msec == 50))
{ //100分頻,就是1秒一次
if(msec == 100) msec = 0;
sec ++;
///
if(Blink)
{//需要閃爍
BlkPtr = 1;
for(LLi = 0; LLi 4; LLi ++)
{
if((sec & 0x01) && (Blink & BlkPtr))
LLTmp = 0xFF;
else
LLTmp = DisBuff[LLi];
BlkPtr <= 1;
for(LLj = 0; LLj 8; LLj ++)
{
if(LLTmp & 0x80)
{
LCD_DI_1;
}
else
{
LCD_DI_0;
}
LCD_CLK_1;
LCD_CLK_0;
LLTmp <= 1;
}
}
}
///
if(sec==60)
{
sec=0;//每分鐘一次
min++;
if(min==60) min=0;
}
}
}
U8 K1Sta = WaitKeyDw;
U8 K2Sta = WaitKeyDw;
void main(void)
{
//INT8U i, tmp;
// Init_CLK();
WDTCTL = WDTPW + WDTHOLD; // 關(guān)閉看門(mén)狗
_DINT();//關(guān)閉中斷
PORT_Init();
PD905;
SPI_Init();
INIT_905();
//P1OUT ^= 0x01; // 點(diǎn)亮LED
RF905_Read(RRC,RFRxBuf);
RFTxBuf[0] = a;
RFTxBuf[1] = b;
RFTxBuf[2] = c;
RFTxBuf[3] = d;
RFTxBuf[4] = e;
RFTxBuf[5] = f;
RFTxBuf[6] = g;
RFTxBuf[7] = h;
RFTxBuf[8] = i;