1
\$\begingroup\$

I'm having problem with inputs of my PIC.

There is somethink like "default value" on all inputs set to logical 1 so if I want to change the state I need to pass GND.

How can I turn it "otherwise"? This is begining of my code:

#include <htc.h>
#include <pic.h>
#include <pic16f627a.h>

__CONFIG(WDTE_OFF & PWRTE_OFF & FOSC_INTOSCCLK & MCLRE_OFF & BOREN_OFF & LVP_OFF & CPD_OFF & CP_OFF);

int main (void)
{
    unsigned int i, j;

    unsigned short count = 0;

    TRISA = 0;
    TRISB = 0b11110000;
    PORTA = 0;
    PORTB = 0;
    nRBPU = 0;
    CMCONbits.CM = 7;
    ...

I don't understand electronics very much and I'm also kind of new to programming in C.

Thank you for any help.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ What you are talking about is a pullup resistor. And I am pretty sure that the PIC doesn't have a pulldown. That means, you are only able to make the default value logic 1. Unless you use an external pulldown resistor. en.wikipedia.org/wiki/Pull-up_resistor \$\endgroup\$ – Dzarda Nov 6 '13 at 23:57
  • \$\begingroup\$ Oh my god, I feel so stupid now. Thank you so much. Could you please send this as an aswer so I can accept it? \$\endgroup\$ – grongor Nov 7 '13 at 10:16
  • \$\begingroup\$ By the way, if I would like to use internal pull-up resistors, is there any way of "inverting" inputs so I still can use "positive logic"? Now I used "if (!RB0) { ... }" which was trigged when RB0 button was pushed. I would like to not have to use negation in every condition. \$\endgroup\$ – grongor Nov 7 '13 at 10:29
1
\$\begingroup\$

This phenomenon is known as a pullup resistor. As seen on the wikipedia page, it is widely used in conjunction with a physical switch. When pressed, the switch "pulls" the input low, overcoming the resistor's high impedance.

Also, on some MCUs there is an option to invert the pin's function. For example, on the AVR XMega, you can configure it so that both input and output will be inverted. I am not sure whether this specific PIC supports such feature. You'll have to dig through the datasheet.

\$\endgroup\$
1
  • \$\begingroup\$ is there another way to inverse pins other than by configuring procesor? Like redefining variables or something like that? I'm not skilled in C so much ... \$\endgroup\$ – grongor Nov 7 '13 at 17:06

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.