Page 1 of 1

PullUp/ PullDown Resistors

Posted: Thu Jun 23, 2022 11:42 pm
by Derrihj
Hi everyone hope u are OK, my question today is how do we enable internal pull-up resistors and pull-down resistors in a pic microcontroller like the PIC18F442 ?

Re: PullUp/ PullDown Resistors

Posted: Fri Jun 24, 2022 9:39 am
by Steve
According to the datasheet for that device, only PORTB has an option for internal pull-ups. You have to add some C code in a C icon at the beginning of your program to enable them. Hopefully this will work:

Code: Select all

INTCON2bits.nRBPU = 0;

Re: PullUp/ PullDown Resistors

Posted: Fri Jun 24, 2022 12:33 pm
by Derrihj
Thanks Steve, but 0 = PORTB pull-ups are enabled by individual port latch values. How do we write it if I want to enable pull_up resistor only for like port B2 ?

Re: PullUp/ PullDown Resistors

Posted: Fri Jun 24, 2022 1:12 pm
by Steve
I don't think you can as there is a single setting for all of PORTB. This is from the datasheet:
Each of the PORTB pins has a weak internal pull-up. A single control bit can turn on all the pull-ups. This is performed by clearing bit RBPU (INTCON2<7>). The weak pull-up is automatically turned off when the port pin is configured as an output. The pull-ups are disabled on a Power-on Reset.
If you need a pull-up (or pull-down) on an individual pin, then you'll have to chose a chip which has that functionality, or alternatively use an external resistor.