#include\x0d\x0asbit LED0=P0^0\x0d\x0asbit wei=P1^1\x0d\x0asbit duan=P1^0\x0d\x0asbit lcden=P1^7\x0d\x0asbit dianzhen=P1^3\x0d\x0asbit leden=P1^2\x0d\x0avoid Delay(unsigned int t)\x0d\x0avoid main (void)\x0d\x0a{\x0d\x0aunsigned int CYCLE=600,PWM_LOW=0//定义
周期并
赋值\x0d\x0alcden=0\x0d\x0aP0=0x00\x0d\x0adianzhen=0\x0d\x0aP0=0xff\x0d\x0awei=0\x0d\x0aduan=0\x0d\x0awhile (1) //主循环\x0d\x0a{\x0d\x0aLED0=1\x0d\x0aDelay(150000)//特意加延时,
可以看到熄灭的过程\x0d\x0afor(PWM_LOW=1PWM_LOW0PWM_LOW--)\x0d\x0a{\x0d\x0aLED0=0\x0d\x0a \x0d\x0aDelay(PWM_LOW)\x0d\x0a \x0d\x0aLED0=1\x0d\x0a \x0d\x0aDelay(CYCLE-PWM_LOW)\x0d\x0a}\x0d\x0a}\x0d\x0a}\x0d\x0avoid Delay(unsigned int t)\x0d\x0a{\x0d\x0awhile(t--)\x0d\x0a}#include<reg51.h>
sbit LED0=P0^0
sbit wei=P1^1
sbit duan=P1^0
sbit lcden=P1^7
sbit dianzhen=P1^3
sbit leden=P1^2
void Delay(unsigned int t)
void main (void)
{
unsigned int CYCLE=600,PWM_LOW=0//定义周期并赋值
lcden=0
P0=0x00
dianzhen=0
P0=0xff
wei=0
duan=0
while (1) //主循环
{
LED0=1
Delay(150000)//特意加延时,可以看到熄灭的过程
for(PWM_LOW=1PWM_LOW<CYCLEPWM_LOW++)
{
LED0=0
Delay(PWM_LOW)
LED0=1
Delay(CYCLE-PWM_LOW)
}
for(PWM_LOW=CYCLE-1PWM_LOW>0PWM_LOW--)
{
LED0=0
Delay(PWM_LOW)
LED0=1
Delay(CYCLE-PWM_LOW)
}
}
}
void Delay(unsigned int t)
{
while(t--)
}
评论列表(0条)