51单片机的板子,段端是p0,位端是p2,一开始用的这个代码但是没反应
#include<REGX52.H>
#define uint unsigned int
#define uchar unsigned char
uchar a[]={0x05,0x7d,0x46,0x54,0x3c,0x94,0x84,0x5d,0x04,0x14};//0-9段端口P0
uchar b[]={0xf7,0xef,0xdf,0xbf};//1-4位端口P2
uchar c[]={0x01,0x79,0x42,0x50,0x38,0x90,0x80,0x59,0x00,0x10};//小数点
uint i,w,a1,a2,a3,a4,a5;
void delayms(uint xms);
void display();//显示
void math(uint w);
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void math(uint w)
{
if(w>1)
{
a1=w/1000;//千位
a2=w%1000/100;//百位
a3=w%100/10;//十位
a4=w%10;//个位
}
else
{
a5= (uint)w%10;
}
}
void display()
{
if(a1>0)
{
P2=b[0];
P0=a[a1];
delayms(50);
P0=0xff;
P2=b[1];
P0=a[a2];
delayms(50);
P0=0xff;
P2=b[2];
P0=a[a3];
delayms(50);
P0=0xff;
P2=b[3];
P0=a[a4];
delayms(50);
P0=0xff;
}
else
{
if(a2>0)
{
P2=b[1];
P0=a[a2];
delayms(50);
P0=0xff;
P2=b[2];
P0=a[a3];
delayms(50);
P0=0xff;
}
else
{
if(a3>0)
{
P2=b[2];
P0=a[a3];
delayms(50);
P0=0xff;
}
else
{
if(a5>0)
{
P2=b[0];
P0=c[0];
delayms(50);
P0=0xff;
P2=b[1];
P0=a[a5];
delayms(50);
P0=0xff;
}
else
{
P2=b[3];
P0=a[a4];
delayms(50);
P0=0xff;
}
}
}
}
}