嵌入式成长轨迹54 【Zigbee项目】【CC2430基础实验】【系统睡眠工作状态】
?
本實(shí)驗(yàn)在小燈閃爍10 次以后進(jìn)入低功耗模式 PM3 。CC2430 一共有4 種功耗模式,分別是PM0,PM1,PM2,PM3,以 PM3 功耗最低。
SLEEP (0xBE) - Sleep mode control
0X03:0000 0011
bit7 -? Unused
bit6? XOSC_STB? XOSC stable status:
?0 – XOSC is not powered up or not yet stable
?1 – XOSC is powered up and stable
bit5? HFRC_STB? RCOSC stable status:
?0 – HF RCOSC is not powered up or not yet stable
?1 – HF RCOSC is powered up and stable
bit4:3? RST[1:0]?? Status bit indicating the cause of the last reset. If there are multiple resets, the register will only contain the last event.
?00 – Power-on reset
?01 – External reset?
?10 – Watchdog timer reset
bit2? OSC_PD? XOSC and HF RCOSC power down setting. The bit shall be cleared if the OSC bit is toggled. Also, if there is a calibration in progress and the CPU attempts to set the bit the module shall update the bit only at the end of calibration:
?0 – Both oscillators powered up
?1 – Oscillator not selected by OSC bit powered down
bit1:0? MODE[1:0]?? Sleep mode setting:
?00 – Power mode 0
?01 – Power mode 1
?10 – Power mode 2
?11 – Power mode 3
/**************************************************************?
* mode?? 0 ? 1? 2?3
*? ?PM0?PM1?PM2?PM3???
****************************************************************/
重要的宏定義
設(shè)置CC2430功耗模式,選定后立刻進(jìn)入相應(yīng)功耗模式。?
?
?
PCON (電源模式控制寄存器)
7:2 -?? 未用
1 -? 未用,讀出為0
0 IDLE?? 電源模式控制,寫1 將進(jìn)入由SLEEP.MODE 指定的電源模式,讀出一定為0
?
???? NOP指令即“空指令”,在x86的CPU中機(jī)器碼為0x90(144)。執(zhí)行到NOP指令時(shí),CPU什么也不做,僅僅當(dāng)做一個(gè)指令執(zhí)行過去并繼續(xù)執(zhí)行NOP后面的一條指令,所以NOP指令自然也會占用執(zhí)行一個(gè)指令的CPU時(shí)間片。
? 常用于程序延時(shí)或精確計(jì)時(shí),不過在較快的CPU上不明顯。
? 主要作用:
? 1、字節(jié)填充對齊
? 2、精確延時(shí)和計(jì)時(shí)
? 3、破解程序的call驗(yàn)證
? 4、等待其他設(shè)備執(zhí)行完畢
? 5、清除由上一個(gè)算術(shù)邏輯指令設(shè)置的flag位
? 6、輔助jmp、call等指令
?
功耗測定方法
將本次實(shí)驗(yàn)的程序?qū)懭隒C2430 模塊,將測量電流表串接入 CC2430 模塊的供電電路,待小燈信步閃爍后測電流,然后根據(jù)P = U*I即可得到功率,提示:可以在程序中將小燈關(guān)閉,進(jìn)一步降低功耗。
?
1 //main.c 2 #include <ioCC2430.h> 3 4 #define uint unsigned int 5 #define uchar unsigned char 6 #define DELAY 10000 7 8 //小燈控端口定義 9 #define RLED P1_0 10 #define YLED P1_1 11 12 /************************************************************** 13 * mode 0 1 2 3 14 * PM0 PM1 PM2 PM3 15 ****************************************************************/ 16 #define SET_POWER_MODE(mode) \ 17 do { \ 18 if(mode == 0) { SLEEP &= ~0x03; } \ 19 else if (mode == 3) { SLEEP |= 0x03; } \ 20 else { SLEEP &= ~0x03; SLEEP |= mode; } \ 21 PCON |= 0x01; \ 22 asm("NOP"); \ 23 }while (0) 24 25 #define CRYSTAL 0x00 26 #define RC 0x01 27 28 29 void Delay(void); 30 void Initial(void); 31 32 /**************************************************************** 33 *函數(shù)功能:延時(shí) 34 *入口參數(shù):無 35 *返回值 :無 36 *說 明 :可在宏定義中改變延時(shí)長度 37 ****************************************************************/ 38 void Delay(void) 39 { 40 uint tt; 41 for(tt = 0;tt<DELAY;tt++); 42 for(tt = 0;tt<DELAY;tt++); 43 for(tt = 0;tt<DELAY;tt++); 44 for(tt = 0;tt<DELAY;tt++); 45 for(tt = 0;tt<DELAY;tt++); 46 } 47 48 /**************************************************************** 49 * 函數(shù)功能:初始化I/O,控制LED 50 * 入口參數(shù):無 51 * 返回值 :無 52 * 說 明 :初始化完成后關(guān)燈 53 ****************************************************************/ 54 void Initial(void) 55 { 56 //P1 out 57 P1DIR = 0x03; //定義P1_0,P1_1為輸出 58 RLED = 1; 59 YLED = 1; //close led 60 } 61 62 /**************************************************************** 63 * 函數(shù)功能:主函數(shù) 64 * 入口參數(shù): 65 * 返回值 :無 66 * 說 明 :10次綠色LED閃爍后進(jìn)入睡眠狀態(tài) 67 ****************************************************************/ 68 void main() 69 { 70 uchar count = 0; 71 Initial(); 72 RLED = 0; //開紅色LED,系統(tǒng)工作指示 73 Delay(); //延時(shí) 74 Delay(); 75 Delay(); 76 Delay(); 77 78 while(1) 79 { 80 YLED = !YLED; 81 count++; 82 if(count == 20)SET_POWER_MODE(3); 83 //10次閃爍后進(jìn)入睡眠狀態(tài) 84 85 //Delay(); 86 Delay(); 87 //延時(shí)函數(shù)無形參,只能通過改變系統(tǒng)時(shí)鐘頻率 88 //來改變小燈的閃爍頻率 89 }; 90 }?
轉(zhuǎn)載于:https://www.cnblogs.com/zeedmood/archive/2012/09/01/2666939.html
總結(jié)
以上是生活随笔為你收集整理的嵌入式成长轨迹54 【Zigbee项目】【CC2430基础实验】【系统睡眠工作状态】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用beanUtils操纵bean的属性
- 下一篇: 手机浏览器