【12345678】 #include<reg52.h> #define uintunsigned int #define ucharunsigned char uchar codeDisplsy[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80}; uchar codeTemble[]={0,1,2,3,4,5,6,7}; void delay(uint z) { uchar t; while(z--) for(t=120;t>0;t--); } void main() { uchar i; P0=0xff; P1=0; while(1) { if(i==8) i=0; P1=Temble; P0=~Displsy[i+1]; i++; delay(2); } } 【脉冲计时】 #include<reg52.h> #define uintunsigned int #define ucharunsigned char uchar codeDisplay[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uchar codeTemble[]={0,1,2,3,4,5,6,7}; uchar Flag; uint Num; void delay(uint z) { uchar t; while(z--) for(t=120;t>0;t--); } voidTest2(void) { TR1 = 1; while(1) {
Num = TH1; Num = Num << 8; Num |= TL1; P1 = 7; P0 = ~Display[Num%10]; delay(3); P1 = 6; P0 = ~Display[Num%100/10]; delay(3); P1 = 5; P0 = ~Display[Num%1000/100]; delay(3); P1 = 4; P0 = ~Display[Num%10000/1000]; delay(3); P1 = 3; P0 = ~Display[Num%100000/10000]; delay(3); P1 = 2; P0 = ~Display[Num%1000000/100000]; delay(3); P1 = 1; P0 = ~Display[Num%10000000/1000000]; delay(3); P1 = 0; P0 = ~Display[Num%100000000/1000000]; delay(3); }
} void main() { TMOD = 0x50; TH1 = 0x00; TL1 = 0x00; EA = 1; ET1 = 1; TR1 = 0; while(1) { Test2(); } }
|