#define uchar unsigned char
sbit key1 = P3^2;
sbit key2 = P3^0;
sbit pin1 = P1^4;
sbit led1 = P3^1;
uchar condition=0,time;
void Time0_Init()
{
mTimer0Clk12DivFsys(); //T0定时器时钟设置
mTimer_x_ModInit(0,1); //T0定时器模式设置16位定时器
mTimer_x_SetData(0,0xC350); //T0定时器赋值5MS
mTimer0RunCTL(1); //T0定时器启动
ET0 = 1; //T0定时器中断开启
EA = 1;
}
voidmTimer0Interrupt( void ) interrupt INT_NO_TMR0 using 1 //timer0中断服务程序,使用寄存器组1
{
mTimer_x_SetData(0,0xC350); //非自动重载方式需重新给TH0和TL0赋值
time++;
if(time
{
pin1=1;
}
else
pin1=0;
if(time>=100)
{
time=0;
}
}
void main( )
{
CfgFsys( ); //CH554时钟选择配置
mDelaymS(5); //配置时钟后,建议延时稳定时钟
Time0_Init();
mDelaymS(5);
while(1)
{
if(key1==0)
{
mDelaymS(50);
if(key1==0)
{
led1=0;
condition+=10;
if(condition>=100)
{
condition=100;
}
}
}
if(key2==0)
{
mDelaymS(50);
if(key2==0)
{
led1=1;
condition-=10;
if(condition<=0)
{
condition=0;
}
}
}
}
}