- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- unsigned char leddata[]={
- 0xC0, //"0"
- 0xF9, //"1"
- 0xA4, //"2"
- 0xB0, //"3"
- 0x99, //"4"
- 0x92, //"5"
- 0x82, //"6"
- 0xF8, //"7"
- 0x80, //"8"
- 0x90, //"9"
- 0x88, //"A"
- 0x83, //"B"
- 0xC6, //"C"
- 0xA1, //"D"
- 0x86, //"E"
- 0x8E, //"F"
- 0x89, //"H"
- 0xC7, //"L"
- 0xC8, //"n"
- 0xC1, //"u"
- 0x8C, //"P"
- 0xA3, //"o"
- 0xBF, //"-"
- 0xFF, //熄灭
- 0xFF //自定义
- };
- void delay(uint z)
- {
- uchar x,y;
- for(x = z;x > 0;x--)
- for(y = 114;y > 0;y--);
- }
- void main()
- {
- int a,k,t,b = 1,c = 2,d = 3,e = 4,f = 5,g = 6,h = 7;
- TMOD = 0X01;
- TR0 = 1;
- TH0 = 0X4B;
- TL0 = 0XFD;
- while(1)
- {
- if(TF0 == 1)
- {
- TH0 = 0X4B;
- TL0 = 0XFD;
- TF0 = 0;
- k++;
- }
- if(k == 20)
- {
- k = 0;
- a++;
- b++;
- c++;
- d++;
- e++;
- f++;
- g++;
- h++;
- }
- if(a == 21)
- a = 0;
- if(b == 21)
- b = 0;
- if(c == 21)
- c = 0;
- if(d == 21)
- d = 0;
- if(e == 21)
- e = 0;
- if(f == 21)
- f = 0;
- if(g == 21)
- g = 0;
- if(h == 21)
- h = 0;
- if(t == a)
- {
- P1 = 0X01;
- P0 = leddata[a];
- delay(5);
-
- P1 = 0X02;
- P0 = leddata[b];
- delay(5);
-
-
- P1 = 0X04;
- P0 = leddata[c];
- delay(5);
-
- P1 = 0X08;
- P0 = leddata[d];
- delay(5);
-
-
- P1 = 0X10;
- P0 = leddata[e];
- delay(5);
-
-
- P1 = 0X20;
- P0 = leddata[f];
- delay(5);
-
-
- P1 = 0X40;
- P0 = leddata[g];
- delay(5);
-
- P1 = 0X80;
- P0 = leddata[h];
- delay(5);
- t = a;
- }
- else
- {
- P1 = 0X01;
- P0 = leddata[a];
- delay(5);
-
- P1 = 0X02;
- P0 = leddata[b];
- delay(5);
-
-
- P1 = 0X04;
- P0 = leddata[c];
- delay(5);
-
- P1 = 0X08;
- P0 = leddata[d];
- delay(5);
-
-
- P1 = 0X10;
- P0 = leddata[e];
- delay(5);
-
-
- P1 = 0X20;
- P0 = leddata[f];
- delay(5);
-
-
- P1 = 0X40;
- P0 = leddata[g];
- delay(5);
-
- P1 = 0X80;
- P0 = leddata[h];
- delay(5);
- }
- }
- }
复制代码 |