这个代码下到板子上数码管亮度低怎么办
单片机源程序如下:
- #include <REGX52.H>
- #define smg P0
- typedef unsigned int U16;
- sbit S18=P2^0;
- sbit S19=P2^1;
- sbit S20=P2^2;
- void delay(U16 i)
- {
- while(i--);
- }
- int i;
- void an()
- {
- if(S18==0)
- {
- delay(5);
- if(S18==0)
- {
- i++;
- if(i==9999)
- {
- i=0;
- }
- }
- while(!S18);
- }
- if(S19==0)
- {
- delay(5);
- if(S19==0)
- {
- i--;
- if(i==0)
- {
- i=9999;
- }
- }
- while(!S19);
- }
- if(S20==0)
- {
- delay(5);
- if(S20==0)
- {
- i=0;
- }
- while(!S20);
- }
- }
- void main()
- {
-
- int q,b,s,g;
- int sz[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
- i=0;
- while(1)
- {
- an();
- q=i/1000;
- b=i%1000/100;
- s=i%100/10;
- g=i%10;
- delay(5);
- P0_0=1;
- P0_1=1;
- P0_2=1;
- P0_3=1;
-
-
- P0_0=0;
- P1=sz[q];
- P0_0=1;
- P1=0xff;
- delay(5);
-
- P0_1=0;
- P1=sz[b];
- P0_1=1;
- P1=0xff;
- delay(5);
-
- P0_2=0;
- P1=sz[s];
- P0_2=1;
- P1=0xff;
- delay(5);
-
- P0_3=0;
- P1=sz[g];
- P0_3=1;
- P1=0xff;
- delay(5);
- }
- }
复制代码
|