两个问题:1.没有消隐 2.延时过长
- #include<reg51.h>
- sbit D0=P1^0;
- sbit D1=P1^1;
- unsigned char code led_ge[]={0x3f,0x06,0x5b,0x4f,0x66,
- 0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned int i=0;
- void delay(unsigned int time)
- {
- unsigned int j;
- for(;time>0;time--)
- for(j=0;j<125;j++);
- }
- void main()
- {
- IT0=1;
- EX0=1;
- EA=1;
- while(1)
- {
- P2=0x00; //消隐
- D0=0;D1=1;//送位码
- P2=led_ge[i/10];//送段码
- delay(5);//延时5ms
- P2=0x00; //消隐
- D0=1;D1=0;//送位码
- P2=led_ge[i%10];//送段码
- delay(5);//延时5ms
- }
- }
- void getKey() interrupt 0
- {
- i++;
- if(i>=100)
- i=0;
- }
复制代码 |