- #include<reg52.h>
- #define uint unsigned int
- sbit pwm=P1^0;
- uint cycle,high,low;
- void delay(uint t)
- {
- while(t--);
- }
- void main()
- {
- cycle=800;
- while(1)
- {
- for(high=1;high<=cycle;high++)
- {
- pwm=1;
- delay(high);
- low=cycle-high;
- pwm=0;
- delay(low);
- }
- high=1;
- delay(60000);
- }
- }
复制代码 为什么这个程序可以使小灯由亮变暗,只是小灯亮和灭延时不同而已啊,好像改变了小灯的电压一样,哪位大神知道能给讲讲,谢谢啦。
|