+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Newbie level 3
    Points: 28, Level: 1

    Join Date
    Jun 2017
    Posts
    4
    Helped
    0 / 0
    Points
    28
    Level
    1

    LED brightness control by pwm for at89c51

    Hello friends,

    Can anybody help me in writing a code of led brightness control by using puls width modulation (pwm) for at89c51 as I'm stuck in it.

    Note that I heve reviewed the related answers for this problem, but sadly, non of them has worked.


    Your help is highly appreciated.

    •   Alt19th June 2017, 12:56

      advertising

        
       

  2. #2
    Super Moderator
    Points: 45,841, Level: 52
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    9,388
    Helped
    2255 / 2255
    Points
    45,841
    Level
    52

    Re: LED brightness control by pwm for at89c51

    Hi,

    Show what you have done so far.
    What code did you try? What did you expect? And what did you get instead?

    Klaus



  3. #3
    Newbie level 3
    Points: 28, Level: 1

    Join Date
    Jun 2017
    Posts
    4
    Helped
    0 / 0
    Points
    28
    Level
    1

    Re: LED brightness control by pwm for at89c51

    Thanks KlausST for your reply,

    In fact, there is a code which was posted in this forum that I'm using and here is it:
    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    
    #include<reg51.h>
    unsigned char segment  = 10;
    unsigned char brightness ; // your brightness - range 0 (dark) to 255 (lght)
    static unsigned char i = 0;
     
    sbit LED = P1^0;
     
    void timer_isr(void) interrupt 1 using 1 {  // 1 = timer 0 interrupt
    if (--segment==0) {
            LED     = 0;                        // LED off
           segment = 10;
            }
        if (segment==brightness) LED = 10;  
    {
     
     
     
    if(i++ < brightness)
    {
        P1=P2=0xFF;
    }
    // turn on LED
    else{
     //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 on
         while (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.

    Thanks in advance,
    Osama



    •   Alt19th June 2017, 15:00

      advertising

        
       

  4. #4
    Super Moderator
    Points: 45,841, Level: 52
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    9,388
    Helped
    2255 / 2255
    Points
    45,841
    Level
    52

    Re: LED brightness control by pwm for at89c51

    Hi,

    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%.

    Use 10% duty cycle if you use your eyes.

    Klaus



  5. #5
    Newbie level 3
    Points: 28, Level: 1

    Join Date
    Jun 2017
    Posts
    4
    Helped
    0 / 0
    Points
    28
    Level
    1

    Re: LED brightness control by pwm for at89c51

    Hi,

    How can I add the duty cycle to the attached code ?



  6. #6
    Advanced Member level 5
    Points: 11,220, Level: 25

    Join Date
    Nov 2012
    Posts
    2,103
    Helped
    468 / 468
    Points
    11,220
    Level
    25

    Re: LED brightness control by pwm for at89c51

    chnage the value in line number 37



    •   Alt20th June 2017, 10:29

      advertising

        
       

  7. #7
    Newbie level 3
    Points: 28, Level: 1

    Join Date
    Jun 2017
    Posts
    4
    Helped
    0 / 0
    Points
    28
    Level
    1

    Re: LED brightness control by pwm for at89c51

    Already did, no use.

    If somebody can help me with coding it, would be much appreciated.

    Thasnks in advance.



  8. #8
    Super Moderator
    Points: 45,841, Level: 52
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    9,388
    Helped
    2255 / 2255
    Points
    45,841
    Level
    52

    Re: LED brightness control by pwm for at89c51

    Hi,

    are you sure the microcontroller is running at all? How?

    Nobody will wirte code for you.
    But many members will help you to find out the problem, but you have to give enough informations first.

    --> Circuit diagram, photo of the circuit, scope pictures, descriptions, debug informations...

    Klaus



--[[ ]]--