如何實(shí)現(xiàn)138譯碼器控制二極管
#include
sbit c=P2^4; //譯碼器74138是一種3線-8線譯碼器
sbit b=P2^3;
sbit a=P2^2;
void Delay()
{
unsigned char j;
unsigned int i;
for(i=1000; i>0; i--)
for(j=110; j>0; j--);
}
void main()
{
while(1)
{
c=0; b=0; a=0; //點(diǎn)亮第1 個(gè)二極管
Delay();
c=0; b=0; a=1; //點(diǎn)亮第2 個(gè)二極管
Delay();
c=0; b=1; a=0; //點(diǎn)亮第3 個(gè)二極管
Delay();
c=0; b=1; a=1; //點(diǎn)亮第4 個(gè)二極管
Delay();
c=1; b=0; a=0; //點(diǎn)亮第5 個(gè)二極管
Delay();
c=1; b=0; a=1; //點(diǎn)亮第6 個(gè)二極管
Delay();
c=1; b=1; a=0; //點(diǎn)亮第7 個(gè)二極管
Delay();
c=1; b=1; a=1; //點(diǎn)亮第8 個(gè)二極管
Delay();
}
}
評(píng)論