Page 1 of 1

how to enable internal pull ups?

Posted: 21 Jan 2010 00:17
by brkovich
PIC 16F883 I wish to use has weak pull ups on port B? What I don't know if where and how do you enable them?
Do you do that in code or do you set some flags in picflash?

Posted: 21 Jan 2010 11:24
by brkovich
It seems that bit RBPU in OPTION register set to 0 enables pull ups on portb.
But code OPTION_REG.RBPU:=0; isn't accepted in compiler.

Posted: 21 Jan 2010 11:38
by anikolic
http://ww1.microchip.com/downloads/en/D ... df#page=49
3.4.2 WEAK PULL-UPS
Each of the PORTB pins has an individually configurable
internal weak pull-up. Control bits WPUB<7:0> enable or
disable each pull-up (see Register 3-7). Each weak
pull-up is automatically turned off when the port pin is
configured as an output. All pull-ups are disabled on a
Power-on Reset by the RBPU bit of the OPTION register.

Posted: 21 Jan 2010 12:41
by piort
hi,
you can try

Code: Select all

procedure init;
begin
TRISB := 1 ;                  // port B input
option_reg.7 := 0 ;         // enable individual pull-up
WPUB := %11111111 ;   // all port b are in weak pull-up
end;
HTH a bit ;-)

Posted: 21 Jan 2010 23:46
by brkovich
piort wrote:hi,
you can try

Code: Select all

procedure init;
begin
TRISB := 1 ;                  // port B input
option_reg.7 := 0 ;         // enable individual pull-up
WPUB := %11111111 ;   // all port b are in weak pull-up
end;
HTH a bit ;-)
Yes I figured it out my self that you must use the bits number not name, something you can use with other registers.

Is the WPUB := %11111111 ; line needed if I wish all portb to have pull ups? Doesn't line option_reg.7 := 0 ; enables all at once?

Posted: 22 Jan 2010 01:21
by janni
brkovich wrote:Is the WPUB := %11111111 ; line needed if I wish all portb to have pull ups? Doesn't line option_reg.7 := 0 ; enables all at once?
No, it enables those that have respective WPUB bit set. Naturally, you may assume that WPUB is $FF at power-up (default state). Just don't complain if some day your application misbehaves :wink: .

Re:

Posted: 22 Mar 2011 19:36
by silvestro71
anikolic wrote:http://ww1.microchip.com/downloads/en/D ... df#page=49
3.4.2 WEAK PULL-UPS
Each of the PORTB pins has an individually configurable
internal weak pull-up. Control bits WPUB<7:0> enable or
disable each pull-up (see Register 3-7). Each weak
pull-up is automatically turned off when the port pin is
configured as an output. All pull-ups are disabled on a
Power-on Reset by the RBPU bit of the OPTION register.
hello!!
with regard to internal pull up for 16F690,
I am trying to put on portC the pulluped bits of protA but it does NOT WORK
here is the code

Code: Select all

//test per i pull up interni
//OSSERVAZIONE
// per la porta a non funziona per la b si :-(
void main()
{
trisa=0xff;
ANSEL=0;
ANSELH=0;
trisc=0;
OPTION_REG = (OPTION_REG & 0b01111111);
WPUA=0xFF;
do
{
portc =(porta>>4);
}
while(1);
}
the sampe code for portB works nicely.
Please can you tell me why??

Re: how to enable internal pull ups?

Posted: 19 Feb 2012 10:40
by programmer5
silvestro71 its working.

Re: how to enable internal pull ups?

Posted: 15 Aug 2015 09:45
by rimaaratri
so, how to enable internal pull ups portB for my pic16f877a? portB are i used to interface with keypad 4x4

Re: how to enable internal pull ups?

Posted: 15 Aug 2015 13:11
by hadv
As usual it's all in the datasheet...read the section about PORTB or do a search for "pull"

Re: how to enable internal pull ups?

Posted: 16 Aug 2015 16:32
by rimaaratri
hadv wrote:As usual it's all in the datasheet...read the section about PORTB or do a search for "pull"
I've written code like the one on datasheet but my keypad is still not working, so what's wrong with my code?

Re: how to enable internal pull ups?

Posted: 29 May 2023 18:40
by dariods
How to enable weak pull up resistor on all pins of PORTB except RB1 on PIC16F886

Re: how to enable internal pull ups?

Posted: 29 May 2023 20:59
by janni
dariods wrote:
29 May 2023 18:40
How to enable weak pull up resistor on all pins of PORTB except RB1 on PIC16F886
It's explained in the datasheet:
Each of the PORTB pins has an individually configurable
internal weak pull-up. Control bits WPUB<7:0> enable or
disable each pull-up (see Register 3-7). Each weak
pull-up is automatically turned off when the port pin is
configured as an output. All pull-ups are disabled on a
Power-on Reset by the RBPU bit of the OPTION register.
In simple steps:
- set bits in TRISB to declare chosen PORTB pins as inputs,
- clear respective ANSELH bits to declare chosen inputs as digital,
- clear chosen bits in WPUB register,
- clear the the RBPU bit of the OPTION register to activate pull-ups declared in WPUB.

Re: how to enable internal pull ups?

Posted: 30 May 2023 22:18
by dariods
Found the answer

Re: how to enable internal pull ups?

Posted: 30 May 2023 23:01
by janni
dariods wrote:
30 May 2023 22:18
Code example please 🙏
Code depends on what you intend to do with RB1

Code: Select all

 TRISB:=%11111101;  // or %11111111 if RB1 should be an input as well
 ANSELH:=%00000000; // or %00000100 if RB1 (AN10) is to be analog input
 WPUB:=%00000010;
 OPTION_REG.NOT_RBPU:=0;