how to enable internal pull ups?

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
brkovich
Posts: 32
Joined: 29 Jul 2009 00:44

how to enable internal pull ups?

#1 Post by brkovich » 21 Jan 2010 00:17

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?

brkovich
Posts: 32
Joined: 29 Jul 2009 00:44

#2 Post by brkovich » 21 Jan 2010 11:24

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.

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#3 Post by anikolic » 21 Jan 2010 11:38

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.
Web Department Manager

piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

#4 Post by piort » 21 Jan 2010 12:41

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 ;-)

brkovich
Posts: 32
Joined: 29 Jul 2009 00:44

#5 Post by brkovich » 21 Jan 2010 23:46

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?

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#6 Post by janni » 22 Jan 2010 01:21

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: .

silvestro71
Posts: 2
Joined: 22 Mar 2011 16:54

Re:

#7 Post by silvestro71 » 22 Mar 2011 19:36

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??

programmer5
Posts: 69
Joined: 28 Jan 2012 06:50
Location: Pakistan
Contact:

Re: how to enable internal pull ups?

#8 Post by programmer5 » 19 Feb 2012 10:40

silvestro71 its working.

rimaaratri
Posts: 10
Joined: 09 Aug 2015 14:40

Re: how to enable internal pull ups?

#9 Post by rimaaratri » 15 Aug 2015 09:45

so, how to enable internal pull ups portB for my pic16f877a? portB are i used to interface with keypad 4x4

hadv
Posts: 116
Joined: 29 Mar 2013 12:55

Re: how to enable internal pull ups?

#10 Post by hadv » 15 Aug 2015 13:11

As usual it's all in the datasheet...read the section about PORTB or do a search for "pull"

rimaaratri
Posts: 10
Joined: 09 Aug 2015 14:40

Re: how to enable internal pull ups?

#11 Post by rimaaratri » 16 Aug 2015 16:32

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?

dariods
Posts: 21
Joined: 26 Apr 2023 07:12

Re: how to enable internal pull ups?

#12 Post by dariods » 29 May 2023 18:40

How to enable weak pull up resistor on all pins of PORTB except RB1 on PIC16F886

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: how to enable internal pull ups?

#13 Post by janni » 29 May 2023 20:59

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.

dariods
Posts: 21
Joined: 26 Apr 2023 07:12

Re: how to enable internal pull ups?

#14 Post by dariods » 30 May 2023 22:18

Found the answer
Last edited by dariods on 31 May 2023 18:16, edited 1 time in total.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: how to enable internal pull ups?

#15 Post by janni » 30 May 2023 23:01

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;

Post Reply

Return to “mikroPascal PRO for PIC General”