Discussion in "Project Help" started by    mem    Aug 30, 2008.
Sat Aug 30 2008, 09:56 pm
#1
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.
After reading through some threads on here I found out how to simulate in keil and my ports are working correctly it seems.

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 */ 
			}
		}
	}
}




Attachment


[ Edited Sun Aug 31 2008, 02:39 am ]
Sat Aug 30 2008, 10:30 pm
#2
Hello mem,

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.


you are fooling yourself by calling AT89C51 an AVR, the micro which you are using /trying belongs to Intel's LEGENDARY 8051 Family. 8051 is the forefather of today's micros.

the program loads 8bit values on to the Port 0 and by seeing the values in your code, an LED shifts from P0.0 to P0.7 with delay in between.




Arun
Sun Aug 31 2008, 01:42 am
#3
hi mem, welcome to website
AVR and 8051 are two different architectures. AVR is one if the most advanced 8-bit microcontroller architecture in market today. whereas as arun said, 8051 is a very old architecture developed by Intel.

AT89C51 is also 8051 based controller made by Atmel (Company Name). AVRs are developed by Atmel so they are usually called by name atmel controller.

AT89C51 - Atmel's 8051
AT90S8515 - Atmel's AVR
the word AT is for vendor company name only so do not confuse yourself next time when you see AT in front

If you want more info on any controller, just download its datasheet. You will get all the info.

If you still have doubt about anything, Please ask freely
 mem like this.
Sun Aug 31 2008, 02:17 am
#4
Your Wait() function is empty.

In that case each led will be on for a very short period,
*far* less than 0.5 seconds.
What you see is mainly a flicker effect.

Put some time wasting loops into Wait(), to give a useful delay.


Can the AT89C51 source current on port 0 ?


[ Edited Sun Aug 31 2008, 03:46 am ]
 mem like this.
Sun Aug 31 2008, 02:42 am
#5
ExperimenterUK, wait() is executed 10,000 times. and wait itself will give small micro seconds delay with call and return statement. so this may provide enough delay with 10Mhz clock..
 mem like this.
Sun Aug 31 2008, 04:10 am
#6


ExperimenterUK, wait() is executed 10,000 times. and wait itself will give small micro seconds delay with call and return statement. so this may provide enough delay with 10Mhz clock..

Ajay



Well it's worth a try anyway

mem.. are you able to display a fixed pattern on the LEDs
such as half on and half off ?

Can you check that your lantern battery is not
putting out more than six volts.


[ Edited Sun Aug 31 2008, 04:13 am ]
 mem like this.
Sun Aug 31 2008, 08:37 am
#7
I noticed last night when using Keils simulator that it was indeed running very fast, I have thrown some maths in to slow the program down.

Yes I got confused when starting out, I thought all ATMEL chips were AVR's (silly me). Despite the mixup I am still having fun learning this architecture.

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

void wait (void)
{  /* wait function */ 
unsigned int i;
i=0;
i++;
i = i++ * i++ * i++;
} 

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 */ 
			}
		}
	}
}


Can you check that your lantern battery is not
putting out more than six volts.


The battery is putting out 6.49v according to my multimeter. which should be fine (I think so anyway) for as the maximum operating voltage is 6.6v.

Can the AT89C51 source current on port 0

Yes, that can be seen by the 1st three LED's lighting up dimly.

mem.. are you able to display a fixed pattern on the LEDs
such as half on and half off ?

I have tried the code being empty (ie no P0=0 and no sending values to P0) and it had the same result. I will modify the code to only turn on the 1st 4 LEDS and report back.

Thanks for the quick replies everyone, I really appreciate it. When I finish waking up I will update this thread with the formula I used for calculating the voltage drop needed for the LED's.
Sun Aug 31 2008, 09:59 am
#8
I originally started a similar thread on avrfreaks (wrong spot I realize now) but one member did provide some good food for thought. So I have pasted his and my reply here to consolidate the information I have so far.

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.

"Levenkay"


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/forum-t12229-last.html which appears to be the correct spot for it.
Cheers.
Sun Aug 31 2008, 02:19 pm
#9
Quotes from thread @ avrfreaks


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 ?

"mem.namefix"

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

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) ?.

"mem.namefix"

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.


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.

"mem.namefix"

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/forum-t12229-last.html which appears to be the correct spot for it.
Cheers.

"Levenkay"


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

"Levenkay"




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 .

"mem.namefix"



So, it seems I have the basics working - I just need to figure out some delay code (which I shall search these forums for).

Thanks very much for the help from 8051projects forums, Im very glad to reach this stage .
Looking forward to learning more about the 8051 arch as I go along.
Sun Aug 31 2008, 05:39 pm
#10
hi mem,
looks like u are finally getting the basics of 8051 computing right. .
fine, here is a method to turn on/off the port pins individually without affecting the other pins of the same port;
say u want to turn ON the LED (clear the bit) at the port P0.4, then use the following instruction:
PORT0 & = ~(1<< 4);
to turn OFF the LED (set the bit), use the following:
PORT0 |= (1<<4);

just crunch the data back to binary and u will figure out that the other pins are indeed not affected.

u can also use the boolean expressions on the port bits to alter the state of the pin ( if the compiler supports the syntax of course!).

 mem like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am