1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include<reg52.h> #define uchar unsigned char #define uint unsigned int uchar num = 0; sbit DI1=P1^0; sbit DI2=P1^1; sbit DI3=P1^2; sbit DI4=P1^3; uchar i4 = 0; uchar i3 = 0; uchar i2 = 0; uchar i1 = 0; uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uchar code table2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; void delay(uint z) { uint x,y; for(x = z;x>0;x--) for(y = 110;y>0;y--); } void display() { P0=0x00; DI1=0; P0=table[i1]; delay(5); DI1=1; DI2=0; P0=table2[i2]; delay(5); DI2=1; DI3=0; P0=table[i3]; delay(5); DI3=1; DI4=0; P0=table[i4]; delay(5); DI4=1; } void main() { TMOD = 0x01; TH0 = (65536-45872)/256; TL0 = (65536-45872)%256; EA = 1; ET0 = 1; TR0 = 1; while(1) { if(num == 20) { num = 0; if(i4 == 9) { i4 = 0; if(i3 == 5) { i3 = 0; if(i2 == 9) { i2 = 0; i1++; } else { i2++; } } else { i3++; } } else { i4++; } } display(); } } void T0time() interrupt 1 { TH0 = (65536-45872)/256; TL0 = (65536-45872)%256; num++; }
|