1
\$\begingroup\$

I am creating a simple pic project that uses a PIC16F877A and I have noticed something that seems odd. Before using any code to change the state of the pins connected to port b, the port b pins are already high. Here is the code I am using in hi tech c with everything else removed to demonstrate the problem. I was wondering if it was normal for the pins to start high before being set in that state. If that is the case I could just set PORTB to 0 at first to solve the problem, I just wanted to make sure that nothing was wrong. This seems to be caused by the line TRISB = 0xFF but I can't understand why since that register only adjusts weather the pin is a input. If anyone requests it I can post my circuit diagram, however I was hoping to avoid having to draw schematic.

#include<htc.h>
#define _XTAL_FREQ 8000000
__CONFIG(UNPROTECT & PWRTDIS & WDTDIS & HS & LVPDIS); 

int main()
{
    TRISB = 0X00;

    while(1)
    {

    }
}
\$\endgroup\$
0
\$\begingroup\$

On reset, all port pins are configured as inputs. If they float high, and then you configure them as outputs, they will be driving high. So it's best to set all pins to their default state before writing to the TRIS registers to set them as outputs.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

PORTB is set to an unknown value on power-up. Hitech C does not do anything to change that at start-up.

enter image description here

The weak pullups on PORTB are disabled at power-up by default.

enter image description here

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.