#include <reg51.h>//51系列单片机定义文件
#include <intrins.h>
#define uchar unsigned char //定义无符号字符
#define uint unsigned int //定义无符
#define uint unsigned int
#define uchar unsigned char
#define key P1 //矩阵键盘接口
#define wei P2 // 位选
#define seg P0 // 段选
uint count0=0;
uchar count1=0;
uchar second=0;
uchar gewei;
uchar shiwei;
uchar scan=0;
char disp[2]={0xc0,0xc0};
char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
void timer0() interrupt 1
{
gewei=second%10;
shiwei=second/10;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count0++;
if(count0==20)
{count0=0;
second++;
if(second==60)
{
second=0;
}
}
disp[0]=tab[gewei];
disp[1]=tab[shiwei];
}
void timer1() interrupt 3
{
count1++;
if(count1==32)
{count1=0;
}
scan++;
if(scan==2) scan=0;
switch(scan)
{
case(1):
{
seg=0xff;
wei=0xfe;
seg=disp[0];
}break;
case(0):
{
seg=0xff;
wei=0xfd;
seg=disp[1];
}break;
}
}
void main()
{
TMOD=0x21; //t1位方式2;t0为方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(256-250);
TL1=(256-250);
IE=0x8a;
TR0=1;
TR1=1;
while(1)
if(shiwei==0)
{
seg=0xff;
wei=0xfd;
seg=disp[0];
}
}
这是我写的数码管程序,实现0-59的秒计数,想在计数<10时,不要显示十位的0,但是按照上面的程序,十位也被隐约点亮。如何实现当<10时,十位切底不亮? |