|   一派掌門 二十級 | 
              代码:【MyAppC.nc】
 configuration MyAppC
 {
 }
 implementation
 {
 components MyC, MainC;
 MyC.Boot -> MainC.Boot;
 }
 
 【MyC.nc】
 module MyC
 {
 uses interface Boot;
 }
 implementation
 {
 #define _BV(n) (1 << (n))
 #define SDAT_0 P2OUT &= ~_BV(0)
 #define SDAT_1 P2OUT |= _BV(0)
 #define STCLK_0 P2OUT &= ~_BV(1)
 #define STCLK_1 P2OUT |= _BV(1)
 #define SHCLK_0 P2OUT &= ~_BV(3)
 #define SHCLK_1 P2OUT |= _BV(3)
 
 // 数字0~9
 const unsigned char table[][8] = {
 {0x00, 0x00, 0x3E, 0x41, 0x41, 0x3E, 0x00, 0x00},
 {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00},
 {0x00, 0x00, 0x62, 0x51, 0x49, 0x46, 0x00, 0x00},
 {0x00, 0x00, 0x22, 0x49, 0x49, 0x36, 0x00, 0x00},
 {0x00, 0x00, 0x38, 0x26, 0x7F, 0x20, 0x00, 0x00},
 {0x00, 0x00, 0x4F, 0x49, 0x49, 0x31, 0x00, 0x00},
 {0x00, 0x00, 0x3E, 0x49, 0x49, 0x32, 0x00, 0x00},
 {0x00, 0x00, 0x03, 0x71, 0x09, 0x07, 0x00, 0x00},
 {0x00, 0x00, 0x36, 0x49, 0x49, 0x36, 0x00, 0x00},
 {0x00, 0x00, 0x26, 0x49, 0x49, 0x3E, 0x00, 0x00}
 };
 
 void SerIn(unsigned char dat)
 {
 unsigned char i;
 for (i = 0; i < 8; i++)
 {
 SHCLK_0;
 if (dat & 0x80)
 SDAT_1;
 else
 SDAT_0;
 dat <<= 1;
 SHCLK_1;
 }
 }
 
 void ParOut(void)
 {
 STCLK_0;
 STCLK_1;
 }
 
 void delay(void)
 {
 unsigned int i;
 for (i = 0; i < 600; i++);
 }
 
 // 显示数字
 void ShowNumber(unsigned char n)
 {
 unsigned char i;
 for (i = 0; i < 8; i++)
 {
 SerIn(~_BV(i));
 SerIn(table[n][i]);
 ParOut();
 delay();
 }
 }
 
 event void Boot.booted(void)
 {
 unsigned char i = 0;
 unsigned char cnt = 0;
 
 P2DIR = 0xff;
 P2OUT = 0x00;
 
 while (1)
 {
 ShowNumber(i);
 
 cnt++;
 if (cnt > 100)
 {
 cnt = 0;
 i++;
 if (i > 9)
 i = 0;
 }
 }
 }
 }
 【Makefile】
 COMPONENT = MyAppC
 include $(MAKERULES)
 【run.sh】
 make telosb install bsl,/dev/ttyUSB0
 
 运行./run.sh就可以编译和烧写程序了
 
 |