写一个数,然后把他显示出来,不知为啥显示的不对,请指点下,鼓捣好几天了,也没有头绪,谢谢
#include <AT89X52.h>
#include <math.h>
#define uchar unsigned char
#define unint unsigned int
sbit DUAN=P2^0; //74HC573的LE端 LED的段选端
sbit WEI=P2^1; //74HC573的LE端 LED的位选端
unint a[5];
unint j;
unint temp;
uchar xian[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,};//共阴显示字库 0123456789
void delay(unint z) //1ms延时
{
unint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void wei_1(uchar wei) //锁存器573的数码管位控制
{
WEI=1;
P0=wei;
WEI=0;
}
void duan_1(uchar duan) //锁存器573的数码管段控制
{
unint i;
DUAN=1;
P0=xian[duan];
DUAN=0;
for(i=200;i>0;i--);
}
void shuzhi()
{a[0]=temp/100000;
temp=temp%100000;
a[1]=temp/10000;
temp=temp%10000;
a[2]=temp/1000;
temp=temp%1000;
a[3]=temp/100;
temp=temp%100;
a[4]=temp/10;
temp=temp%10;
a[5]=temp;
}
void display2() //显示
{
shuzhi();
wei_1(0x7f); /*秒*/
duan_1(a[0]);
wei_1(0xbf);
duan_1(a[1]);
wei_1(0xdf); /*-*/
duan_1(10);
wei_1(0xef); /*分*/
duan_1(a[2]);
wei_1(0xf7);
duan_1(a[3]);
wei_1(0xfb); /*-*/
duan_1(10);
wei_1(0xfd); /*时*/
duan_1(a[4]);
wei_1(0xfe);
duan_1(a[5]);
}
void main()
{ temp=323456;
display2();
}
|