#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;
sbit L1=P0^0;
sbit L2=P0^1;
sbit L3=P0^2;
sbit L4=P0^3;
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 led_disp()
{
Init_HC138(4);
P0=0xff;
}
void close_buzz()
{
Init_HC138(5);
buzz_1=0;//0是关闭
jdq_2=0;//0是关闭
}
/*****************************************************************/
void Timer1Init(void) //1毫秒@12.000MHz
{
AUXR &= 0xBF; //定时器时钟12T模式
TMOD &= 0x0F; //设置定时器模式
TL1 = 0x18; //设置定时初始值
TH1 = 0xFC; //设置定时初始值
TF1 = 0; //清除TF1标志
TR1 = 1; //定时器1开始计时
ET1 = 1; // 允许定时器 1 中断
EA = 1; // 允许系统中断
}
void ServiceTimer1() interrupt 3
{
static unsigned int T1Count;
T1Count++;
if(T1Count>=1000)
{
L1=0;
}
if(T1Count>=2000)
{
L2=0;
}
if(T1Count>=3000)
{
L3=0;
}
if(T1Count>=4000)
{
L4=0;
}
}
/*****************************************************************/
void main()
{
close_buzz();
led_disp();
Timer1Init();
while(1)
{
}
}