最近在开发利尔达CC430的套件,程序本来走的好好,自从我加入一个这样的程序void Time_conversion()
下面是源程序
******************************************************************************/
#include "../inc/RF_Toggle_LED_Demo.h"
#define PACKET_LEN (0x09) // PACKET_LEN <= 61
#define RSSI_IDX (PACKET_LEN+1) // Index of appended RSSI
#define CRC_LQI_IDX (PACKET_LEN+2) // Index of appended LQI, checksum
#define CRC_OK (BIT7) // CRC_OK bit
// 433MHz下的发射功率宏定义
#define PATABLE_VAL (0x50) // 0XC4-- 10 dBm;
// 0X50-- 0 dBm;
// 0X2D-- -6 dBm;
// 0X26-- -12dBm;
// 0x05-- -30dBm;
// 0xc0-- max
#define LED_RBIT 6
#define LED_GBIT 7
#define LED_DIR P2DIR
#define LED_OUT P2OUT
#define LED_SEL P2SEL
#define LEDR_ON() LED_OUT|=(1<<LED_RBIT)
#define LEDG_ON() LED_OUT|=(1<<LED_GBIT)
#define LEDR_OFF() LED_OUT&=~(1<<LED_RBIT)
#define LEDG_OFF() LED_OUT&=~(1<<LED_GBIT)
#define BUTTON_BIT 0
#define BUTTON_DIR PJDIR
#define BUTTON_OUT PJOUT
#define BUTTON_REN PJREN
#define BUTTON_IN PJIN
int RSSI_dec1;
extern RF_SETTINGS rfSettings;
unsigned char packetReceived;
unsigned char packetTransmit;
unsigned char RxBuffer[64];
unsigned char RxBufferLength = 0;
const unsigned char TxBuffer[6]= {PACKET_LEN, 0x27, 0x23, 0x24, 0x25, 0x26};
unsigned char buttonPressed = 0;
unsigned int i,j,number,x,g;
unsigned char flag;
unsigned char second,min,hour,day,day_of_week,month,year;
unsigned char aa[254];
int RSSI_offset=74;
unsigned int oldsavecount ;
unsigned int savecount ;
unsigned int newcount ;
unsigned int oldsavecarry;
unsigned int savecarry;
unsigned int newcarry;
unsigned int carry;
//__no_init
unsigned char transmitting = 0;
unsigned char receiving = 0;
unsigned int f,k;
unsigned int time;
unsigned int HOUR,MIN,SECOND;
//unsigned char buffer0[2047];
unsigned char sss[8]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
unsigned char time1,time2;
//初始化RTC
void RTC_Init(void)
{
RTCCTL01 |= RTCBCD + RTCHOLD + RTCMODE;
// RTC enable, BCD mode, RTC hold 使能RTC,开启BCD模式,RTC保持
// Disable RTC read ready interrupt 关闭RTC 中断
// Disable RTC time event interrupt
// 时间初始化
RTCSEC = 0x40; // 设置秒
RTCMIN = 0x36; // 设置分
RTCHOUR = 0x01; // 设置小时
// 日期初始化
RTCDOW = 0x00; // 设置星期数 5
RTCDAY = 0x20; // 设置日 04
RTCMON = 0x10; // 设置月 01
RTCYEAR = 0x2013; // 设置年 2013
RTCCTL01 &= ~RTCHOLD; // Start RTC calendar mode
}
/********************************************
* 函数名 :Read_Time
* 功能 :RTC 实时时钟,时间读取
* 输入参数 :无
* 输出参数 :无
* 作者 :
*/
void Read_Time()
{
for(;RTCCTL01&RTCRDY;) _NOP();
for(;!(RTCCTL01&RTCRDY);) _NOP();
year= RTCYEAR ; //读 年 寄存器
month= RTCMON ; //读 月 寄存器
day= RTCDAY ; //读 日 寄存器
day_of_week = RTCDOW ; //读 星期 寄存器
hour = RTCHOUR ; //读 时 寄存器
min= RTCMIN ; //读 分 寄存器
second= RTCSEC; //读 秒 寄存器
}
/********************************************
* 函数名 :Write_RTC
* 功能 :RTC 实时时钟,设置初始时间
* 输入参数 :无
* 输出参数 :无
* 作者 :
*/
void Write_RTC()
{
for(;RTCCTL01&RTCRDY;) _NOP();
for(;!(RTCCTL01&RTCRDY);) _NOP();
RTCCTL01 |= RTCHOLD ;
RTCYEAR = year ; //写 年 寄存器
RTCMON = month ; //写 月 寄存器
RTCDAY = day ; //写 日 寄存器
RTCDOW = day_of_week ; //写 星期 寄存器
RTCHOUR = hour ; //写 时 寄存器
RTCMIN = min ; //写 分 寄存器
RTCSEC = second ; //写 秒 寄存器
RTCCTL01 &= ~RTCHOLD;
}
/***********************************************************************/
void delayms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<800;j++);
}
}
//*****************************************************************************************
void InitRadio(void)
{
// Set the High-Power Mode Request Enable bit so LPM3 can be entered
// with active radio enabled
PMMCTL0_H = 0xA5;
PMMCTL0_L |= PMMHPMRE_L;
PMMCTL0_H = 0x00;
WriteRfSettings(&rfSettings);
WriteSinglePATable(PATABLE_VAL);
}
//*****************************************************************************************
void Transmit(unsigned char *buffer, unsigned char length)
{
RF1AIES |= BIT9;
RF1AIFG &= ~BIT9; // Clear pending interrupts
RF1AIE |= BIT9; // Enable TX end-of-packet interrupt
WriteBurstReg(RF_TXFIFOWR, buffer, length);
Strobe( RF_STX ); // Strobe STX
}
//*****************************************************************************************
void ReceiveOn(void)
{
RF1AIES |= BIT9; // Falling edge of RFIFG9
RF1AIFG &= ~BIT9; // Clear a pending interrupt
RF1AIE |= BIT9; // Enable the interrupt
// Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode
Strobe( RF_SRX );
}
//*****************************************************************************************
void ReceiveOff(void)
{
RF1AIE &= ~BIT9; // Disable RX interrupts
RF1AIFG &= ~BIT9; // Clear pending IFG
// It is possible that ReceiveOff is called while radio is receiving a packet.
// Therefore, it is necessary to flush the RX FIFO after issuing IDLE strobe
// such that the RXFIFO is empty prior to receiving a packet.
Strobe( RF_SIDLE );
Strobe( RF_SFRX );
}
void FlashWrite(unsigned char *pc_byte,unsigned char *Datain,unsigned int count)
{
//FCTL2 = FWKEY + FSSEL_1 + FN3 + FN4;//MCLK 16*FN4 + 8*FN3
FCTL3 = FWKEY;
FCTL1 = FWKEY + WRT;
while(FCTL3 & BUSY); //如果处于忙状态,则等待
while(count--)
{
while(FCTL3 & BUSY);
*pc_byte++ = *Datain++;
}
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
while(FCTL3 & BUSY);
}
//*****************************************************************************************
void FlashRead(unsigned char *pc_byte,unsigned char *Dataout,unsigned int count)
{
while(count--)
{
*Dataout = *pc_byte;
Dataout++;
pc_byte++;
}
}
void Time_conversion()
{
Read_Time();
HOUR=(((hour&0xf0)>>4)*10+(hour&0x0f)); //16进制bcd码转换为10进制。
if(HOUR>12)
{
HOUR=(HOUR-12); //24小时制转换为12小时制。
}
HOUR=((HOUR&0xf0)>>4)*10+(HOUR&0x0f);
MIN=((min&0xf0)>>4)*10+(min&0x0f);
SECOND=((second&0xf0)>>4)*10+(second&0x0f);
time=( HOUR<<12)|( MIN<<6)|(SECOND);
time1=(time>>8)&0x00ff;
time2=time&0x00ff;
}
//*****************************************************************************************
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
SetVCore(2);
ResetRadioCore();
InitRadio();
ReceiveOn();
receiving = 1;
RTC_Init();
_EINT();
while (1)
{
ReceiveOn();
receiving = 1;
Time_conversion();
}
}
//*****************************************************************************************
#pragma vector=CC1101_VECTOR
__interrupt void CC1101_ISR(void)
{
switch(__even_in_range(RF1AIV,32)) // Prioritizing Radio Core Interrupt
{
case 0: break; // No RF core interrupt pending
case 2: break; // RFIFG0
case 4: break; // RFIFG1
case 6: break; // RFIFG2
case 8: break; // RFIFG3
case 10: break; // RFIFG4
case 12: break; // RFIFG5
case 14: break; // RFIFG6
case 16: break; // RFIFG7
case 18: break; // RFIFG8
case 20: // RFIFG9
RxBufferLength = ReadSingleReg( RXBYTES );
ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength);
// Stop here to see contents of RxBuffer
__no_operation();
RSSI_dec1=CalculateRssi(RxBuffer[RSSI_IDX]);
// f=(int)RxBuffer[5];
// Check the CRC results
if(RxBuffer[CRC_LQI_IDX] & CRC_OK)
{
unsigned char *pc_byte;
pc_byte= ( unsigned char *) 0x008910;
LED_OUT |= (1<<LED_GBIT); // Toggle LED1
delayms(5);
if(RxBuffer[0]==0x09&RxBuffer[1]==0x27)
{
flag=1;
newcount ++;
FlashWrite((pc_byte+k),RxBuffer,8);
k+=8;
}
LED_OUT &=~(1<<LED_GBIT);
}
break;
case 22: break; // RFIFG10
case 24: break; // RFIFG11
case 26: break; // RFIFG12
case 28: break; // RFIFG13
case 30: break; // RFIFG14
case 32: break; // RFIFG15
}
__bic_SR_register_on_exit(LPM3_bits);
}
/***************************************************
void Time_conversion()这个函数是用来将采集到的RTC实时时钟的hour,min,second 3个BCD码组成的字节数据压缩成两个字节,现在我放在主函数里面使用,时间长了就会跑飞。进入一个这样的地方
显示的Stack也是100%的状态,这是为什么呢?我将Options里面的Stack的数值加大到200,甚至是500都一样会溢出,这是什么情况呢?各位大神,求指教啊
|
|