单片机 可调节亮度LED

#include <regx51.h>
sbit key=P2^0;
sbit LED=P1^0;

void T0delay1ms(unsigned short ms){
	unsigned char k;
	for(k=0;k<ms;k++){
		TH0=(65536-50000)/256;
		TL0=(65536-50000)%256;
		TR0=1;
		while(!TF0);
		TF0=0;
	}
}

void main(void){
	unsigned char ms=1,i=0,up=1;
	TMOD &=0xf0;
	TMOD |=0x01;
	LED=1;
	while(1){
		while(key==0){
			if(++i>9){
				i=0;
				if(up){
					if(++ms>8){
					up=0;
					}
				}
					else{
						if(--ms<2){
							up=1;
						}
					}
				}
						LED=0;
						T0delay1ms(ms);
						LED=1;
						T0delay1ms(10-ms);
					}
					LED=0;
					T0delay1ms(1);
					LED=1;
					T0delay1ms(9);
				}
		}
	

上一篇:notepad++ :正则表达式系统教程


下一篇:IfcFlowMovingDevice