8051 led blink problem

Thread Starter

aashishaac

Joined May 10, 2014
8
Hi I am aashish, I am a pure beginner to 8051 microcontrollers and want to Blink a LED with it (as my first test).


But at the end the LED did not blink :mad::mad:, I performed the following steps,
1. Generate Hex file from keil uVision
2. Flash the AT89S52 with this hex file using a 8051 programmer.
3. Connect a LED to AT89S52 on breadboard to test my work.


Please have a look at the word document : https://drive.google.com/file/d/0B5NYQC3oiHcHcjh2a3RBOW5famc/edit?usp=sharing to see the detailed steps that I have followed along with the connection of LED to AT89S52 on breadboard to test my work


So where I was wrong? my program is incorrect/incomplete?? Or Does the AT89S52 not have an on chip clock? Whether I have to connect an external crystal?? Or anything I am missing….??


Please help me I am in a great need of it. Please help.


Thanks in advance.
 

absf

Joined Dec 29, 2010
1,968
Did you check out Ian Rogers' 8051 tutorial #1 ? He detailed how to blink the LED with ASM and C.

8051 tutorial 1

The RST in the schematic you linked was left unconnected. I remember you have to connect that pin to ground in order for it to work.

Allen
 

Arm_n_Legs

Joined Mar 7, 2007
186
The reset (RST) is not connected. Connect the RST to a 10uF cap. The other end of the cap connect to Vcc.

I think this IC does not hv an internal oscillator. You may need to connect up the crystal with 2 external caps.
 

Thread Starter

aashishaac

Joined May 10, 2014
8
Thanks all of you for your fruitful replies........

Can any body please ensure me that whether my program is correct ?

And please send me a sample LED hookup circuit diagram

Thanks in advance
 

Thread Starter

aashishaac

Joined May 10, 2014
8
I changed the circuit to this,

but the same problem persists....LED glows but not blink.

For a while I thought that if my AT89S52 IC is damaged but if it were it was not and even now get program correctly.

So what is the matter ? Please help me, I am in a great need of it for my project.
Thanks in advance
 

djsfantasi

Joined Apr 11, 2010
9,163
Where did you get the value of 1275 used in your second for loop? Are you sure that the loop takes 1ms to execute?

If it's much less, then your delay will be wrong. If it's too short, the LED will appear to be always on, but dimmer. The dimness is caused by a PWM effect resulting in 1/2 power to the LED.

If you are sure of this value, then I got nothing.
 

Thread Starter

aashishaac

Joined May 10, 2014
8
Thanks for your reply djsfantas, I am suffering from exactly that you have written : the LED will appear to be always on, but dimmer.

Actually sir,I am an absolute beginner to 8051/52 and I was mt very first test just after purchasing the IC and its programmer, I a got the 1275 in a tutorial by just goggling AT89S52 led blink.

I am not sure to this value, please guide me with the suitable value and/or good program to blink led.

Thanks in advance. Please help me, I am in a great need of it

Thanks......Waiting for your reply........
 

absf

Joined Dec 29, 2010
1,968
I simulated your hardware and it was working on Proteus. I am not sure if P1.0 is able to source the LED so I connected it as sinking.

The code I used was from http://www.electro-tech-online.com/articles/basic-8051-tutorial-1.667/

Rich (BB code):
        org 0   ; Reset vector
sjmp Start
        org 30H    ; Code starts here
Start:
    setb    P1.0    ; Set LED pin ( turn off LED )
    acall    delay
    clr    P1.0    ; Clear LED pin ( turn on LED )
    acall    delay
    sjmp    Start    ; do it again ( Forever loop )
delay:
    mov R2,#225   ; 2 clock cycles (call) = 2
    mov R1,#0   ; 2 clock cycles (loading) = 2
    d1: djnz R1,d1   ; 2 * 256 clock cycles *225 = 115200
    djnz R2,d1    ; 2 * 225 clock cycles = 450
    ret     ; 2 clock cycles (return) = 2
    end
Sorry, I dont know how to use 8051 C yet.

Allen
 

Attachments

djsfantasi

Joined Apr 11, 2010
9,163
One way to check the value is experimental. Try increasing it by a factor of 10. I.e., change it to 12750. Then observe the results and tune the value until the desired time is met.

I am not familiar with the 8051, but am a programmer. Often the language will have a built in delay function so that you don't have to code your own as you have done? I would check to see if there is such a function available.

One of the difficulties in using hard coded loops for timing is that it is dependent on the specific type of chip and it's clock speed.
 

Thread Starter

aashishaac

Joined May 10, 2014
8
thanks for your reply djsfantasi and absf, I don't think that proteus is a good and reliable software, because the hardware and code what I am suffering from is running well in proteus, also with and without crystal, connecting/ not connecting reset circuitry etc has no effect on its simulation ????

One thing I have to say that I am a regular user of Atmega16, 328 i.e., AVR microcontrollers, and I never got such a problem, it does not require a reset circuitry and has inbuilt clock source so no need of external crystal also, but for 8051 I am getting tired now, but I will never giveup (it is my habit)

Please guide me more (like a teacher), I really need it

Thanks in advance........waiting for your fruitful replies
 

ErnieM

Joined Apr 24, 2011
8,377
A simulator makes certain assumptions about your circuit. These include it has proper power, proper decoupling, proper reset signals, and the like. It also assumes the hardware was built the same as you drew in the simulator.

My rule of thumb here is "if it can't sim then you can't win." That means if it doesn't work in the simulator it cannot work on the real hardware.

