|
为什么改了之后。按键切换300/600数码管会暗下来。。
单片机源程序如下:
#include <STC15F2K60S2.H>
#define uchar unsigned char
#define uint unsigned int
sbit led = P1^7;
sbit key1 = P5^4; //时间切换键
sbit key2 = P1^6; //启动按键
sbit we1 = P1^1; //数码管位端口
sbit we2 = P1^3;
sbit we3 = P1^2;
uchar knum;
bit k1f=0; //key1按键按下次数计数变量
uchar cont; //中断次数变量
uint cont1=30,cont2=300,cont3=600; //定义时间变量并赋值30秒,300秒,600秒
uchar code LedTab[]= {0xef,0x8c,0xb7,0xbe,0xdc,0x7e,0x7f,0xac,0xff,0xfe};
void delay()
{
unsigned char i;
i = 3;
while (--i);
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
void Delay30us() //@11.0592MHz
{
unsigned char i;
i = 80;
while (--i);
}
void display1(uint shu)
{
we1 = 0;we2 = 1; we3 = 1;
P3= LedTab[shu/100];
we1=1;
P3=0x00;
we1 = 1;we2 = 0; we3 = 1;
P3 = LedTab[shu%100/10];
we2 = 1;
P3 = 0x00;
we1 = 1;we2 = 1; we3 = 0;
P3 = LedTab[shu%10];
we3 = 1;
P3 = 0x00;
}
void keyscan()
{ if(key1==0)
{ Delay30us();
if(k1f==0)
{ k1f=1; knum++;
if(knum==4)
knum=0;
} }
else k1f=0;
if(key2 == 0)
{ Delay30us();
if(key2 == 0) //key2按下
TR0=~0; }
// led = 0; //点亮LED,松手后启动倒计时
//这句后面不加分号,下一句调用显示函数,按键时数码管才不会灭
if(knum==0)
{ display1(cont1);
if(knum==1)
display1(cont2);
if(knum==2)
display1(cont3);
if(knum==3)
P3=0x00; }
/* switch(knum)
{
case 0: display1(cont1); break;
case 1: display1(cont2); break;
case 2: display1(cont3); break;
} */
|
|