//注意swictch语句case后是冒号,记得break
#include <STC15F2K60S2.H>
sbit HC138_A=P2^5;
sbit HC138_B=P2^6;
sbit HC138_C=P2^7;
sbit buzz_1= P0^6;
sbit jdq_2= P0^4;
void Delay(unsigned int num)
{
unsigned int i;
while(num--)
for(i=0; i<628; i++);
}
void Init_HC138(unsigned char n)
{
switch (n)
{
case 4:
HC138_A=0;
HC138_B=0;
HC138_C=1;
break;
case 5:
HC138_A=1;
HC138_B=0;
HC138_C=1;
break;
case 6:
HC138_A=0;
HC138_B=1;
HC138_C=1;
break;
case 7:
HC138_A=1;
HC138_B=1;
HC138_C=1;
break;
}
}
void close_buzz()
{
Init_HC138(5);
buzz_1=0;//0是关闭
jdq_2=0;//0是关闭
}
void led_disp()
{
Init_HC138(4);
P0=0xfe;
Delay(200);
P0=0xfd;
Delay(200);
P0=0xfb;
Delay(200);
P0=0xf7;
Delay(200);
P0=0xef;
Delay(200);
P0=0xdf;
Delay(200);
P0=0xbf;
Delay(200);
P0=0x7f;
Delay(200);
}
void main()
{
close_buzz();
while(1)
{
led_disp();
}
}