如何实现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();
}
}

评论