#include <STC15.H>
sbit led = P3^3;
sbit ledgao = P3^4; //调亮
sbit leddi =P3^5; //调暗
sbit ledkg =P3^2; //开关
sbit fmq =P3^1; //蜂鸣器
bit work; //工作标识
unsigned char num;
unsigned char light;
#define kg_NO() led=1
#define kg_OFF() led=0
char key(num)
{
if(work==1)
{
if(ledgao==0)
{
num++;
if(num>100)
{
num=100;
fmq=!fmq;
}
}
if(leddi==0)
{
num--;
if(num<=1)
{
num=1;
fmq=!fmq;
}
}
}
return num;
}
void exint0() interrupt 0
{
if(ledkg==0)
{
work=1;
}
if(ledkg==1)
{
work=0;
kg_OFF();
}
}
void Timer0Init(void) //100微妙@11.0592MHz
{
AUXR |= 0x80; // 1T模式
TMOD &= 0xF0;
TL0 = 0xAE;
TH0 = 0xFB;
TR0 = 1;
ET0 = 1;
EA = 1;
}
void tm0_isr() interrupt 1
{
if(light=key(num))
kg_NO();
}
void main()
{
P3M0 = 0x00;
P3M1 = 0x0A;
led = 0;
ledgao =1;
leddi =1;
ledkg =1;
fmq =0;
num=50;
Timer0Init();
IT0 = 0;
EX0 = 1;
while(1)
{
key(num);
}
} |