1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Sorry, a bsasic query here: How to Setting up P1.0 as Input Pin to read a high input

Discussion in 'Project Doubts' started by rahulpsharma, Oct 23, 2012.

  1. rahulpsharma

    rahulpsharma New Member

    Likes Received:
    0
    Trophy Points:
    0
    Hello, I was looking for a thread where newbies in 8051 can ask 'silly' questions... But couldnt find one... So am posting my silly query here...!!

    Am trying to learn 8051 by reading a book and simultaneously writing practice codes on a dev board. Am using 89V51RD2 development board... Flash Magic to prorgram and Keil uVisioin to write the basic assembly code... Have tested the basic functionalties of all these by turning on and off LEDs ... So there's no problem with the set up, as such...

    Now my Query:
    The book I am reading says that to configure any port to read an external Input, I need to first write FF to the Port (mov px, #0ffh)... Also, to configure any Pin as Input Pin I need to first 'set' it to 1 (setb px.y)...

    So I decided to write a little more complex program:
    Idea is that If P1.0 is goes 'High', a LED connected to P1.1 blinks once:

    I connected, as shown in the book, P1.0 to Ground, via a 4.7K resistor... Connected a Normally Open switch between +5V and P1.0... So that whenever, the switch is presesed, P1.0 goes high else it remains pulled to the ground....!!

    And wrote the following Code : Rather copied it from the example given in the book:

    here: setb P1.0
    jnb, P1.0, $
    setb 1.1
    call delay
    clr p1.1
    sjmp here:

    delay: ---------
    ret
    end


    Now when I download the program in the controller, I observe the following:
    P1.0 always remains High even when pulled to the Ground via 4.7K.... So my switch doesnt seem to have any effect and the LED connected to P1.1 stays on...

    What is it that I am missing here... And if I have to set P1.0 to make it work as an input pin, then how will it read a High Input Condition created by an external switch, cos it's already set High by the software...!! Any help will be appreciated...
    Tags:
  2. Binu

    Binu Administrator

    Likes Received:
    138
    Trophy Points:
    63
    Place some delay routines and wait for the pin to go low before you jump to the first line

    here: setb P1.0
    jnb, P1.0, $
    setb 1.1
    call delay
    clr p1.1
    jb p1.0,$ 'wait until you release the button
    sjmp here:

    delay: ---------
    ret
    end
  3. rahulpsharma

    rahulpsharma New Member

    Likes Received:
    0
    Trophy Points:
    0
    Thanks for your quick reply...

    But the problem is that P1.0 by default is 1 (4.9VDC)... Whether I press the switch or not... When I power up, the pin goes to High EVEN THOUGH it is pulled down to Ground using a 4.7K resistor (4.7K placed betweel P1.0 & Ground)... Now why should that be...?? If it goes High on power up, then what is the point in pulling it down with a 4.7K resistor...??

    The Normally Open switch is placed between P1.0 and +5VDC source... So when I depress the swtich, P1.0 continues to read 5V (High) and when I release the switch, the voltage at P1.0 is still High... So in all conditions its High...!!

    I am sorry, I know I am making some quite silly error.... But pls help me out of this...

    And yes, my delay routine is about 500mS... Ofcourse, I post the code here...!! But its there....

    Rgds
  4. rahulpsharma

    rahulpsharma New Member

    Likes Received:
    0
    Trophy Points:
    0
    I just checked the schematic of Devlopment Kit again... Seems all the ports are pulled up to 5VDC with a 4.7K resistor Bank... Hence, when I am trying to pull P1.0 down by a 4.7K resistor on my breadboard, it shows a voltage of 2.5VDC...

    Could that be a reason for the code not working...!! What can I now do to ensure that P1.0 is pulled down to 0 to begin with....!! I cant desolder the 4.7K pull up bank from the Development board, without damaging it... Can I try something else...??
  5. Binu

    Binu Administrator

    Likes Received:
    138
    Trophy Points:
    63
    You dont need any resistor for pull down. Since its already pulled uped. Just connect the switch to the port pin and ground.
  6. rahulpsharma

    rahulpsharma New Member

    Likes Received:
    0
    Trophy Points:
    0
    :).. Thanks... Worked...!!! I was worried, if directly shorting P1.0 to ground might damage it....!! But tried and the code worked as expected...!! Thanks, again... Will keep coming back with some more silly questions, since I am just begining to learn 8051... But will give my own tries as much as I can, before posting...!! :)..

Share This Page

Loading...