本帖最后由 1070309620 于 2011-4-2 10:50 编辑
我这几天焊接了一个数码管显示电路,仿真是没有问题,一通电数码管就一直闪(即使P0直接输出0)或者根本不亮,不知道是怎么回事哪位高手给我指点一下?
#include <reg51.h>
sbit key1=P1^0;
sbit key2=P1^1; //0 1 2 3 4 5 6 7 8 9
int code num[ ] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int j,k;
void delay_1ms(int k) //延时
{
while(k--)
for(j=0;j<125;j++);
}
void main(void)
{
int i=0,m,n=0,P0=0xff;
while(1)
{
if(!key1)
loop1: {delay_1ms(100);i=i+1;
while(1)
{
if(i==100)i=99;
P3=i;
m=i/10;n=i%10;
P0=0xfd;
P2=~num[m]+128;
delay_1ms(10);
P0=0xfe;
P2=~num[n];
delay_1ms(10);
if(!key1){delay_1ms(100);goto loop1;}
if(!key2){delay_1ms(100);goto loop2;}
}
}
if(!key2)
loop2: {delay_1ms(100);i=i-1;
while(1)
{
if(i==-1)i=0;
P3=i;
m=i/10;n=i%10;
P0=0xfd;
P2=~num[m]+128;
delay_1ms(10);
P0=0xfe;
P2=~num[n];
delay_1ms(10);
if(!key1){delay_1ms(100);goto loop1;}
if(!key2){delay_1ms(100);goto loop2;}
}
}
}
} |