Code:
//Chuong trinh dieu khien led nhap nhay #include <REGX51.H> sbit led0 =P1^0; sbit led1 =P1^1; sbit led2 =P1^2; sbit led3 =P1^3; sbit led4 =P1^4; sbit led5 =P1^5; sbit led6 =P1^6; sbit led7 =P1^7; //Hàm tao tre void delay(unsigned int ms)//tao tre voi don vi la ms { unsigned char i,j;//khai báo kieu char moi bien la 1 byte for(i=0;i<ms;i++) for(j=0;j<120;j++) {} }//không làm gì ca main() { while(1) { P1=0x01;delay(1000);//led0 sang 1s P1=0x03;delay(1000);//led0,1 sang .... P1=0x05;delay(1000);//led0,1,2 sang .... P1=0x0F;delay(1000);//led0,1,2,3 sang ... P1=0x1F;delay(1000);//led0,1,2,3,4 sang ... P1=0x2F;delay(1000);//led0,1,2,3,4,5 sang .... P1=0x7F;delay(1000);//led0,1,2,3,4,5,6 sang ..... P1=0xFF;delay(1000);//led0,1,2,3,4,5,6,7 sang ........ } }
Comment