代码如下:
#include "reg52.h"
typedef unsigned int u16;
typedef unsigned int u8;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
void delay(u16 i){
while(i--);
}
void Led(){
u8 i;
for (i=0;i<8;i++){
delay(2000);
P0=0xff;
switch(i){
case(0):
LSA=1;LSB=1;LSC=1; break;
case(1):
LSA=0;LSB=1;LSC=1; break;
case(2):
LSA=1;LSB=0;LSC=1; break;
case(3):
LSA=0;LSB=0;LSC=1; break;
case(4):
LSA=1;LSB=1;LSC=0; break;
case(5):
LSA=0;LSB=1;LSC=0; break;
case(6):
LSA=1;LSB=0;LSC=0; break;
case(7):
LSA=0;LSB=0;LSC=0; break;
}
delay(3000);
P0=0x00;
}
}
void main(){
while(1){
Led();
}
}