本帖最后由 孟令民 于 2014-2-11 17:28 编辑
求助,大家帮我看看,怎么就显示一个0呢。附上代码。先谢谢啦。补充下dateport=weima[1]; dateport=duan[1];都写成这样就能正常显示,换成qian bai就都不好用了。
#include<c:\Keil\C51\INC\STC\STC12c5a60S2.H>
#define uchar unsigned char
#define uint unsigned int
#define dateport P0
sbit LATCH1=P2^2;
sbit LATCH2=P2^3;
uchar i=0,qian,bai,shi,ge;
unsigned char code duanma[8]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
unsigned char code weima[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay(unsigned int t)
{
while(--t);
}
unsigned char q=3450;
void display()
{
qian=q/1000;
bai=q%1000/100;
shi=q%100/10;
ge=q%10;
}
void main()
{
P0=0x00;
while(1)
{
dateport=weima[qian];
LATCH2=1;
LATCH2=0;
dateport=duanma[qian];
LATCH1=1;
LATCH1=0;
delay(200);
dateport=weima[bai];
LATCH2=1;
LATCH2=0;
dateport=duanma[bai];
LATCH1=1;
LATCH1=0;
delay(200);
dateport=weima[shi];
LATCH2=1;
LATCH2=0;
dateport=duanma[shi];
LATCH1=1;
LATCH1=0;
delay(200);
dateport=weima[ge];
LATCH2=1;
LATCH2=0;
dateport=duanma[ge];
LATCH1=1;
LATCH1=0;
delay(200);
/* dateport=weima;
LATCH2=1;
LATCH2=0;
dateport=duanma;
LATCH1=1;
LATCH1=0;
delay(200);
*/
i++;
if(8==i) i=0;
}
}
以下是正解。在坛友的帮助下修改的,不足之处请高手指教。
#include<c:\Keil\C51\INC\STC\STC12c5a60S2.H>
#define uchar unsigned char
#define uint unsigned int
#define dateport P0
sbit LATCH1=P2^2; //段选
sbit LATCH2=P2^3; //位选
unsigned long q=1234;
uchar qian,bai,shi,ge;
uchar code table[]={ //数组
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
/********delay 函数**********/
void delay(unsigned int t)
{
while(--t);
}
/*********display显示函数***/
void display()
{
qian=q/1000;
bai=q%1000/100;
shi=q%100/10;
ge=q%10;
LATCH1=1;
dateport=table[qian];
LATCH1=0;
dateport=0xff;
LATCH2=1;
dateport=0xfe;
LATCH2=0;
delay(200);
LATCH1=1;
dateport=table[bai];
LATCH1=0;
dateport=0xff;
LATCH2=1;
dateport=0xfd;
LATCH2=0;
delay(100);
LATCH1=1;
dateport=table[shi];
LATCH1=0;
dateport=0xff;
LATCH2=1;
dateport=0xfb;
LATCH2=0;
delay(100);
LATCH1=1;
dateport=table[ge];
LATCH1=0;
dateport=0xff;
LATCH2=1;
dateport=0xf7;
LATCH2=0;
delay(10);
}
/********main主函数*****/
void main()
{
P0=0x00; //初始化P0 i/o
while(1)
{
display(); //调用display函数
}
}
|