两个不一样的数组。为什么可以重叠使用啊!
以下是程序:
#include <reg52.h> //包含寄存器的库文件
#define u16 unsigned int
#define u8 unsigned char
sbit a = P1^0;
sbit b= P1^1;
sbit c = P1^2;
sbit d= P1^3;
sbit e = P1^4;
u8 pt[] = { //用数组来表示数码管真值表
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8e,
};
void main()
{
u16 z= 0;
u8 j = 0;
unsigned long s =0;
u8 look[6]={0};
e= 0; d= 1;P0 = 0XFF; //74HC138和P0初始化部分
TMOD = 0x01; //设置定时器0为模式1
TH0 = 0xFC;
TL0 = 0x67; //定时值初值,定时1ms
TR0 = 1; //打开定时器0
while(1)
{
if(1 == TF0) //判断定时器0是否溢出
{
TF0 = 0;
TH0 = 0xFC; //一旦溢出后,重新赋值
TL0 = 0x67;
z++;
if(1000 == z) //判断定时器0溢出是否达到1000次
{
z= 0;
s++; //秒表数值一秒加1
look[0] = s%10; 余数为1
look[1] = s/10%10; 余数1
look[2] = s/100%10; 余数1
look[3] = s/1000%10; //数码管显示值计算
look[4] = s/10000%10;
look[5] = s/100000%10;
}
switch(j)
{
case 0: a=0; b=0; c=0; j++; P0=pt[look[0]];break;
case 1: a=1; b=0; c=0; j++; P0=pt[look[1]];break;
case 2: a=0; b=1; c=0; j++; P0=pt[look[2]];break;
case 3: a=1; b=1; c=0; j++; P0=pt[look[3]];break;
case 4: a=0; b=0; c=1; j++; P0=pt[look[4]];break;
case 5: a=1; b=0; c=1; j=0; P0=pt[look[5]];break;
default: break;
}
} //数码管动态刷新部分
}
}
|