直接上程序
include <reg52.h> //包含寄存器的库文件
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char code LedChar[] = { //用数组来表示数码管真值表
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8e,
};
void main()
{
unsigned int counter = 0;
unsigned char j = 0;
unsigned long stopwatch =0;
unsigned char LedNumber[6]={0};
ENLED = 0; ADDR3 = 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;
counter++;
if(1000 == counter) //判断定时器0溢出是否达到1000次
{
counter = 0;
stopwatch++; //秒表数值一秒加1
LedNumber[0] = stopwatch%10;
LedNumber[1] = stopwatch/10%10;
LedNumber[2] = stopwatch/100%10;
LedNumber[3] = stopwatch/1000%10; //数码管显示值计算
LedNumber[4] = stopwatch/10000%10;
LedNumber[5] = stopwatch/100000%10;
}
switch(j)
{
case 0: ADDR0=0; ADDR1=0; ADDR2=0; j++; P0=LedChar[LedNumber[0]];break;
case 1: ADDR0=1; ADDR1=0; ADDR2=0; j++; P0=LedChar[LedNumber[1]];break;
case 2: ADDR0=0; ADDR1=1; ADDR2=0; j++; P0=LedChar[LedNumber[2]];break;
case 3: ADDR0=1; ADDR1=1; ADDR2=0; j++; P0=LedChar[LedNumber[3]];break;
case 4: ADDR0=0; ADDR1=0; ADDR2=1; j++; P0=LedChar[LedNumber[4]];break;
case 5: ADDR0=1; ADDR1=0; ADDR2=1; j=0; P0=LedChar[LedNumber[5]];break;
default: break;
}
} //数码管动态刷新部分
}
我的问题就是,在最后的那个switch语句里面,执行完case0不就是直接跳出switch了吗,那不就是永远只能显示一个数码管了吗?
实在是理解不过来,求指点。。。。
|