PDA

View Full Version : programming problem



puneetverma24
10-16-2010, 06:17 PM
i program the mirocontroller(at89s52) to give output to some pin to perform task , & it works


but when i try to program in such way that is take input from one port , and give output in some other port it fails to work

thought my programming is logic correct , & compiler donot show any error
& my circuit connections are correct

but when i perform it practically , it does"t work

example of my code::

if(P1==0x01) // input
{
P2=0xff; //output

}



is i am missing something, any of conditional statement like this,does"t work for me.

asimov_18
10-16-2010, 07:24 PM
In 8051 port reading, one has to write 0xff to port before reading the pin logical value back from the port. Did u write 0xffh to the port. In assembly its done like

mov P1, 0ffh; this command makes the port high state so that logic values at the pinput pins are read subsequently
mov a, p1; this command reads actual port value


Asimov

allbits
10-17-2010, 12:27 AM
1) What have you connected to port 1? is it floating, or is any of the pins connected to anything?
2) Do you have an infinite loop at the end of the code?
3) Post the entire code.
4) What have you connected to P2?
5) It is not necessary to write an FF to read a port
6) Have you checked the voltage levels of the input port? Does it read 0x01?

puneetverma24
10-17-2010, 08:16 AM
here is my code
#include<REGX52.h>


void main()
{


while(1)
{
if(P1==0x01)
{
P2=0xff;
}



if(P1==0x00)
{
P2=0x00;
}

}

}



my circuit is simple
i directly given 5v to pin p1.0

and connected leds to port p2 (+ terminal to pins of p2 & -ve to gnd)


i only connect p1.0 to +5ve

is i have to give gnd to pin(p1.1 to p1.7) also ???

allbits
10-17-2010, 09:49 AM
Its not a good idea to leave anything floating.

And it is not a good idea either, to have a clue about something, and NOT trying it out. You could have tried connecting the other inputs to ground, and come back if it still doesnt work.
Did you check the voltage level at the input port?

puneetverma24
01-15-2011, 12:05 AM
here is my code
#include<REGX52.h>


void main()
{


while(1)
{
if(P1==0x01)
{
P2=0xff;
}



if(P1==0x00)
{
P2=0x00;
}

}

}



my circuit is simple
i directly given 5v to pin p1.0

and connected leds to port p2 (+ terminal to pins of p2 & -ve to gnd)


i only connect p1.0 to +5ve


hey i am unable to do this ,
in my circuit:: if i give 5v at p1.0 , then a led at p2.0 will have to glow otherwise not
but it does not working

asimov_18
01-15-2011, 12:29 AM
This is the asm listing of your file I see the error clearly(you should now point it out)
and thebn try the code modified in the end and see the results for yourself

;================================================= ==============;
; Disassembled Using DIS8051 - (C)1989 Data Sync Engineering ;
;================================================= ==============;
;
;
;
ORG 00003H
;
;
L0003: MOV A,P1
CJNE A,#001H,L000B
MOV P2,#0FFH
;
L000B: MOV A,P1
JNZ L0003
MOV P2,A
SJMP L0003
;
ORG 00000H
;
LJMP L0013
;
;
ORG 00013H
;
;
L0013: MOV R0,#07FH
CLR A
;
L0016: MOV @R0,A
DJNZ R0,L0016
MOV SP,#007H
LJMP L0003
;
;
; Unresolved Address Reference list
;
;
;
;
END

++++++++++++++++++++++++++++++++++++++++++++++++++ +++

#include<REGX52.h>


void main()
{

P1=0x01;
while(1)
{
if(P1^1==1)
{
P2=0xff;
}
else
{
P2=0x00;
}

}

}



Asimov

puneetverma24
01-15-2011, 04:43 PM
hey what the use of declaring P1=0x01 before while loop

asimov_18
01-15-2011, 05:55 PM
I am not here to spoon feed(don't get me wrong!!!) try commenting it and see what happens; keil has an inbuilt simulator with which you can simulate the scenario. Probably then you will understand my post in the thread(look at all my post in this thread)

Asimov