Confusion and possible bug on 16f876


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    46


    Did you find this post helpful? Yes | No

    Default Question to Bruce

    "The simple fix is to setup all output port latches & TRIS registers in
    the initialization/startup section of your code."

    Bruce - are you saying to use TRIS to set the pins as outputs when the program starts?

    Eric

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


    Did you find this post helpful? Yes | No

    Default

    Absolutely.

    Example:

    DEFINE OSC 20

    MyVar VAR BYTE ' Define all variables, etc,,

    PORTB = %11110000 ' output logic at power-up
    TRISB = 0 ' all outputs

    Main: ' Main code starts here.

    The very first instructions that execute will be port latch setup (value
    to place on any output pin at power-up), followed by TRIS settings.
    Regards,

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

  3. #3
    Join Date
    Oct 2004
    Posts
    46


    Did you find this post helpful? Yes | No

    Default A Super Thanks

    Thanks Bruce et all for your help and insights into helping solve this issue. I've probably put a good 15 hours overall into wrestling with this issue.

    Many thanks again!
    Kind Regards,
    Eric

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


    Did you find this post helpful? Yes | No

    Default

    I'd always set TRIS before I do any Port I/O... so in Bruces example I'd initialise my PIC...

    TRISB = 0 ' all outputs
    PORTB = %11110000 ' output logic at power-up

    in that sequence.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,

    I used to do it that way as well until reading the 16F mid-range ref
    manual.

    9.11 Initialization

    It is recommended that when initializing the port, the data latch
    (PORT register) should be initialized first, and then the data direction
    (TRIS register). This will eliminate a possible pin glitch, since the PORT
    data latch values power up in a random state.
    Regards,

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

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce.

    Yeah... I read that too and disregarded it... didn't seem logical to start any I/O operation before you decided what the pin is going to be first. I normally follow the TRIS immediately with my pin initial state value... the school of thought being that the 1uS or so that a pin 'might' be in the wrong state at initialisation isn't going to do anything drastic. The most dangerous peripherals most folks could have are Relays, Contactors or SSR's - and they're just not going to react that fast. Further, there will be a number of clock cycles between physical Power-On and when the PIC actually wakes up and starts executing (kinda like me in the morning between the time the alarm clock goes off and my first cup of coffee!) and executes your first I/O Instruction and TRIS... now that is an indeterminate time anyway which is beyond our control during which the I/O pin will be high impedance - whatever you've got connected to that pin, and depending on the circuit, could float either way anyhow, so what's another uS between friends?

Members who have read this thread : 0

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