Code:
//LED nhap nhap; //Creat 14h35 29/02/2012; #include <REGX51.H> //Tao ham thoi gian tre de duy tri thoi gian sang, tat cho led; void delay(unsigned int ms) //ms co 1000 nen khia bao kieu int { unsigned int i,j; for(i=0;i<ms;i++) for(j=0;j<121;j++) { }//Khong lam gi ca } void choptat() { unsigned char i; while(1) { for(i=0;i<3;i++) //chay 3 lan { P1=0x00;//he hexa =00000000 nen led tat; delay(1000); P1=0xFF;// he hexa=11111111 nen tat ca led sang; delay(1000); } } } void sangdan() { unsigned char i; while(1) { for(i=0;i<3;i++) //chay 3 lan { P1=0x01;delay(1000);// led1 sang; P1=0x03;delay(1000);// led 1 2 sang; P1=0x07;delay(1000);// led 1 2 3 sang; P1=0x0F;delay(1000);// led 1..4 sang; P1=0x1F;delay(1000);// led 1.....5 sang; P1=0x3F;delay(1000);// led 1....6 sang; P1=0x7F;delay(1000);// led 1....7 sang; P1=0xFF;delay(1000);// led 1....8 sang; } } } main() { while(1) { sangdan(); choptat(); } }
Comment