Help newbie with led chaser project please :)

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I have recently become an ATMEL / AVR fan (WHATS AVR ?!?!?) and have gotten stuck on my first basic project. I am unsure if it is code related or not. Any help would be greatly appreciated.

ISSUE:

* LEDS 1&2 light up at ~50% brightness and LED 3 at ~20%.
* LEDS dont work as expected.

Parts:

* 1x AT89C51
* 1x 8.2k ohm resistor
* 8x 300 ohm resistors
* 8x 3mm 2.1v LEDS
* 1x 10Mhz SPF Crystal
* 2x 33pf Caps
* 1x 10uF Cap
* 1x 6v Lantern battery

I would appreciate if anyone could offer insite to the issue, I have hit a wall it seems after trying all I can find via google.
The programmer verifies fine each time I program and I have 4 chips to test / alternate between.

leds1.c:

#include < REGX51.H > 
		   
char const num[ ] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; 

void wait (void)
{ ; /* wait function */ 
} 

void main( void )
{
	unsigned int i;
	unsigned char j; 

	P0 = 0; /* initialize ZERO to P0 */

	while(1)
	{

		for( j = 0; j < 8; j++ )
		{
			P0 = num[ j ];
			   
			for ( i = 0; i < 10000; i++ )
			{
				wait(); /* delay for half second */ 
			}
		}
	}
}

See my electronics blog for more info: http://i-bullshit.blogspot.com
:twisted:

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You ask: (WHATS AVR ?!?!?)

Well, for one thing the AT89C51 is not an AVR microcontroller.

It is kind of hard to get beyond that point on an AVR forum.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If my memory of 8051s isn't playing me up (the AT89C51 is an 8051 derivative), the pins of Port 0 (where you've connected your LEDs) are incapable of pulling HIGH, as lighting up your LEDs would require them to do. Reverse your LEDs, so that their cathodes go to the resistors whose other ends connect to Port0 pins, and their anodes go to your VCC. And you should check to see if the '89C51 is rated to operate from 6V. Then in software, you clear bits of Port0, rather than setting them, to turn the associated LED ON.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

smileymicros wrote:
You ask: (WHATS AVR ?!?!?)

Well, for one thing the AT89C51 is not an AVR microcontroller.

It is kind of hard to get beyond that point on an AVR forum.

As I said Im a newbie to all this, the video "What is an AVR" linked on this forums main site was definitely not helpful in distinguishing nor was googling "What is an AVR". Thanks to some helpful people I have learned that they are different arch's and thats that (unless you care to enlighten us). So sorry for making a 1st timers mistake, rest assured the next batch of chips I buy to play with will be AVR's.

Levenkay wrote:
If my memory of 8051s isn't playing me up (the AT89C51 is an 8051 derivative), the pins of Port 0 (where you've connected your LEDs) are incapable of pulling HIGH, as lighting up your LEDs would require them to do. Reverse your LEDs, so that their cathodes go to the resistors whose other ends connect to Port0 pins, and their anodes go to your VCC. And you should check to see if the '89C51 is rated to operate from 6V. Then in software, you clear bits of Port0, rather than setting them, to turn the associated LED ON.

Thanks alot Levenkay, you have given me something to go on.
Below is the section of the AT89C51's pdf regarding port 0 and port 1 pins.

Pulling High = make voltage available correct ?
Assuming I understood that (after a few wiki pages) Port zero when it has a 1 written to it should go high impedance preventing voltage and turning off the led correct ?

I rewired my bread board as per your instructions (but using same code atm) and tested, all leds come on @ normal brightness now. Would I be correct in assuming that all LEDS are bright due to the Ports being still open (sinking volts) ?.

Do you know how to write 1's to each individual pin in C ?, atm I am working of example code and it seems to me (atm anyway) that you can only toggle 1 pin at a time.

Thankyou for your help, again sorry for posting to the wrong forums, Levenkay - if you have an account I have also started a similar thread in http://www.8051projects.net/plugins/forum/forum_viewtopic.php?12229.last which appears to be the correct spot for it.
Cheers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mem.namefix wrote:

Pulling High = make voltage available correct ?
Assuming I understood that (after a few wiki pages) Port zero when it has a 1 written to it should go high impedance preventing voltage and turning off the led correct ?
Correct conclusion, but I think of it more that when Port 0 pins have 1s written to them, they're not behaving like zeroes anymore, meaning that they're not acting like shorts to ground. In the case of Port0 8051 pins, there's nothing inside the part acting to "pull up" or raise the voltage on the port pins, so unless some external circuit (like your LEDs) provides a source of current, you wouldn't be able to necessarily recognize any difference in the voltages of pins that had 1s written to them and the ones that had zeroes. Kind of like hooking a voltmeter across the two terminals of an SPST switch and not noticing much difference in readings taken when the switch is "on" vs. when it's "off".
mem.namefix wrote:
I rewired my bread board as per your instructions (but using same code atm) and tested, all leds come on @ normal brightness now. Would I be correct in assuming that all LEDS are bright due to the Ports being still open (sinking volts) ?.
Uh, "open" and "sinking" have somewhat contradictory meaning to electronics types. Your LEDs would be lit if the port pins were sinking current, yes, but they're obviously not "open" (circuits) when they do that. Only the LEDs connected to PORT0 pins which are cleared to zero should light up, and PORT0 is initialized to "all bits set" as a part of the 8051's hardware reset. So unless your program wanted them on, none of them should be.
mem.namefix wrote:

Do you know how to write 1's to each individual pin in C ?, atm I am working of example code and it seems to me (atm anyway) that you can only toggle 1 pin at a time.
I've only ever programmed an 8051 in assembler, and that many years ago. I imagine that your compiler would treat the IO registers pretty much like the AVR's compilers do, and give you a symbolic reference to PORT0 that you can use in a C assignment statement as if it were a variable. You should be able to use a statement like
PORT0 = 0xff;

to turn off all your LEDs, or

PORT0 = 0;

to turn them all on.

Thankyou for your help, again sorry for posting to the wrong forums, Levenkay - if you have an account I have also started a similar thread in http://www.8051projects.net/plugins/forum/forum_viewtopic.php?12229.last which appears to be the correct spot for it.
Cheers.


I haven't an account there, so will post here one last time in answer to your questions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thankyou so much Levenkey, after a bit more fiddling I went back to basics as I understood alot more after your explanation.
Port 0 as you said grounds at state 0.
Wiring as you suggested, feeding v+ to led to a pin on port 0 works.
All leds light up with no code apart from a main loop.
adding P0 = 0x01 to the start, turned off LED 1.
P0 = 0x02 turned off LED 2 and so on.
8bit number for 8 ports (crunched it back to binary to figure out controlling more than 1 LED).

My biggest mistake was attempting blinking, the blinks were indeed working (once I wired to your suggestion) but far to fast to tell.

Many thanks, expect to see me on these forums again once I buy some AVR chips :).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well as it's not related to AVRs but is generally about electronics that's where I'll move this one...