|
直接上程序
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[] = { //用數(shù)組來表示數(shù)碼管真值表
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; //設(shè)置定時器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溢出是否達(dá)到1000次
{
counter = 0;
stopwatch++; //秒表數(shù)值一秒加1
LedNumber[0] = stopwatch%10;
LedNumber[1] = stopwatch/10%10;
LedNumber[2] = stopwatch/100%10;
LedNumber[3] = stopwatch/1000%10; //數(shù)碼管顯示值計算
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;
}
} //數(shù)碼管動態(tài)刷新部分
}
我的問題就是,在最后的那個switch語句里面,執(zhí)行完case0不就是直接跳出switch了嗎,那不就是永遠(yuǎn)只能顯示一個數(shù)碼管了嗎?
實在是理解不過來,求指點。。。。
|
|