#include
//IO引脚定义;
sbit LED=P1^0; // 用sbit关键字定义LED到P1.0端口
void Delay(unsigned int t); //延时函数声明
void main (void)
{
// unsigned int Time=1000, PWM=0; //定义周期并赋值 (STC12C5A60S2芯片)
unsigned int Time=500, PWM=0; //定义周期并赋值 (STC89C52RC芯片)
while (1) //主循环
{
LED=1; //P1.0管脚赋值1高电平,熄灭LED灯
Delay(50000); //延时
for(PWM=1; PWM
{
LED=0; //点亮LED
Delay(PWM);
LED=1; //熄灭LED
Delay(Time-PWM);
}
LED=0;
Delay(50000); //延时
for(PWM=Time-1; PWM>0; PWM--) //与逐渐变亮相反的过程
{
LED=0; //点亮LED
Delay(PWM);
LED=1; //熄灭LED
Delay(Time - PWM);
}
}
}
/*------------------------------------------------
延时函数,含有输入参数 unsigned int t,无返回值
范围是0~65535
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………