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

Mon Jun 12 2017, 07:36 PM
madhusoodanan
how to receive string using 8051
ajay_bhargav
Thu Jun 08 2017, 05:48 PM
@Vinoth post in forum.
Wed Jun 07 2017, 06:40 AM
vinothkannan
how interface eprom in this code
Thu May 25 2017, 05:25 AM
Monir Hossain
Can i change the 7-Segment are common pin ? And how to?
Mon May 08 2017, 12:45 PM
ivan muvunyi
please can you send me wiring diagram for automatic control of 3 phase induction motor for production of maize flour
Wed May 03 2017, 08:39 PM
imran qureshi
hello friend
Sun Apr 30 2017, 05:49 AM
Lijin G Varghese
Can u send me the circuit diagram for Program to interface GSM Module with 8051 microcontroller (AT89C51) using PC and LCD
Fri Apr 28 2017, 03:47 PM
SANDEEP T S
I need pcb wizard 3.5 version kindly send valid link of yours
ExperimenterUK
Mon Apr 17 2017, 11:56 PM
Sorry..We had a problem with registration.Confirmation emails were not sent.Please re-register
Thu Apr 13 2017, 07:29 PM
Piyush Aughad
I want circuit & program for radar detection using Microcontroller 8051

Downloads

Comments

richard1976
Sat Jun 24 2017, 05:48 PM
DruvaN
Wed Jun 21 2017, 11:44 AM
lalala
Tue Jun 20 2017, 11:05 PM
Siddh@
Tue Jun 20 2017, 07:47 AM
firdaus0hsem
Sat Jun 17 2017, 04:53 PM
amir9297
Fri Jun 16 2017, 05:44 AM
madhusoodhanan
Mon Jun 12 2017, 07:31 PM
Aminookano
Sun Jun 11 2017, 05:50 AM

Online

Guests: 52, Members: 0 ...

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

Members: 37847
Newest member: richard1976
Forum Activity
richard1976 Avatar
Posted By richard1976
Sat Jun 24 2017, 08:47 PM
Hi can you tell me how to send and recieve usart d...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jun 24 2017, 08:24 PM
HiUnfortunately there is too much code here to wor...
richard1976 Avatar
Posted By richard1976
Sat Jun 24 2017, 06:01 PM
hi i have written this programme and can send data...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jun 23 2017, 08:19 PM
>Should I need to check PWR_VLD bits every time on...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jun 23 2017, 07:42 PM
I would say yes, but data transfer will be slower ...
Utsavi Avatar
Posted By Utsavi
Thu Jun 22 2017, 12:14 PM
Hello ExperimenterUK, Thanks for your support. Fro...
DruvaN Avatar
Posted By DruvaN
Wed Jun 21 2017, 11:51 AM
Is it possible to Use 8051 bit-banging method to p...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jun 20 2017, 06:27 PM
You could start by looking at this tutorial on ke...
firdaus0hsem Avatar
Posted By firdaus0hsem
Sat Jun 17 2017, 04:58 PM
I have an issue regarding how to use 4x3 keypad to...
amir9297 Avatar
Posted By amir9297
Fri Jun 16 2017, 05:47 AM