Output of uC not changing!!!

Thread Starter

elex09

Joined Mar 17, 2010
39
I am giving the output of IR rxers to P2.0 to P2.3 of the uC 89C51..and programming the output from P1.6 to 0 or 1 according to state of IR rxers o/p...this i am giving to a 1k resistor and then to BC547 transistor...and to 12v spdt relay...
all the voltage levels on the i/p pins of uC are accurately varying according to IR beam being detected or broken but the output from P1.6 stays constant at 0.65 volts...don't know why.. and the drop across the 1k resistor is 0v...
can someone pls help?

Rich (BB code):
Program to monitor status of Infrared Receiver according 
;to occupancy in classroom and switch ON/OFF supply
 
org 0000h            ;
 
mov P2,#00h        ;clear the other pins other than i/p pins 
 
mov P2,#0Fh        ;make P2.0 to P2.3 input port
 
;if the IR beam is not blocked i.e. nobody is present in 
;class so relay is OFF,o/p is low
 
;if the IR beam is blocked i.e. 
;someone present so relay must energize,o/p is high
 
back:mov A,P2       ;copy input in ACC
JNZ relay1             ;if ACC is 1,somebody is present in class so relay must switch ON supply
acall delay             ;
 
;Using Timer 0 in mode 1 for 10 sec delay
 
delay: mov tmod,#01h  ;use timer0 in mode1
mov R0,#1680             ;
 
back2: mov th0,#00h    ;load the delay in high byte of timer reg
mov tl0,#00h               ;load the delay in lower byte of timer reg
setb tr0                      ;start the timer0
back1: jnb tf0,back1     ;till time has elapsed stay here
clr tf0                         ;
clr tr0                         ;
djnz R0,back2               ;
 
;Now using timer 1 in mode 1 for another 10 sec delay
 
mov tmod,#10h            ;use timer1 in mode1
mov R1,#1680              ;
  
back3: mov th1,#00h     ;load the delay in high byte of timer reg
mov tl1,#00h                ;load the delay in lower byte of timer reg
setb tr1                       ;start the timer0
back4: jnb tf1,back4      ;till time has elapsed stay here
clr tf1                          ;
clr tr1                          ;
djnz R1,back3                ; do nothing if nobody present
 
sjmp back                     ;continue monitoring the status of the receiver
RET                             ;
 
relay1: setb P1.6           ;give base drive to transistor to energize the relay
sjmp back                     ;continue monitoring the status of the receiver
end                             ;
 

rjenkins

Joined Nov 6, 2005
1,013
Firstly, I'm not familiar with that chip so this not absolute...

You are using P2 as inputs and later P1 bits for output, but I don't see anywhere you may be setting the data direction on the ports?

I think you may need to check how you are setting pins as input or output.
 

Thread Starter

elex09

Joined Mar 17, 2010
39
i am initializing the port pins from P2.0 to P2.3 as input pins...by " mov P2,#0Fh;"
and actually there isn't any need to initialize an output port, because i think by default all ports are configured as output...so actually there is no need of " mov P1,#00h; "

i just need to know where the problem lies in the code...cause i have already simulated it in keil, (by giving an input thro' s/w itself).....and does this have to be written in an interrupt, or would this do?
 

rjenkins

Joined Nov 6, 2005
1,013
Again, read the datasheet - surely P2 cannot be both the data port itself and the data direction control register for P2 - those should be two different addresses?
 

Thread Starter

elex09

Joined Mar 17, 2010
39
i didnt understand what u meant by "2 different addresses"..

also when i ran the project i realized the problem was that P1 port pins were not getting set..but when i tried it with P2 (the upper part:p2.4 to P2.7) the bits got set..
so port 1 isnt working?
 

retched

Joined Dec 5, 2009
5,207
try to write a simple led lighting code to test the function of the pins.

Try with P1 as an input, using a button to light an led on P2 (which will be set as output)

then reverse it and try again. (button on p2 as input and led on P1 as output)

You may have dropped the PIC or electrostaticly shocked the pin.. or it may be faulty..
 

rjenkins

Joined Nov 6, 2005
1,013
OK, I've found the datasheet and had a look how port direction works on that chip.

The outputs are all open collector with internal pullups, so writing '1's to the port allows the pins to act as inputs. I've not seen one like that before; your output setup in your program is OK, it's me confusing myself..

I'm not quite clear on the wiring between the 339 and the inputs?

The LM339 output pins should go direct to the MPU inputs, and the 10K resistors should connect between +5V and the input connections.

Is that how you have them?
 

rjenkins

Joined Nov 6, 2005
1,013
I don't know enough about that MPU to understand the timers, but that is one area I'd look at, the code may be stuck in a loop waiting for a timer that is not running.
Is there any setup for timer enable or count mode, or do they just run forever?

Another point is that I can't see anywhere you turn the relay off if the timer expires.
 
Top