无线传感器网络TinyOS nesC语言 实验一

Makefile

COMPONENT=BlinkAppC
include $(MAKERULES)

BlinkC.nc

/**
 * Implementation for Blink application.  Toggle the red LED when a
 * Timer fires.
 **/

#include "Timer.h"

module BlinkC @safe() {
  uses interface Timer<TMilli> as Timer0;
  uses interface Leds;
  uses interface Boot;
} implementation {
  event void Boot.booted() {
    call Timer0.startPeriodic(1000);
  }

  event void Timer0.fired() {
    static uint8_t i = 1;

    dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
    
    call Leds.led0Toggle();
    if ((i & 0x01) == 0x00) {    //bracket is needed here !    
        call Leds.led1Toggle();
    }
    if ((i & 0x03) == 0x00) {
        call Leds.led2Toggle();
    }
    
    //call Leds.set(i);        //equivalent way to set the three LEDs
    i = ++i & 0x07;
  }
}



BlinkAppC.nc
/**
 * Blink is a basic application that toggles a mote's LED periodically.
 * It does so by starting a Timer that fires every second. It uses the
 * OSKI TimerMilli service to achieve this goal.
 **/

configuration BlinkAppC {

} implementation {
  components MainC, LedsC, BlinkC;
  components new TimerMilliC() as Timer0;

  BlinkC -> MainC.Boot;
  BlinkC.Timer0 -> Timer0;
  BlinkC.Leds -> LedsC;
}



你可能感兴趣的:(无线传感器网络TinyOS nesC语言 实验一)