Author Topic: 8051Debugging Help needed ( LED not blinking :P)  (Read 13633 times)

0 Members and 1 Guest are viewing this topic.

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
8051Debugging Help needed ( LED not blinking :P)
« on: August 11, 2013, 10:14:31 am »
So about two weeks ago I decided on starting a new project, this comes with using an AT89C2051 as the uC. I'm using the willar USB programmer and absolutely nothing. I've checked the circuit a few times and also changed every component. Below is a schematic and picture of the circuit.
Code: [Select]
#include<reg51.h>

// LED Pin
sbit LED = P1^0;    // Pin P1.0 is named as LED

//Function declarations
void cct_init(void);
void delay(int a);


int main(void)
{
   cct_init();           // Make all ports zero
 
   while(1)
   {
   LED = 0;            // Pin P1.0 Low
       delay(30000);    // Half sec delay
       LED = 1;    // Pin P1.0 High
       delay(30000);    // Half sec delay
   }
}

void cct_init(void)
{
P0 = 0x00;   
P1 = 0x00;   
P2 = 0x00;   
P3 = 0x00; 
}

void delay(int a)
{
   int i;
   for(i=0;i<a;i++);   //null statement
}


I dont think I've wired up the reset correctly, I've got the 10uf cap going form 5v to a 10K res which goes to GND. Also I have some serious doubts on my programmer Willar 200s its an open source usb programmer that is widely available here in Bangalore India.

Edit 1: Dont know if this will change anything but I'm running the system of a 12V-2A wall adapter that is reduced via a LM7805 with a 0.1uf and a 1000uf.
« Last Edit: August 11, 2013, 11:38:12 am by rohan-04 »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #1 on: August 11, 2013, 10:18:10 am »
I can see one major problem that will stop it from working.

Check the mcu pin numbering, it isn't the way you have that wired up.
With 99.9% of DIP/SOIC chips (this one included) the last pin (20 in this case) is located right above pin 1.

You have the led connected to pin 19 instead of 12,  also you have power going into pin 11 instead of pin 20

The chip should be ok. Wiring it up that way wont have damaged it.

« Last Edit: August 11, 2013, 10:27:11 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #2 on: August 11, 2013, 10:28:00 am »
You're right. But this was an error i made in breadboarding quick so i could get this post up. I've corrected it and uploaded a new pic still no different.
« Last Edit: August 11, 2013, 10:35:17 am by rohan-04 »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #3 on: August 11, 2013, 10:38:51 am »
I have no experience with the 8051 but from the datasheet it seems pretty clear that RESET is active high instead of active low like most mcus.

If this is the case then holding it high, like you are doing with a pullup, will keep the mcu in a reset state instead of a run state.

Try moving the reset resistor so its a pulldown instead of a pullup.  It may not reprogram like that but it might start running your code (if it has been programmed successfully in the past).

EDIT: i just noticed that you have it correct in the circuit diagram. Its just another breadboard issue.
« Last Edit: August 11, 2013, 10:48:26 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5127
  • Country: nl
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #4 on: August 11, 2013, 11:15:38 am »
The caps on the Xtal are taking the long route now, you better connect them directly to pin 10.
Also, put a decoupling cap between pins 10 and 20.
Keyboard error: Press F1 to continue.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #5 on: August 11, 2013, 11:21:26 am »
Also, if you have a scope, check if the xtal is oscillating (x10 probe)
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #6 on: August 11, 2013, 11:34:06 am »
Unfortunately, I cant afford and scope nor do i know enough of what im doing to be safe with one. I will try changing rest around and added the caps.
 

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #7 on: August 11, 2013, 11:36:50 am »
The caps on the Xtal are taking the long route now, you better connect them directly to pin 10.
Also, put a decoupling cap between pins 10 and 20.

What do you mean long route? And Is it not necessary for the caps to be connected to the crystal? Added the caps on 10 and 20 and didnt get anything.
 

Offline RoadRunner

  • Frequent Contributor
  • **
  • Posts: 378
  • Country: de
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #8 on: August 11, 2013, 12:01:33 pm »
i guess atmel 8051 mcu is not capable of sourcing much current from the port pin , even not enough for a tiny led.
but port pin can sink 20mA  so connect your led backwards  i hope it can work.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #9 on: August 11, 2013, 12:05:51 pm »
Yep. :-+ They're only meant for high-current sink, not source. Flip the LED around.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #10 on: August 11, 2013, 12:06:19 pm »
Yeah, move the led+resistor so its between P1.0 and VCC


What do you mean long route? And Is it not necessary for the caps to be connected to the crystal? Added the caps on 10 and 20 and didnt get anything.

He means the GND for the xtal caps has to travel longer than it needs to. When it comes to xtals, keep the connections short.
I don't think that's your problem though.
« Last Edit: August 11, 2013, 12:12:03 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #11 on: August 11, 2013, 12:21:13 pm »
Yep. :-+ They're only meant for high-current sink, not source. Flip the LED around.
According to the datasheet it can only source ~80uA to maintain a voltage of 2.4V.

