LED流水灯【单向】
#includesbit LED1 = P1^1;sbit LED7 = P1^7;void delay(unsigned int s);// code: 定义在ROM,常量放在ROM// 否则定义在RAM,尽量节省RAM。/*unsigned char code table[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};*/main(){ unsigned char i=0; // 0~65535 unsigned char j; LED7 = 0; // 点亮P1.7 P1 = 0xFE; while(1) { /* * While语句占了2个赋值语句的时间 * 通过多执行2次,形成2个相等方波 */ //LED1 = 0; // P1.1点亮 //delay(1); //LED1 = 1; // P1.1熄灭 //delay(1); // 查表 /* for(i=0;i<8;i++) { P1 = table[i]; delay(1); } */ // 移位 j = P1; j = j << 1; if(j != 0xFE) j = j | 0x01; P1 = j; delay(1); } return 0;}void delay(unsigned int s){ unsigned int i, end; end = s*30000; for(i=0;i