点亮一盏灯#includeREGX51.Hvoidmain(){P0=0;//初始化P0P1=0x80;while(1){P0_4=1;//点亮D0}}闪亮一盏灯#includeREGX51.Hvoidmain(){unsignedinti=0;P0=0;P1=0x0c;//00001100P1_2=0;//244使能while(1){P0_4=1;//闪亮D0;1-0-1-0……for(i=100000;i0;i--);P0_4=0;for(i=100000;i0;i--);}}循环闪亮#includeREGX51.Hvoidmain(){unsignedinti=0;P0=0;P1=0x0c;//00001100P1_2=0;//244使能while(1){P0_4=1;//闪亮D0;1-0-1-0……for(i=100000;i0;i--);P0_4=0;for(i=100000;i0;i--);P0_5=1;//闪亮D1;1-0-1-0……for(i=100000;i0;i--);P0_5=0;for(i=100000;i0;i--);P0_6=1;//闪亮D2;1-0-1-0……for(i=100000;i0;i--);P0_6=0;for(i=100000;i0;i--);P0_7=1;//闪亮D3;1-0-1-0……for(i=100000;i0;i--);P0_7=0;for(i=100000;i0;i--);}}循环闪亮#includeREGX51.Hvoiddelay();voidmain(){P0=0;P1=0x0c;//00001100P1_2=0;//244使能while(1){P0_4=1;//闪亮D0;1-0-1-0……delay();P0_4=0;delay();P0_5=1;//闪亮D1;1-0-1-0……delay();P0_5=0;delay();P0_6=1;//闪亮D2;1-0-1-0……delay();P0_6=0;delay();P0_7=1;//闪亮D3;1-0-1-0……delay();P0_7=0;delay();}}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}循环闪亮#includeREGX51.Hvoiddelay();voidmain(){P0=0;P1=0x0c;//00001100P1_2=0;//244使能while(1){P0=0x10;//闪亮D0;1-0-1-0……delay();P0=0;delay();P0=0x20;//闪亮D1;1-0-1-0……delay();P0=0;delay();P0=0x40;//闪亮D2;1-0-1-0……delay();P0=0;delay();P0=0x80;//闪亮D3;1-0-1-0……delay();P0=0;delay();}}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}循环点亮#includeREGX51.Hvoiddelay();voidmain(){unsignedcharTab[4]={0x10,0x20,0x40,0x80};P0=0;P1=0x0c;//00001100P1_2=0;//244使能while(1){P0=Tab[0];//闪亮D0;1-0-1-0……delay();P0=0;delay();P0=Tab[1];//闪亮D1;1-0-1-0……delay();P0=0;delay();P0=Tab[2];//闪亮D2;1-0-1-0……delay();P0=0;delay();P0=Tab[3];//闪亮D3;1-0-1-0……delay();P0=0;delay();}}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}循环点亮#includeREGX51.Hvoiddelay();voidmain(){unsignedinta=0;unsignedcharTab[4]={0x10,0x20,0x40,0x80};P0=0;P1=0x0c;//00001100P1_2=0;//244使能while(1){for(a=0;a4;a++){P0=Tab[a];//闪亮D0;1-0-1-0……delay();P0=0;delay();}}}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}#includeREGX51.H#includeintrins.hvoiddelay();voidmain(){unsignedinta=0;P0=0;P1=0x0c;P1_2=0;while(1){P0=0x10;for(a=0;a4;a++){delay();P0=_crol_(P0,1);}}}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}数码管点亮5#includeREGX51.Hvoiddelay();voidmain(){P0=0;P1=0x0c;P0=0x6d;P1_0=1;delay();P1_0=0;delay();P0=0xfe;P1_1=1;delay();P1_1=0;delay();}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}学号#includeREGX51.Hvoiddelay();voidmain(){P0=0;P1=0x0c;P0=0x3f;P1_0=1;P1_0=0;P0=0x7f;P1_1=1;P1_1=0;delay();P0=0x6f;P1_0=1;P1_0=0;P0=0xbf;P1_1=1;P1_1=0;delay();P0=0x5b;P1_0=1;P1_0=0;P0=0xdf;P1_1=1;P1_1=0;delay();P0=0x06;P1_0=1;P1_0=0;P0=0xef;P1_1=1;P1_1=0;delay();P0=0x3f;P1_0=1;P1_0=0;P0=0xf7;P1_1=1;P1_1=0;delay();P0=0x7d;P1_0=1;P1_0=0;P0=0xfb;P1_1=1;P1_1=0;delay();P0=0x07;P1_0=1;P1_0=0;P0=0xfd;P1_1=1;P1_1=0;delay();P0=0x5b;P1_0=1;P1_0=0;P0=0xfe;P1_1=1;P1_1=0;delay();}voiddelay(){unsignedinti=0;for(i=100000;i0;i--);}#includeREGX51.Hvoiddelay();voidmain(){unsignedinta=0;unsignedcharseg[]={0x3f,0x6f,0x5b,0x06,0x3f,0x7d,0x07,0x5b};unsignedchardig[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};for(a=0;a8;a++){P0=0;P1=0x0c;P0=seg[a];P1_0=1;P1_0=0;P0=dig[a];P1_1=1;P1_1=0;delay();}}voiddelay(){unsignedinti=0;for(i=1000000000;i0;i--);}开关K0控制灯#includeREGX51.H#defineuintunsignedint#defineucharunsignedcharsbitKey_ce=P1^3;sbitDig_ce=P1^1;sbitLed_ce=P1^2;voidmain(){bitStat=0;P0=0;P1=0x0c;Led_ce=0;while(1){P0_4=Stat;P0=0x0e;Dig_ce=1;Dig_ce=0;Key_ce=0;if(P0_0==0){Stat=~Stat;}Key_ce=1;}}开关K0控制灯#includeREGX51.H#defineuintunsignedint#defineucharunsignedcharsbitKey_ce=P1^3;sbitDig_ce=P1^1;sbitLed_ce=P1^2;voiddelayms(uint);voidmain(){bitStat=0;P0=0;P1=0x0c;Led_ce=0;while(1){P0_4=Stat;P0=0x0e;Dig_ce=1;Dig_ce=0;Key_ce=0;if(P0_0==0){delayms(10);if(P0_0==0){Stat=~Stat;}}Key_ce=1;}}voiddelayms(uinti){uintj;for(i;i0;i--)for(j=10;j0;j--);}#includeREGX51.H#defineuintunsignedint#defineucharunsignedcharsbitKey_ce=P1^3;sbitDig_ce=P1^1;sbitSeg_ce=P1^0;ucharcodeseg1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelayms(uint);voidKeyscan();voidmain(){P0=0;P1=0x0c;while(1){Keyscan();}}voiddelayms(uinti){uintj;for(i;i0;i--)for(j=10;j0;j--);}voidKeyscan(){unsignedcharTemp1,Temp2,Keynum;P0=0;Seg_ce=1;Seg_ce=0;P0=0xfe;Dig_ce=1;Dig_ce=0;Key_ce=0;Temp1=P0;Temp1=Temp1&0x0f;if(Temp1!=0x0f){delayms(10);Temp2=P0;Temp2=Temp2&0x0f;if(Temp1==Temp2){switch(Temp2){case0x0e:Keynum=0;break;case0x0d:Keynum=1;break;case0x0b:Keynum=2;break;case0x07:Keynum=3;break;default:break;}while(Temp2!=0x0f){Temp2=P0;Temp2=Temp2&0x0f;}}}Key_ce=1;P0=seg1[Keynum];Seg_ce=1;Seg_ce=0;P0=0xfe;Dig_ce=1;Dig_ce=0;delayms(1);P0=0;Seg_ce=1;Seg_ce=0;P0=0;P0=0xfd;Dig_ce=1;Dig_ce=0;Key_ce=0;Temp1=P0;Temp1=Temp1&0x0f;if(Temp1!=0x0f){delayms(10);Temp2=P0;Temp2=Temp2&0x0f;if(Temp1==Temp2){switch(Temp2){case0x0e:Keynum=4;break;case0x0d:Keynum=5;break;case0x0b:Keynum=6;break;case0x07:Keynum=7;break;default:break;}while(Temp2!=0x0f){Temp2=P0;Temp2=Temp2&0x0f;}}}Key_ce=1;P0=seg1[Keynum];Seg_ce=1;Seg_ce=0;P0=0xfd;Dig_ce=1;Dig_ce=0;delayms(1);P0=0;Seg_ce=1;Seg_ce=0;P0