#include "reg52.h"
sbit HC138_A = P2^5;
sbit HC138_B = P2^6;
sbit HC138_C = P2^7;
void delay(unsigned int t)
{
while(t--);
while(t--);
}
void YN(unsigned char n)
{
switch(n)
{
case 4:
HC138_C = 1;
HC138_B = 0;
HC138_A = 0;
break;
case 5:
HC138_C = 1;
HC138_B = 0;
HC138_A = 1;
break;
case 6:
HC138_C = 1;
HC138_B = 1;
HC138_A = 0;
break;
case 7:
HC138_C = 1;
HC138_B = 1;
HC138_A = 1;
break;
}
}
void outputP0(unsigned char channel,unsigned char dat)
{
YN(channel);
P0 = dat;
}
void LEDrunning()
{
unsigned char i;
for(i = 0;i<3;i++)
{
outputP0(4,0x00);
delay(60000);
delay(60000);
outputP0(4,0xff);
delay(60000);
delay(60000);
}
for(i = 1;i<=8;i++)
{
outputP0(4,(0xff << i));
delay(60000);
delay(60000);
}
outputP0(5,0x10);
delay(60000);
outputP0(5,0x00);
for(i = 1;i<=8;i++)
{
outputP0(4,~(0xff << i));
delay(60000);
delay(60000);
}
outputP0(5,0x40);
delay(60000);
outputP0(5,0x00);
}
void InitSysyem()
{
outputP0(5,0x00);
}
void main()
{
InitSysyem();
while(1)
{
LEDrunning();
}
}
标签:02,case,HC138,void,继电器,unsigned,char,break,蜂鸣器
From: https://www.cnblogs.com/Unclesundada/p/16995597.html