zoukankan      html  css  js  c++  java
  • 嵌入式成长轨迹54 【Zigbee项目】【CC2430基础实验】【系统睡眠工作状态】


    本实验在小灯闪烁10 次以后进入低功耗模式 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   
    ****************************************************************/


    重要的宏定义
    设置CC2430功耗模式,选定后立刻进入相应功耗模式。 

    1 #define SET_POWER_MODE(mode)                   \ 
    2    do {                                        \ 
    3       if(mode == 0)        { SLEEP &= ~0x03; } \ 
    4       else if (mode == 3)  { SLEEP |= 0x03;  } \ 
    5       else { SLEEP &= ~0x03; SLEEP |= mode;  } \ 
    6       PCON |= 0x01;                            \ 
    7       asm("NOP");                              \ 
    8    }while (0) 


     


    PCON (电源模式控制寄存器)
    7:2 -   未用
    1 -  未用,读出为0
    0 IDLE   电源模式控制,写1 将进入由SLEEP.MODE 指定的电源模式,读出一定为0

         NOP指令即“空指令”,在x86的CPU中机器码为0x90(144)。执行到NOP指令时,CPU什么也不做,仅仅当做一个指令执行过去并继续执行NOP后面的一条指令,所以NOP指令自然也会占用执行一个指令的CPU时间片。
       常用于程序延时或精确计时,不过在较快的CPU上不明显。
       主要作用:
       1、字节填充对齐
       2、精确延时和计时
       3、破解程序的call验证
       4、等待其他设备执行完毕
       5、清除由上一个算术逻辑指令设置的flag位
       6、辅助jmp、call等指令

    功耗测定方法
    将本次实验的程序写入CC2430 模块,将测量电流表串接入 CC2430 模块的供电电路,待小灯信步闪烁后测电流,然后根据P = U*I即可得到功率,提示:可以在程序中将小灯关闭,进一步降低功耗。

     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 *函数功能:延时                        
    34 *入口参数:无                            
    35 *返回值  :无                            
    36 *说  明    :可在宏定义中改变延时长度            
    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 *    函数功能:初始化I/O,控制LED                            
    50 *    入口参数:无                        
    51 *    返回值    :无                        
    52 *    说  明    :初始化完成后关灯                
    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 *    函数功能:主函数                    
    64 *    入口参数:                    
    65 *    返回值    :无                        
    66 *    说  明    :10次绿色LED闪烁后进入睡眠状态            
    67 ****************************************************************/
    68 void main()
    69 {
    70     uchar count = 0;
    71     Initial();
    72     RLED = 0;       //开红色LED,系统工作指示
    73     Delay();        //延时
    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次闪烁后进入睡眠状态
    84 
    85         //Delay();
    86         Delay();
    87                 //延时函数无形参,只能通过改变系统时钟频率
    88                 //来改变小灯的闪烁频率
    89     };
    90 }
  • 相关阅读:
    [erlang 002]gen_server中何时会跑到terminate函数
    设计模式:桥接模式
    设计模式:组合模式
    Harbor:镜像上传和下载
    Harbor:简介和安装
    Docker:compose
    ThinkPHP的静态化页面方法
    php使用memcached详解
    大话PHP设计模式
    PHP魔术方法使用
  • 原文地址:https://www.cnblogs.com/zeedmood/p/2666939.html
Copyright © 2011-2022 走看看