|
硬件部分改一下,參考程序:#include<reg52.h> //庫(kù)文件
#define uchar unsigned char//宏定義無符號(hào)字符型
#define uint unsigned int //宏定義無符號(hào)整型
/********************************************************************
初始定義
*********************************************************************/
//顯示段碼 數(shù)碼管字跟位的控制端
code uchar seg7code[10]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
uchar wei[4]={0XEf,0XDf,0XBf,0X7f}; //
/********************************************************************
延時(shí)函數(shù)
*********************************************************************/
void delay(uchar t)
{
uchar i,j;
for(i=0;i<t;i++)
{
for(j=13;j>0;j--);
{ ;
}
}
}
/********************************************************************
顯示函數(shù)
*********************************************************************/
void Led(int date) //顯示函數(shù)
{
/*****************數(shù)據(jù)轉(zhuǎn)換*****************************/
uint z,x,c,v;
z=date/1000; //求千位
x=date%1000/100; //求百位
c=date%100/10; //求十位
v=date%10; //求個(gè)位
P2=0XFF;
P0=seg7code[z];
P2=wei[0];
delay(80);
P2=0XFF;
P0=seg7code[x];
P2=wei[1];
delay(80);
P2=0XFF;
P0=seg7code[c];
P2=wei[2];
delay(80);
P2=0XFF;
P0=seg7code[v];
P2=wei[3];
delay(80);
P2=0XFF;
}
/********************************************************************
主函數(shù)
*********************************************************************/
void main()
{
int display_date=1358; //定義并賦值要顯示的數(shù)據(jù)
while(1)
{
Led(display_date);//調(diào)用顯示函數(shù)顯示數(shù)據(jù)display_date
}
}
|
|