数码管按键移动位数闪烁实验
2015-06-23 来源:51hei
#include
#define uchar unsigned char
#define uint unsigned int
#define uint unsigned int
sbit k1=P1^0;
void delay(uint k)
{
while(k--);
{
while(k--);
}
code uchar seg[]={0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60}; //数码管码表
code uchar tab[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //数码管位选
uchar move,flag;
void time0_init()
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
}
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
}
void str_init() //中断初始化
{
EA=1;
ET0=1;
}
{
EA=1;
ET0=1;
}
void time0_event() interrupt 1 //中断事件
{
static uchar i;
i++;
if(i==15)
{
flag=~flag;i=0;
}
}
{
static uchar i;
i++;
if(i==15)
{
flag=~flag;i=0;
}
}
void show()
{
uchar i;
for(i=0;i<4;i++)
{
if(i==move)
{
P0=seg[i]|(0xdf&flag);
}
else
{
P0=seg[i];
}
P2=tab[i];
delay(100);
P0=0xff;
P2=0xff;
}
}
{
uchar i;
for(i=0;i<4;i++)
{
if(i==move)
{
P0=seg[i]|(0xdf&flag);
}
else
{
P0=seg[i];
}
P2=tab[i];
delay(100);
P0=0xff;
P2=0xff;
}
}
void key()
{
static uchar i,j;
if(k1==0)
{
if(i==0)
{
j++;
if(j>10)
{
if(k1==0)
{
i=1;j=0;
move++;
if(move==4)move=0;
}
}
}
}
else
{
i=0;
j=0;
}
}
{
static uchar i,j;
if(k1==0)
{
if(i==0)
{
j++;
if(j>10)
{
if(k1==0)
{
i=1;j=0;
move++;
if(move==4)move=0;
}
}
}
}
else
{
i=0;
j=0;
}
}
void main()
{
time0_init();
str_init();
while(1)
{
key();
show();
}
{
time0_init();
str_init();
while(1)
{
key();
show();
}
}
相关文章
最新器件