Discussion in "Project Help" started by    mem    Aug 30, 2008.
Sun Aug 31 2008, 01:42 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, 06:17 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, 01:57 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, 02:41 AM ]
Mon Sep 01 2008, 08:43 AM
#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 Mon Sep 01 2008, 07:47 PM ]
Mon Sep 01 2008, 06:24 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, 12:23 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, 03:05 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

Conversation

ExperimenterUK
Sat Mar 25 2017, 09:56 PM
@Noreen I suggest you log in and post a full description of what you need in our PIC forum
Sat Mar 25 2017, 03:10 PM
Noreen
Hello I worked on a project related to Wireless Electricity theft detection using GSM during my bachelors. I used Nokia 6230 for sending sms using AT commands. I chose to work with SMS text mode. The microcontroller I used was PIC16F877A and its software coding done through PIC Basic Pro. Unfortunately, I lost my account password and do not have coding for generation sms using AT commands. I need that coding. Can some one help me to provide complete Pic Basic Pro code. In which step by step guidance is given so that I can understand easily. Regards,
Wed Mar 22 2017, 09:13 PM
ajay kumar
help me nokia lcd light
Wed Feb 22 2017, 06:14 AM
ChollyMo
Indeed, on the LCD tutorial, many missing Tables and figures !!
Wed Feb 22 2017, 06:06 AM
ChollyMo
I don't see any Table 3. I'm using Chrome.
Fri Feb 03 2017, 05:56 AM
irfan shaikh
hi, i want interface WS2811 pixel led using NUVOTON N79E352, but i dont know how to code it. can anyone help me or provide me sample coding for interfacing WS2811 PIXEL LED. THNX
Thu Jan 19 2017, 08:42 PM
abhays
Hi...i have made a circuit for interfacing PT100 with LM358 whose temperature is shown on the LCD...But the temperature is not getting incresed slowly ..a small change directly increses the temp...can any one help me
Thu Jan 19 2017, 04:27 PM
roba
send me alarm clock simulation using proteus software
Mon Jan 16 2017, 03:15 PM
Rutuja
How can we read notepad file using random acess file
Fri Jan 06 2017, 06:18 AM
muhammad Umar
i need cd4047 library file for protious please help me i s

Downloads

Comments

SAUnwin
Tue Mar 21 2017, 02:29 PM
letonarolikah
Mon Mar 20 2017, 11:21 AM
nerodear
Tue Mar 14 2017, 07:08 AM
XuZiling
Wed Feb 22 2017, 02:40 AM
diwakar_96
Thu Feb 16 2017, 02:40 PM
Helia
Thu Feb 09 2017, 09:59 AM
fasihaftab
Sat Jan 28 2017, 08:58 AM
jmunjr
Tue Jan 17 2017, 06:25 PM

Online

Guests: 62, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37804
Newest member: SAUnwin
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 25 2017, 09:49 PM
I have attached code showing one method you could ...
Deepakvaishu Avatar
Posted By Deepakvaishu
Sat Mar 25 2017, 07:59 AM
I am using Keil and 8051 microcontroller
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Mar 24 2017, 06:05 PM
The best way is to use an interrupt to run the cou...
Deepakvaishu Avatar
Posted By Deepakvaishu
Fri Mar 24 2017, 05:22 AM
Hi,I got that we should use timer......But I am a ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Mar 23 2017, 09:14 PM
You have largely answered your own question.Use on...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Mar 23 2017, 07:03 AM
I have looked at your code.I think you are confuse...
Deepakvaishu Avatar
Posted By Deepakvaishu
Thu Mar 23 2017, 05:34 AM
hello,I can type the letters now when the particul...
SAUnwin Avatar
Posted By SAUnwin
Tue Mar 21 2017, 02:55 PM
HI,There are two ways I'd tackle thiss.Key down on...
Deepakvaishu Avatar
Posted By Deepakvaishu
Mon Mar 20 2017, 08:24 AM
hello,I am using a keypad to type the text message...
Helia Avatar
Posted By Helia
Thu Mar 16 2017, 09:15 AM
hi.. the following code is not working on hardware...