Discussion in "Project Help" started by    mem    Aug 30, 2008.
Sun Aug 31 2008, 07:12 pm
#11


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);

pdi33


Thanks, I have been playing around some more and hit yet another wall, I thought your tip might help but it just replicates the same issue.
I can turn off LEDS 1&2 by setting P0 to 0x01 and 0x02 respectively.
Setting P0 to 0x04 which should turn off LED 3 instead causes all LEDS to blink rapidly. Same behavior on all my 4 chips (thought I may have blown one).

code below is using your example (all LEDS blinking rapidly):
#include < REGX51.H >
 
void main( void )
{
	P0 |= (1<<4);
	while(1)
	{
	}
}


My code that fails (all LEDS blinking rapidly):
#include < REGX51.H >
    
void main( void )
{
	P0 = 0x04;
	while(1)
	{
	}
}


My code that correctly turns off LED 1:
#include < REGX51.H >
    
void main( void )
{
	P0 = 0x01;
	while(1)
	{
	}
}

Sun Aug 31 2008, 11:47 pm
#12
hi mem,
do not worry bro, actually i think there is nothing wrong with ur code (both of them ) and will work just as good. the problem i think lies in ur hardware where u have to connect the EA/VPP to VCC for ur code to work properly. (u were plain lucky that the previous code did work!!!).
do that and give feedback. (Ur doubt certainly confused me for some time until i cross checked in detail ur ciruit in the previous post!!)
good luck :-)
In ur code:
P0 | = (1<<4);
u will have to add this statement before that :
P0 = 0x00 ;
to make it equivalent to ur other code because in the former case, the state of P0 will be 0xff (only in case of 89c51 and not guaranteed in case of 89s51!!).
 mem like this.
Mon Sep 01 2008, 07:27 am
#13

i think lies in ur hardware where u have to connect the EA/VPP to VCC for ur code to work properly. (u were plain lucky that the previous code did work!!!).
~snip~
In ur code:
P0 | = (1<<4);
u will have to add this statement before that :
P0 = 0x00 ;
to make it equivalent to ur other code because in the former case, the state of P0 will be 0xff (only in case of 89c51 and not guaranteed in case of 89s51!!).

pdi33



Thanks mate, I read through the pdf again after reading the info you provided and it does seem Im 1 wire short.

PDF EA/VPP Pin info:


I will update my circut (and diagram) and test once Im home today. Thanks very much for you help.

Updated Diagram:


[ Edited Mon Sep 01 2008, 08:11 am ]
Mon Sep 01 2008, 02:13 pm
#14
Thanks very much pdl33. That was indeed the issue and no doubt it would have taken me quite awhile to sort it out. Here is my final code that I used.

/*
Target chip: AT89C51
IDE: Keil (startup code)

This project is written in Keil by Jacob Jarick
[email protected]

Pattern Table:

HEX	DEC	0 1 2 3 4 5 6 7

0x03	2	1 1 0 0 0 0 0 0
0x06	6	0 1 1 0 0 0 0 0
0x0C	12	0 0 1 1 0 0 0 0
0x18	24	0 0 0 1 1 0 0 0
0x30	48	0 0 0 0 1 1 0 0
0x60	96	0 0 0 0 0 1 1 0
0xC0	64	0 0 0 0 0 0 1 1
0x81	65	1 0 0 0 0 0 0 1

*/

#include <REGX51.H>
#include <intrins.h>
	// provides _nop_

char const num[  ] = {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x81 }; 

void wait ()
{
	unsigned int c;
	for(c=0;c<50000;c++)
	{
		_nop_();
	}
}
	   
void main( void )
{
	unsigned char j;
	P0 = 0x00;
	while(1)
	{
		for(  j = 0; j < 8; j++  )
		{
			P0 = num[j];
			wait();
		}
	}
}


Now to have some fun making different patterns.


[ Edited Tue Sep 02 2008, 01:17 am ]
Mon Sep 01 2008, 11:54 pm
#15
good for u mem,
now i think u should explore the other features of 8051 as well like interrupts/timers etc. they always come in handy when u jump to some advanced application.
good luck
 mem like this.
Tue Sep 02 2008, 05:53 am
#16
Cheers , I think my next project will be to either: make port 1 control another 8 LED's or control existing 8 LED's via a PC serial/ parallel cable.
Would it be worth writing a how to for my LED chaser project ?, if so Id be more than happy to write one up for submission.
Tue Sep 02 2008, 08:35 am
#17
the second option looks better. check the UART communication tutorial (tutorial section) on this site. It has a very simple explaination about the serial communication .and if u have any doubts u know where to post them .

wish u all the best . :bye .
 mem like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Michailqfh
Fri Mar 29 2024, 01:53 am
Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm