如何實現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; //點亮第1 個二極管
Delay();
c=0; b=0; a=1; //點亮第2 個二極管
Delay();
c=0; b=1; a=0; //點亮第3 個二極管
Delay();
c=0; b=1; a=1; //點亮第4 個二極管
Delay();
c=1; b=0; a=0; //點亮第5 個二極管
Delay();
c=1; b=0; a=1; //點亮第6 個二極管
Delay();
c=1; b=1; a=0; //點亮第7 個二極管
Delay();
c=1; b=1; a=1; //點亮第8 個二極管
Delay();
}
}
評論