#includereg52.h#includeLCD1602.huintNum=0;ucharNumCode[4]={0,0,0,0};//---------------中断加一--------------voidmy_INT1(void)interrupt0{Num++;}//-----------------------------voidDisp(){uintm;NumCode[0]=Num/1000;NumCode[1]=Num%1000/100;NumCode[2]=Num%100/10;NumCode[3]=Num%10;for(m=0;m4;m++){LCD_Disp(0,5+m,NumCode[m]+0x30);}}//---------------------voidmain(){IT0=1;EA=1;EX0=1;LCD_Init();while(1){Disp();}}#includereg52.h#includeLCD1602.huintNum=3728;ucharNumCode[4]={0,0,0,0};//-----------------------自动加一-------------------------voidDisp(){ucharm;NumCode[0]=Num/1000;NumCode[1]=Num%1000/100;NumCode[2]=Num%100/10;NumCode[3]=Num%10;for(m=0;m4;m++){LCD_Disp(0,6+m,NumCode[m]+0x30);}}//--------------------------------------------voidmain(){LCD_Init();while(1){Disp();Num++;Delay(50000);}}#includereg51.h#includeLCD1602.huintNum=5432;ucharNumCode[4]={0,0,0,0};//----------定时器T0按键加一---------------voidT0Init(){TMOD=0x0d;TH0=5432/256;TL0=5432%256;TR0=1;}//------------------------------------------voidDisp(){intm;NumCode[0]=Num/1000;NumCode[1]=Num%1000/100;NumCode[2]=Num%100/10;NumCode[3]=Num%10;for(m=0;m4;m++){LCD_Disp(0,5+m,NumCode[m]+0x30);}}//-------------------------------------------voidmain(){T0Init();LCD_Init();while(1){Num=TH0*256+TL0;Disp();}}#includereg51.h#defineucharunsignedcharucharT0Num;sbitLED=P1^0;//--------定时器TO使LED自动一秒闪一下---------voidT0Init(){TMOD=0x01;TH0=(65536-10000)/256;TL0=(65536-10000)%256;TR0=1;ET0=1;EA=1;}//---------------------------voidT0Sever()interrupt1{TH0=(65536-10000)/256;TL0=(65536-10000)%256;T0Num++;if(T0Num==100){LED=~LED;T0Num=0;}}//---------------------------voidmain(){T0Init();while(1){}}#includereg52.h#defineucharunsignedchar#defineuintunsignedintucharnum[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};uintshu;//-----------外部中断按键加减一----------voidmy_INT1(void)interrupt0{shu--;}//-----------------------------------------------------voidmy_INT2(void)interrupt2{shu++;}//------------------------------------------------------voidmain(){shu=5;IT0=1;EA=1;EX0=1;IT1=1;EA=1;EX1=1;while(1){P2=num[shu];if(shu==10){shu=0;}if(shu==-1){shu=9;}}}#includereg51.h#defineuintunsignedint#defineucharunsignedcharucharDisp[4]={0x9a,0xca,0xa9,0xac};//------------------------交通灯---------------------voiddelay3ms(uchari){uintn,j,k;for(;i=1;i--){for(n=2;n=1;n--){for(j=250;j=1;j--){for(k=200;k=1;k--);}}}}//-------------------------------------voidmain(){while(1){P1=Disp[0];delay3ms(4);P1=Disp[1];delay3ms(1);P1=Disp[2];delay3ms(4);P1=Disp[3];delay3ms(1);}}#includereg51.h#defineucharunsignedcharucharT0Num=0;ucharPWM=50;sbitLED=P3^7;//------------PWM频率------voidT0Init(){TMOD=0x01;TH0=(65536-100)/256;//0.1msTL0=(65536-100)%256;ET0=1;EA=1;TR0=1;}//-----------------------voidEx0Init(){IT0=1;EX0=1;EA=1;}//------------------------voidmain(){T0Init();Ex0Init();while(1){}}//------------------------voidT0Server()interrupt1{TH0=(65536-100)/256;//0.1msTL0=(65536-100)%256;T0Num++;if(T0Num==PWM){LED=1;}if(T0Num==100){T0Num=0;LED=0;}}//--------------------------voidInt0Server()interrupt0{PWM=PWM+5;if(PWM=100){PWM=0;}}includereg52.h#defineucharunsignedcharuchari,Flagls,Scon,T0Num;ucharcodeLedCode[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//-------串口74LS164驱动流水灯--------------voidT0_Init(){TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TR0=1;ET0=1;EA=1;}//----------------voidSerial_Init(){Scon=0x00;}//------------------voidSerialSend(ucharch){SBUF=ch;while(TI==0){}TI=0;}//--------------voidmain(){T0_Init();Serial_Init();while(1){if(Flagls==1){Flagls=0;SerialSend(LedCode[i]);i++;if(i7){i=0;}}}}//------------------voidToserver()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;T0Num++;if(T0Num20){T0Num=0;Flagls=1;}}#includereg51.h#defineucharunsignedchar#defineuintunsignedintucharDispCode[10]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0x3e,0xe0,0xfe,0xe6};uintNum=9995;ucharNumCode[4]={0,0,0,0};ucharT1Num;bitFlag1s=0;//---------串口74LS164驱动数码管----------------voidSerialInit(){SCON=0x00;}//-----------------------------------------voidT1Init(){TMOD=0x10;TH1=-10000/256;TL1=-10000%256;TR1=1;ET1=1;EA=1;}//------------------------------------------voidDisp(){uchari;NumCode[0]=Num/1000;NumCode[1]=Num%1000/100;NumCode[2]=Num%100/10;NumCode[3]=Num%10;for(i=0;i4;i++){SBUF=DispCode[NumCode[3-i]];while(TI==0){}TI=0;}}//------------------------------------------voidmain(){SerialInit();T1Init();while(1){if(Flag1s==1){Flag1s=0;Disp();}}}//-----------------------------------------voidT1Server()interrupt3{TH1=-10000/256;TL1=-10000%256;T1Num++;if(T1Num==100){T1Num=0;Flag1s=1;Num++;if(Num9999){Num=0;}}}#includereg51.h#defineucharunsignedchar#defineuintunsignedintucharT0Num;bitFlag1s=0;ucharDispCode[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//--------MUC_MUC串口自发自收-----------voidSerialInit(){SCON=0x50;//方式1允许接收PCON=0x00;//串口波特率不加倍TMOD|=0x20;//定时器1,方式2TH1=0xfd;//波特率为9600TL1=0xfd;TR1=1;//启动定时器ES=1;EA=1;}//--------------------------------voidT0Init(){TMOD|=0x01;TH0=-10000/256;TL0=-10000%256;ET0=1;TR0=1;EA=1;}//-