Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LED brightness control by pwm for at89c51

Status
Not open for further replies.

osama_xyz

Newbie level 3
Joined
Jun 19, 2017
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
36
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.
 

Hi,

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

Klaus
 

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
 

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
 

Hi,

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

chnage the value in line number 37
 

Already did, no use.

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

Thasnks in advance.
 

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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top