You are on page 1of 3

Chng trnh sau, qut 6 LED 7 on v hin th t 0 n 999999.

#include <16f877a.h>
#include <def_877A.h>
#fuses hs
#use delay(clock=8000000)
int j,l,temp,b[6],m,i;
int32 k[7],a,t;
Void hienthi(int l);
void kichhoat(int m);
void main()
{
trisD = 0x00;
trisA=0x00;
Porta=0Xff;
Portd=0xff;
t=0;
while(true)
{
a=t;
if (t!=0)
{
for(j=0;j<=5;j++)
{
k[j]=a%10;
a=a/10;
}
//hienthi(k[0]);
for(j=5;j>=0;j--)
{
if (k[j]!= 0)
{
temp=j;
break;
}
}
i=1;
while(i)
{
i--;
for(j=0;j<=temp;j++)
{
hienthi(k[temp-j]);
kichhoat(j);
delay_ms(5);
}
}
//Ket thuc if

}
if (t==0)
{
i=1;
while(i)
{
i--;
Porta=0Xfe;
hienthi(0);
delay_ms(5);
}
}
t++;
if (t==10000000)
t=1;
//Ket thuc vong lap vo tan
}
}
void hienthi(int l)
{
switch(l)
{
case 0:
{
PortD=0xC0;
break;
}
case 1:
{

PortD=0xF9;

break;
}
case 2:
{
PortD=0xA4;
break;
}
case 3:
{
PortD=0xB0;
break;
}
case 4:
{
PortD=0x99;

break;
}
case 5:
{
PortD=0x92;
break;
}
case 6:
{
PortD=0x82;
break;
}
case 7:
{
PortD=0xF8;
break;
}
case 8:
{
PortD=0x80;
break;
}
case 9:
{
PortD=0x90;
break;

}
}
void kichhoat(int m)
{
PortA=0xff;
Bit_clear(PortA,m);
}

You might also like