本帖最后由 t.jm 于 2012-2-7 14:06 编辑
这个电路LED也能调光,问题出在drive
void drive(void) {
unsigned int a;
a=Brightness;
LED=0;
delay(a);
a=~a;
LED=1;
delay(a);
a=~a;
}
不能调光是因为a是int,而Brightness是uchar,所以~a后总是>0xff00,调光范围很小。
改成:
void drive(void) {
static unsigned char a;
if(a++ >= Brightness)
LED=1;
else
LED=0;
} |