Input problems with PortD on Pic16F874A


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2006
    Location
    Kalmar in sweden
    Posts
    5

    Angry Input problems with PortD on Pic16F874A

    Hi,
    I have some serious problems, I need to use PortD.0 to PortD.3 for digital I/O.
    It just wont work,!!!
    I have read that:
    “PortD is also the PARALLEL SLAVE PORT. To make it a general purpose I/O port, Bit4 of TRISE must be set to 0 IE TRISE.4 = 0”

    So I tried:
    TRISE.4=0

    And to be on the safe side I also tried:
    ADCON1 = 7
    CMCON=7
    TRISD = %11111111

    And it still doesn’t work, does anyone have an idea?



    / Petter

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    What are you trying to do that doesn't work? It's hard to tell with just
    TRISD = %11111111.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Aug 2006
    Location
    Kalmar in sweden
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Input problems with PortD on Pic16F874A

    Hi Bruce.
    I am trying to use PortD.0 to PortD.3 as digital input.

    “IF PortD.0 = 1 THEN…”
    and it doesn’t work.


    / Petter

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    IF PortD.0 = 1 THEN
    Are you holding the pin at ground with a pull-down resistor until a button is
    pressed taking the input high?

    I don't have a 16F874A, but I do use the 16F876A with PORTD inputs, and
    it works as expected.

    It might help is you showed all your code & a schematic.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Aug 2006
    Location
    Kalmar in sweden
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Input problems with PortD on Pic16F874A

    Hi again.

    Yes, I am using pull-down resistor on all my inputs.
    I will try to find some free time tomorrow to post my code & schematic.

    / Petter

  6. #6
    Join Date
    Aug 2006
    Location
    Kalmar in sweden
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Hi
    This is my testcode & schematic:

    '---------------------------------
    Include "modedefs.bas"
    @ DEVICE HS_OSC
    DEFINE OSC 20
    ADCON1 = 7
    CMCON=7
    TRISE.4=0
    LED VAR PORTB.5

    boot:
    Pause 500
    Low led
    high porta.0

    LOOP:
    if portc.2 = 1 then high ut10
    if portc.3 = 1 then high ut10
    if portd.0 = 1 then high ut10
    if portd.1 = 1 then high ut10

    if portc.5 = 1 then high ut10
    if portc.4 = 1 then high ut10
    if portd.3 = 1 then high ut10
    if portd.2 = 1 then high ut10

    pause 1
    low ut10
    goto loop
    '---------------------------------




    link to my schematics:
    http://www.mediespecialist.se/pic16f874a/874a.gif
    and a picture:
    http://www.mediespecialist.se/pic16f874a/IMG_2144.JPG

    / Petter

  7. #7
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Petter,

    Where are your port settings for Port C & D in the initalization of your PIC?

    TRISD = %00000000 'for outputs
    TRISD = %11111111 'for inputs
    PortD = 0' set port D to low

    Same settings needed for portC.

    Maybe that's why it's not working. You haven't told the PIC HOW you want to use the pins. This is a similar chip to the 877A. I had no problems using it with only setting the TRISD,C, & D and PORTB,C, & D to what I wanted them to do.

    I did see you had tried TRISD = %11111111 in a previous posting but not on the current one.

    Also how can you see UT10 change states when you only pause for 1us? Try at least PAUSE 1000 until to get some testing results then fine tune it.

    Also since this is an "A" type device do you have .1uF caps across both Vcc & Vdd pins on both sides of the chip as close to the pins as possible? The A series micros are supposedly more sensitive to noise. I couldn't see any because of the crystal being in the way.

    Hope some of this helps!

    BobK

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    another thing...
    Code:
    @ DEVICE HS_OSC
    is invalid. look at the faq there's a whole thread about config fuses setting.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Aug 2006
    Location
    Kalmar in sweden
    Posts
    5


    Did you find this post helpful? Yes | No

    Smile

    Hi again, and thanks a million for all the help.
    Nothing worked!
    So I gave up and tried from scratch with a new .bas file, and then…
    EUREKA!

    Here is my test code that worked:

    '-------------------------------------------------
    'från början

    @ DEVICE HS_OSC
    DEFINE OSC 20
    ADCON1 = 7
    LED VAR PORTB.5
    UT1 var PORTB.4
    UT2 var PORTB.2
    UT3 var PORTB.1
    UT4 var PORTB.0
    UT5 var PORTD.7
    UT6 var PORTD.6
    UT7 var PORTD.5
    UT8 var PORTD.4
    UT9 var PORTC.7
    UT10 var PORTC.6
    IN1 var PORTC.2
    IN2 var PORTC.3
    IN3 var PORTD.1
    IN4 var PORTD.0
    IN5 var PORTC.5
    IN6 var PORTC.4
    IN7 var PORTD.3
    IN8 var PORTD.2

    BOOT:
    PAUSE 500
    LOW led

    LOOP:
    IF IN1 = 1 THEN high UT1
    IF IN2 = 1 THEN high UT2
    IF IN3 = 1 THEN high UT3
    IF IN4 = 1 THEN high UT4
    IF IN5 = 1 THEN high UT5
    IF IN6 = 1 THEN high UT6
    IF IN7 = 1 THEN high UT7
    IF IN8 = 1 THEN high UT8
    pause 1
    LOW UT1:LOW UT2:LOW UT3:LOW UT4:LOW UT5:LOW UT6:LOW UT7:LOW UT8:LOW UT9:LOW UT10
    goto loop
    '-------------------------------------------------

    Sometimes the world is a bit strange, but for the moment I am happy :-)

    Thanks again for all your help.


    / Petter

Similar Threads

  1. Input problems with 12F629?
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 24th April 2018, 06:25
  2. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  3. Input problems
    By ALFRED in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd July 2006, 21:02
  4. Problems with PORTD on 18F658
    By blainecf in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th June 2006, 17:32
  5. 18F6680 and portd problems.
    By jkbh in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 6th June 2005, 10:54

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts