|  | 目前总结的TinyOS常用操作 | 
                
          |   一派掌門 二十級 | 
              使用I/O口组件:components HplMsp430GeneralIOC;
 MyC.LED1 -> HplMsp430GeneralIOC.Port54;  // 用LED1表示P5.4
 uses interface HplMsp430GeneralIO as LED1;
 
 将I/O口设置为输入/输出:
 call LED1.makeInput();
 call LED1.makeOutput();
 输入: call LED1.get();
 输出0/1:
 call LED1.clr();
 call LED1.set();
 call LED1.toggle(); // 反转高低电平
 
 
 
 | 
                
          |   一派掌門 二十級 | 
              读I/O口所在端口(如P5)的8个I/O口的状态:call LED1.getRaw();
 (相当于51单片机中的P0、P1之类的寄存器,以及AVR单片机中的PORTA、PORTB等寄存器)
 判断I/O口目前是输入还是输出:
 call LED1.isInput();
 call LED1.isOutput();
 读取或判断I/O口是否使用其复用功能:
 call LED1.selectModuleFunc();
 call LED1.selectIOFunc();
 call LED1.isModuleFunc();
 call LED1.isIOFunc();
 
 
 | 
|
        
                
          |   一派掌門 二十級 | 
              MSP430单片机中有两个基本定时器:TimerA和TimerB使用定时器组件:components Msp430TimerC;
 使用定时器A:
 MyC.TimerA -> Msp430TimerC.TimerA;
 uses interface Msp430Timer as TimerA;
 必须实现定时器中断函数:
 async event void TimerA.overflow(void) {}
 启用/禁用定时器中断:
 call TimerA.enableEvents();
 call TimerA.disableEvents();
 
 
 | 
|
        
                
          |   一派掌門 二十級 | 
              BusyWaitMicroC延时组件使用组件:
 components BusyWaitMicroC;
 MyC.BusyWait -> BusyWaitMicroC.BusyWait;
 uses interface BusyWait<TMicro, uint16_t>; // 其中的两个参数不能改变
 
 延时100微秒:
 call BusyWait.wait(100);
 
 
 | 
|
        
                
          |   一派掌門 二十級 | 
              标准1秒延时函数// 延时1秒
 void delay_1s(void)
 {
 uint8_t i;
 for (i = 0; i < 20; i++) {
 call BusyWait.wait(50000u); // 延时50000微秒(=50毫秒)
 }
 }
 
 
 | 
|