Demo entry 6655400

MyAppM

   

Submitted by anonymous on Oct 26, 2017 at 14:01
Language: nesC. Code size: 836 Bytes.

module MyAppM {
	uses interface Boot;
	uses interface Leds;
	uses interface Timer<TMilli> as Timer1;
	uses interface Alarm<T32khz, uint32_t> as SleepTimerAlarm;
}

implementation {
	
	uint8_t i=0;
	
	void setPowermode(int mode)	//设置模式
	{
		int j;
		if(mode<4){
			SLEEPCMD &= ~0X03;
			SLEEPCMD |= mode;
			PCON |= 1;
			for(j=0;j<4;j++);
		}
		else
			PCON=0;
	}
	
	task void Demo(){}

	task void SleepTask() {
		call SleepTimerAlarm.start(512 *6);
		setPowermode(2); //设置能源模式PM2  
	}

	//MainC自动触发
	event void Boot.booted() {

		call Leds.led2Off();
		call Timer1.startPeriodic(512); 

	}
	
	//timer结束触发
	event void Timer1.fired() {
		i++;
		if(i == 6) {
			i = 0;
			post SleepTask();
		}
		call Leds.led2Toggle();//切换LED状态   
	}
	
	async event void SleepTimerAlarm.fired() {

	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).