main.c

来自「cc2430系统唤醒功能的源代码」· C语言 代码 · 共 91 行

C
91
字号
//cd wxl
#include <ioCC2430.h>

#define uint unsigned int
#define uchar unsigned char
#define DELAY 10000

//小灯控端口定义
#define RLED P1_0
#define YLED P1_1

/**************************************************************	
* mode   0 	 1	 2	3
*  	PM0	PM1	PM2	PM3			
****************************************************************/
#define SET_POWER_MODE(mode)                   \
   do {                                        \
      if(mode == 0)        { SLEEP &= ~0x03; } \
      else if (mode == 3)  { SLEEP |= 0x03;  } \
      else { SLEEP &= ~0x03; SLEEP |= mode;  } \
      PCON |= 0x01;                            \
      asm("NOP");                              \
   }while (0)

#define CRYSTAL 0x00
#define RC      0x01


void Delay(void);
void Initial(void);

/****************************************************************
*函数功能:延时						
*入口参数:无							
*返回值  :无							
*说  明	:可在宏定义中改变延时长度			
****************************************************************/
void Delay(void)
{
	uint tt;
	for(tt = 0;tt<DELAY;tt++);
	for(tt = 0;tt<DELAY;tt++);
	for(tt = 0;tt<DELAY;tt++);
	for(tt = 0;tt<DELAY;tt++);
	for(tt = 0;tt<DELAY;tt++);
}

/****************************************************************
*	函数功能:初始化I/O,控制LED							
*	入口参数:无						
*	返回值	:无						
*	说  明	:初始化完成后关灯				
****************************************************************/
void Initial(void)
{
	//P1 out
	P1DIR = 0x03;     //定义P1_0,P1_1为输出
	RLED = 1;
	YLED = 1;         //close led
}

/****************************************************************
*	函数功能:主函数					
*	入口参数:					
*	返回值	:无						
*	说  明	:10次绿色LED闪烁后进入睡眠状态			
****************************************************************/
void main()
{
	uchar count = 0;
	Initial();
	RLED = 0;       //开红色LED,系统工作指示
	Delay();        //延时
	Delay();
	Delay();
	Delay();

	while(1)
	{
		YLED = !YLED;
		count++;
		if(count == 20)SET_POWER_MODE(3);
		//10次闪烁后进入睡眠状态

		//Delay();
		Delay();
                //延时函数无形参,只能通过改变系统时钟频率
                //来改变小灯的闪烁频率
	};
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?