#include<reg51.h>unsignedchar segment =10;unsignedchar brightness ;// your brightness - range 0 (dark) to 255 (lght)staticunsignedchar i =0;
sbit LED = P1^0;void timer_isr(void) interrupt 1 using 1{// 1 = timer 0 interruptif(--segment==0){
LED =0;// LED off
segment =10;}if(segment==brightness) LED =10;{if(i++< brightness){
P1=P2=0xFF;}// turn on LEDelse{//turn off LED}}}void main(void){
TMOD =1;// timer 0 auto reload
TH0 =-250;// 250 uS each segment
TR0 =1;// start timer 0
ET0 =1;// enable timer 0 interrupt
EA =1;// enable interrupt system
LED =0;// turn LED off
brightness =5;// LED on// 0 : off; 10 : full onwhile(1);}
My expectation and aim is to bright my leds to 50 % only, while I'm getting a full of 100% brightness which I do not want.
How do you know it is 100%?
Our eyes react very unlinear, they are not a useful measurement device.You may recognize almost no difference between 100% and 50%.