#include<regx51.h>
void kiemtrachan(unsigned char *x,unsigned char *u)
{
if ((P1_0 = 1) != 0)
{
*u=1;
}
else
{
if ((*u=1) != 0)
{
*x= *x+1;
*u=0;
}
}
}
void hienthi(unsigned char k)//hien thi so ra man hinh
{
switch(k)
{
case 0:
P2=0x40;
break;
case 1:
P2=0x79;
break;
case 2:
P2=0x24;
break;
case 3:
P2=0x30;
break;
case 4:
P2=0x19;
break;
case 5:
P2=0x12;
break;
case 6:
P2=0x02;
break;
case 7:
P2=0x78;
break;
case 8:
P2=0x00;
break;
case 9:
P2=0x10;
break;
}
}
main()//Chu+o+ng trình chính
{ unsigned char l,t,k1;
l=k1=t= 0;
while(1)//ta.o vòng la(.p vô ha.n
{
kiemtrachan(&l,&t);
if (l>0x09) l=0;
hienthi(l);
}
}
void kiemtrachan(unsigned char *x,unsigned char *u)
{
if ((P1_0 = 1) != 0)
{
*u=1;
}
else
{
if ((*u=1) != 0)
{
*x= *x+1;
*u=0;
}
}
}
void hienthi(unsigned char k)//hien thi so ra man hinh
{
switch(k)
{
case 0:
P2=0x40;
break;
case 1:
P2=0x79;
break;
case 2:
P2=0x24;
break;
case 3:
P2=0x30;
break;
case 4:
P2=0x19;
break;
case 5:
P2=0x12;
break;
case 6:
P2=0x02;
break;
case 7:
P2=0x78;
break;
case 8:
P2=0x00;
break;
case 9:
P2=0x10;
break;
}
}
main()//Chu+o+ng trình chính
{ unsigned char l,t,k1;
l=k1=t= 0;
while(1)//ta.o vòng la(.p vô ha.n
{
kiemtrachan(&l,&t);
if (l>0x09) l=0;
hienthi(l);
}
}
Comment