#define uchar unsigned char //宏定义
#define uint unsigned int
sbit dula=P2^6; //申明u1锁存器的锁存端
sbit wela=P2^7; // u2
uchar num1,num2;
uchar code table[]={ //数组定义
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code aable[]={ //位选数组定义
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delays(uint); //子函数申明
void main()
{
while(1)
{
for(num1=0;num1<48;num1++) //6个数循环显示
{
wela=1; //打开u2锁存端
P0=aable[num1%6]; //送入位选信号
wela=0; //关闭u2锁存端
// delays(1);
dula=1; //打开u1锁存端
P0=table[num1%16]; //送入段选信号
dula=0; //关闭u1锁存端
delays(1);
}
}
}
/*---------主函数-----------------------------------------------*/
void delays(uint xs)
{
uint i,j,k;
for(i=xs;i>0;i--)
for(j=1000;j>0;j--)
for(k=110;k>0;k--);
}
/*----------------延时程序-----------------------------------------------*/