/**********************************************************
This programis purose to check CC2530' PM2 supply current.
I could see the supply current 1 micro Ampare when sleep.
Result: PM2=1uA, Active=according to loads condition
***********************************************************/
/* ST_test3.c */
#include <ioCC2530.h>
static void SleepTimerSetting(void);
void Delay(unsigned int value);
////////////////
int main (void)
////////////////
{
P0DIR = 0Xff; // P0 output mode
P0 = 0x00; // P0 set to 0
P1DIR = 0xff; // P1 output mode
P1 = 0x00; // P1 set to 0
P2INP = 0x60;
CLKCONCMD = 0;
SLEEPCMD = 0x02; // Setting power mode 2
while (1)
{
P1_0 = 1; // led_0 on
Delay(40000); // some delay to lit LED
Delay(40000);
Delay(40000);
Delay(40000);
P1_0=0; // led_0 off
SleepTimerSetting();
}
}
///////////////////////////////////
static void SleepTimerSetting(void)
///////////////////////////////////
{
unsigned long sleeptime = 0;
EA = 0;
IEN0 = 0;
STIF = 0; //clear interrupt flag
// read sleep timer
sleeptime |= ((unsigned long)ST0);
sleeptime |= ((unsigned long)ST1 << 8);
sleeptime |= ((unsigned long)ST2 << 16);
sleeptime += (32768 * 5);
if(sleeptime > 0xFFFFFF)sleeptime = sleeptime - 0xFFFFFF;
// set sleep timer
// to check the Sleep Timer is ready to start loading a new compare value.
while((STLOAD & 0x01) == 0);
ST2 = (unsigned long)(sleeptime >> 16);
ST1 = (unsigned long)(sleeptime >> 8);
ST0 = (unsigned long) sleeptime;
STIF = 0; // sleep timer flag clear
STIE = 1; // sleep timner interrupt enable
EA = 1; // Enable global interrupt
PCON = 0X01; //go to sleep
}
/////////////////////////////////
#pragma vector=ST_VECTOR
__interrupt void sleeptimer_int()
/////////////////////////////////
{
EA = 0; // global interrupt disable
IEN0 = 0; // sleep timer interrupt disable
STIF = 0; //clear interrupt flag
}
//////////////////////////////
void Delay(unsigned int value)
//////////////////////////////
{
unsigned int k;
for(k=0; k < value; k++);
}
댓글 없음:
댓글 쓰기