51单片机数码管用指针写显示函数,结果只有前三个显示的是对的,后五个显示的全是8。。

2025-03-03 19:14:23
推荐回答(3个)
回答1:

有意思!
for(i=0;i<7;i++)
{
P0=smg_du[*p];
p++;
P2=smg_we[i];
delay_50us(6);
P2=0x00; //加个这个再试试!
}

回答2:

你确定指针这么用 还有P自加完了 你要怎么办 到时候他超过数组 会怎么显示 你想过没有

回答3:

指针用法不对。
不如不用。

试试:

#include
unsigned char code smg_du[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char code smg_we[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code table[]={2,3,4,5,6,7,8,9};
void delay_50us(uint t)
{
uchar j;
for(;t > 0; t--) for(j = 19; j > 0; j--);
}
void main(void)
{
uchar i;
while(1) {
for(i = 0; i < 7; i++) {
P2 = 255;
P0 = smg_du[table[i]];
P2 = smg_we[i];
delay_50us(6);
}
}
}