74LS164是串入並出轉換晶片,可以藉助串列埠來實現,也可以用普通IO口模擬實現。舉例如下:
#include
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
sbit keyup=P3^6;
sbit keydn=P3^7;
void delay()
{
int i=1000;
while(i--);
}
main()
uchar i;
i=0;
SCON=0x00;
TI=1;
while(1)
SBUF=table[i];
while(TI==0);
TI=0;
delay();
if(keyup==0)
i++;
while(keyup==0);
if(keydn==0)
if(i>0)i--;
while(keydn==0);
i%=10;
74LS164是串入並出轉換晶片,可以藉助串列埠來實現,也可以用普通IO口模擬實現。舉例如下:
#include
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
sbit keyup=P3^6;
sbit keydn=P3^7;
void delay()
{
int i=1000;
while(i--);
}
main()
{
uchar i;
i=0;
SCON=0x00;
TI=1;
while(1)
{
SBUF=table[i];
while(TI==0);
TI=0;
delay();
if(keyup==0)
{
i++;
while(keyup==0);
}
if(keydn==0)
{
if(i>0)i--;
while(keydn==0);
}
i%=10;
}
}