I've always wondered why this is the case - for NMOS I can understand the pullup resistor creates a source impedance, but wouldn't it be symmetrical for CMOS?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #12 on: August 11, 2013, 12:25:36 pm »
The high side transistor in the driver is probably being using for a dual purpose to save on transistors.
If it pulls high through a resistor then it can both..
- Enable/disable a pullup for inputs
- Pull high for an output (but due to the resistor quite weakly)

At least, that's my guess.
« Last Edit: August 11, 2013, 12:28:42 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #13 on: August 11, 2013, 01:21:48 pm »
That port on an 8051 is pull down only. The 80ua is a small current source to dampen glitches.
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #14 on: August 11, 2013, 05:28:04 pm »
Yeah, move the led+resistor so its between P1.0 and VCC


How would one do this?
From what I understand P1 isnt supplying enough current to the led. I connected the led directly and the res to the - side still nothing.
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #15 on: August 11, 2013, 07:41:16 pm »
5 votls - led anode - led cathode - resistor - resistor pin of 8051
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #16 on: August 11, 2013, 08:21:50 pm »
Still nothing. I also tried a different Port and changed the code for P3.0 and still nothing. The led is just brighter now also changed the res from 10k to 1.8k.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #17 on: August 12, 2013, 06:35:39 am »
Yeah, move the led+resistor so its between P1.0 and VCC

How would one do this?
From what I understand P1 isnt supplying enough current to the led. I connected the led directly and the res to the - side still nothing.

The output pins on that mcu are like switches to GND.  That's all they can really do. It can't output a voltage like a modern micro can. (at least not at any usable current).

Connect it like this, (make sure you get the led around the right way)

This way, when the code outputs a "low", the output will switch GND onto the resistor and the led will light up.
When the code outputs a "high" the led will switch off. 
« Last Edit: August 12, 2013, 06:40:46 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline qno

  • Frequent Contributor
  • **
  • Posts: 422
  • Country: nl
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #18 on: August 12, 2013, 06:39:56 am »
This reminds me of:

Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und
vatch das blinkenlights!!!
Why spend money I don't have on things I don't need to impress people I don't like?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #19 on: August 12, 2013, 06:43:06 am »
This microcontroller is so old it probably has a grey beard made of tin whiskers.
« Last Edit: August 12, 2013, 08:41:02 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline lapm

  • Frequent Contributor
  • **
  • Posts: 564
  • Country: fi
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #20 on: August 12, 2013, 07:17:24 am »
Well heres few things i have learned over the years with microcontrollers.

- Crystal oscillator, make sure you have proper bypass capacitor to ground. Keep ground path short as bossible.

- Pin out of chip, check it, check it again just in case.

- Output pins, check datasheet for internal hardware to see what its exactly can do. PIF16F84 had infamous RB4 pin that could not source current at all, could sink it well... Bite me first time i tried to use it... Yes this is old example but very fitting when if comes to pin thats open-drain type output only.

- Options inside program code that can effect how chip behaves, oscillator settings, etc... Make sure you know the default values witch chip comes from factory.

- Always double check your connections. Not a few times i have forgot one wire from breadboard and that missing wire has caused circuit to do strange things...

- Program code itself, are you sure you understand what its doing or is supposed to be doing. I have tons of these, bugs, incompability issues between chips over missing hardware options, etc...

- If anything else fails, go back to basics, read datasheet again, bring out multimeter and just try drive that pin up or down...

Yes, even after all these years i still get bit by some of these still. Live and learn i say. Failure often teaches us more then success.
Electronics, Linux, Programming, Science... im interested all of it...
 

Offline rohan-04Topic starter

  • Contributor
  • Posts: 45
  • Country: in
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #21 on: August 12, 2013, 01:00:48 pm »
Still nothing gentlemen, I've done the re-arrangement of the led and res. This all just points to the programmer being at fault, or could there be an issue with the header file?
 

Offline JoeO

  • Frequent Contributor
  • **
  • Posts: 527
  • Country: us
  • I admit to being deplorable
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #22 on: August 12, 2013, 03:09:41 pm »
Divide and conquer: Write a program to turn on the LED and then endless loop.  Then write a program to turn the LED off and endless loop.  These results will tell you where your problem is.
The day Al Gore was born there were 7,000 polar bears on Earth.
Today, only 26,000 remain.
 

Offline Alana

  • Frequent Contributor
  • **
  • Posts: 297
  • Country: pl
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #23 on: August 12, 2013, 06:14:20 pm »
Quirks about 8051 family in 20pin packages - port p1.0 and p1.1 is kind of open collector - those 2 pins are connected to internal analouge comparator and cannot source current. This should not be an issue here but you may try to move to some other pins.
And if you are unsure about your programing try to test your circut using Bascom 8051 or even assembly language. At least for me those two are easier than C for 8051 family.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: 8051Debugging Help needed ( LED not blinking :P)
« Reply #24 on: August 12, 2013, 11:18:12 pm »
I'm beginning to think the chip hasn't been programmed.
Greek letter 'Psi' (not Pounds per Square Inch)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf