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

sahar7478
Fri Dec 08 2017, 12:47 PM
can i get gsm a6 library? can anybody help? tia
Faiqa
Sat Nov 25 2017, 08:32 AM
Can i get the code of Monitering and controlling of green house effect? ... Can anyone help me ?
Wed Nov 08 2017, 01:35 PM
Anirudh jain
I want to burn code in atmel 89s51 24pc 0329 but cannot get the connection with the burner. Can somebody provide me with the circuit diagram for connecting controller to burner. I'm using usb burner
Thu Nov 02 2017, 11:44 AM
karpal
write a program to exchange the content of b register with external RAM address 02CFH help me
Wed Nov 01 2017, 05:47 PM
sanae
i am using the DHT11 but i'm getting some errors in the simulate the programe in proteus 8 professional,: 1)cannot find model file 'DHTXX.MDF'.2)simulation failed due to netlist linker error(s).
Fri Sep 29 2017, 02:45 AM
Maaz
i am doing the same project on verilog please contact me [email protected]
Wed Sep 20 2017, 12:36 AM
Ted
In a missing pulse detector using a 555 timer connected as a monostable vibrator with a PNP transistor,how does the positve input pulse turn on the PNP transistor?
Sun Sep 03 2017, 02:29 PM
martymarty
How do I connect an <NOKIA 1100 LCD > to an atmega328P ?
poojab51296
Sun Aug 20 2017, 10:23 AM
i am intending to interface sd card with STM32F4 and want to write a file in sd card using SPI protocol but using HAL only. Can anyone help me PLEASE!!!!
poojab51296
Sun Aug 20 2017, 10:22 AM
hello

Downloads

Comments

roopay
Wed Dec 13 2017, 07:11 AM
janvimandeep
Mon Dec 11 2017, 01:05 PM
fernanmonroy2
Mon Dec 11 2017, 08:33 AM
sahar7478
Fri Dec 08 2017, 12:34 PM
zhudao
Tue Dec 05 2017, 06:14 AM
chetan6379
Sat Dec 02 2017, 03:42 PM
HaloSpartanOdst
Fri Dec 01 2017, 12:05 PM
workzone
Sat Nov 25 2017, 01:13 PM

Online

Guests: 61, Members: 0 ...

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

Members: 37928
Newest member: roopay
Forum Activity
fernanmonroy2 Avatar
Posted By fernanmonroy2
Mon Dec 11 2017, 08:40 AM
Que significa que el contador de programa abordar...
zhudao Avatar
Posted By zhudao
Wed Dec 06 2017, 03:08 AM
I think either your 120 - 5 volt adapter, or the L...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Dec 05 2017, 08:12 PM
I think either your 120 - 5 volt adapter, or the L...
zhudao Avatar
Posted By zhudao
Tue Dec 05 2017, 06:41 AM
Hi to all, in the period time I'm doing an project...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 20 2017, 10:18 PM
Here is a version of the tutorial that reads a key...
Ansh12 Avatar
Posted By Ansh12
Mon Nov 20 2017, 02:15 AM
As a starting point, can you tell us how much of t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Nov 19 2017, 08:35 PM
As a starting point, can you tell us how much of t...
Ansh12 Avatar
Posted By Ansh12
Fri Nov 17 2017, 04:07 AM
I am looking keypad interfacing program. I was rea...
JardCrocker Avatar
Posted By JardCrocker
Wed Nov 08 2017, 05:29 PM
Hi...i am a new user here. I was also facing the s...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 07 2017, 07:13 PM
> It employs a fairly advanced technique to detect...