Output of uC not changing!!!

Discussion in 'Embedded Systems and Microcontrollers' started by elex09, Apr 16, 2010.

  1. elex09

    Thread Starter Member

    Mar 17, 2010
    39
    0
    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?

    Code ( (Unknown Language)):
    1.  
    2. Program to monitor status of Infrared Receiver according
    3. ;to occupancy in classroom and switch ON/OFF supply
    4.  
    5. org 0000h            ;
    6.  
    7. mov P2,#00h        ;clear the other pins other than i/p pins
    8.  
    9. mov P2,#0Fh        ;make P2.0 to P2.3 input port
    10.  
    11. ;if the IR beam is not blocked i.e. nobody is present in
    12. ;class so relay is OFF,o/p is low
    13.  
    14. ;if the IR beam is blocked i.e.
    15. ;someone present so relay must energize,o/p is high
    16.  
    17. back:mov A,P2       ;copy input in ACC
    18. JNZ relay1             ;if ACC is 1,somebody is present in class so relay must switch ON supply
    19. acall delay             ;
    20.  
    21. ;Using Timer 0 in mode 1 for 10 sec delay
    22.  
    23. delay: mov tmod,#01h  ;use timer0 in mode1
    24. mov R0,#1680             ;
    25.  
    26. back2: mov th0,#00h    ;load the delay in high byte of timer reg
    27. mov tl0,#00h               ;load the delay in lower byte of timer reg
    28. setb tr0                      ;start the timer0
    29. back1: jnb tf0,back1     ;till time has elapsed stay here
    30. clr tf0                         ;
    31. clr tr0                         ;
    32. djnz R0,back2               ;
    33.  
    34. ;Now using timer 1 in mode 1 for another 10 sec delay
    35.  
    36. mov tmod,#10h            ;use timer1 in mode1
    37. mov R1,#1680              ;
    38.  
    39. back3: mov th1,#00h     ;load the delay in high byte of timer reg
    40. mov tl1,#00h                ;load the delay in lower byte of timer reg
    41. setb tr1                       ;start the timer0
    42. back4: jnb tf1,back4      ;till time has elapsed stay here
    43. clr tf1                          ;
    44. clr tr1                          ;
    45. djnz R1,back3                ; do nothing if nobody present
    46.  
    47. sjmp back                     ;continue monitoring the status of the receiver
    48. RET                             ;
    49.  
    50. relay1: setb P1.6           ;give base drive to transistor to energize the relay
    51. sjmp back                     ;continue monitoring the status of the receiver
    52. end                             ;
    53.  
    54.  
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Can you post a schematic of your circuit as well?
     
  3. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    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.
     
  4. elex09

    Thread Starter Member

    Mar 17, 2010
    39
    0
    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?
     
  5. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    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?
     
  6. elex09

    Thread Starter Member

    Mar 17, 2010
    39
    0
    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?
     
  7. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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..
     
  8. elex09

    Thread Starter Member

    Mar 17, 2010
    39
    0
    ok thanks retched...
    hey can u tell me how i should attach my schematic here..its in .pdf form....
     
  9. elex09

    Thread Starter Member

    Mar 17, 2010
    39
    0
    this is my schematic....
     
  10. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    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?
     
  11. elex09

    Thread Starter Member

    Mar 17, 2010
    39
    0
    yup thats right..thats how i have connected them..
     
  12. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    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.
     
Loading...