求大神解释一下为什么我这个数码管程序,当百位小于3在数码管上显示正常,大于3就显示错误
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void delay(uint ms) ;
uchar x;
void main()
{
uchar bwei,swei,gwei,m;
x=345;
while(1)
{
bwei=x/100;swei=x/10%10;gwei=x%10;
for( m=0;m<20;m++)
P2=0X01; P0=tab[bwei]; delay(10); P0=0xff;
P2=0X02; P0=tab[swei]; delay(10); P0=0xff;
P2=0X04; P0=tab[gwei]; delay(10); P0=0xff; }
}
void delay(uint ms)
{uchar i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<120;j++)
{;}
}
}
|