- #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);
- }
- }
復制代碼 為什么這個程序可以使小燈由亮變暗,只是小燈亮和滅延時不同而已啊,好像改變了小燈的電壓一樣,哪位大神知道能給講講,謝謝啦。
|