Note the reverse is not true: a circuit may not correctly simulate but work perfectly fine. This is due to the limits of any simulator.

Summation: don't give up on the simulator.
 

djsfantasi

Joined Apr 11, 2010
9,163
I did some research and the examples I found used a much smaller value in the loop for a 1ms delay. Exactly opposite of what I would expect. See this link http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm

The delay depends on the clock speed and compiler. Some compilers may optimize the loop out of existence, since it's doing nothing.

The article also describes the process I alluded to, to time a large value, calculate a better value and repeat the test, and then divide to get the specific value.

First, I would use a very large value for the loop; perhaps 32767 as it's the largest positive integer and see what the delay is by timing with a watch. I would set the delay call to 1000.

Note that if the optimizer removes the "do nothing" loop, this should have no effect. Then, you may have to insert some operation with the index within the loop.

If the large value results in a 12second delay (I am making the numbers up in this example), then reduce the value and re-time until it results in an even 10 second delay.

Since you are calling delay for a 1 second delay, delaying for 10 seconds means that your value is 10 times too large. So divide it by 10 and test again.

Understand?

Since your simulator works and the observed behavior is that the delay is not happening, I suspect the compiler. If it turns out that is the case, try my suggestion of inserting an operation within the loop. For example, define an integer k just within the function and in the inner loop, add "k=j-1;". Of course this will also affect your timing value, and you'll have to retune its value.
 

JohnInTX

Joined Jun 26, 2012
4,787
One problem may be that the circuit requires the port pin to SOURCE the LED current.

4.3 Port 0
Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL
inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance inputs.
That and looking at Ch. 27 DC Electrical Characteristics says (as I read it) that it sources squat but does sink up to 26ma.

Turn the LED around. Connect its anode to +5 through the resistor. Connect the cathode to P0.0 and make '0' = ON.

Please guide me more (like a teacher), I really need it
Avoid pictorial diagrams as shown in #2. Schematic diagrams like yours in #5 are much better.

Good luck.
 
Last edited:

Thread Starter

aashishaac

Joined May 10, 2014
8
Great thanks for your replies, but even now I could not get the LED blink,

Try 1 : Mr. djsfantasi I read your link http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm and implemented the

delay_1s() // timer of 1 sec
{
int d;
for(d=0;d<=20;d++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}
} - See more at: http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm#sthash.knwYMAxT.dpuf
Rich (BB code):
delay_1s() // timer of 1 sec
{
int d;
for(d=0;d<=20;d++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}
}
delay_1s()			                               // timer of 1 sec
{
int d;
	for(d=0;d<=20;d++)
	{
	TMOD=0x01;
	TL0=0xFD;
	TH0=0x04B;
	TR0=1;		                                        // start timer.
	while(TF0==0);	                               // run until TF turns to 1
	TR0=0;		                                      // stop timer
	TF0=0;		                                     // reset the flag
	}
} - See more at: http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm#sthash.knwYMAxT.dpuf
but the LED does not glow any more.

Try 2 : Mr. djsfantasi I tried 32767in my for loop but no effect LED dimmer and not flashing, I tried adding "k=j-1;" to the inner for loop but no effect.

Try 3 : Mr. absf asm code I tried the asm code and the circuit [http://www.electro-tech-online.com/attachments/switch-png.85572/switch.png]
from the tutorial, but LED not even lightup.

Try 4 : Mr. JohnInTX tried sourcing and sinking LED not not helpful.


I am using Arduino and AVR Atmega microcontrollers but never got such type of problem ????

Please help me, I am not giving up now because I know that I am making a mistake either in my code,and/or in wiring but....... Huh!

I know and experienced also ''Try again and again and You will get success at last" .......... but just waiting that successful last.

Thanks in advance........waiting for your fruitful replies


delay_1s() // timer of 1 sec
{
int d;
for(d=0;d<=20;d++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}
} - See more at: http://www.8051projects.net/t18426/8051-discussion-forum/delay-loop-in-c.htm#sthash.knwYMAxT.dpuf
 

Thread Starter

aashishaac

Joined May 10, 2014
8
So, have you all stopped replying me .........????????:mad::mad:

Please don't do this, can anybody take some pain to the needful and experiment by his/her own on AT89S52 on breadboard.

Please help me.:mad::mad::mad:
 

absf

Joined Dec 29, 2010
1,968
Can you attach your compiled HEX file here? So I can try it out on my 8051 SBC? My 8051 SBC is called EMC32 from a Canadian company. It uses external memories.

Allen
 
Hi I am aashish, I am a pure beginner to 8051 microcontrollers and want to Blink a LED with it (as my first test).


But at the end the LED did not blink :mad::mad:, I performed the following steps,
1. Generate Hex file from keil uVision
2. Flash the AT89S52 with this hex file using a 8051 programmer.
3. Connect a LED to AT89S52 on breadboard to test my work.


Please have a look at the word document : https://drive.google.com/file/d/0B5NYQC3oiHcHcjh2a3RBOW5famc/edit?usp=sharing to see the detailed steps that I have followed along with the connection of LED to AT89S52 on breadboard to test my work


So where I was wrong? my program is incorrect/incomplete?? Or Does the AT89S52 not have an on chip clock? Whether I have to connect an external crystal?? Or anything I am missing….??


Please help me I am in a great need of it. Please help.


Thanks in advance.
i too had a similar problem , i did this and it worked. you have tot connect pin number 31 to Vcc. this makes the IC select internal ROM. next also try grounding your reset pin, dont leave it floating. hope this helps
 
Top