Weak Pull-up

by CatsEyes

You can use an external resistor from a PIC pin up to the 5 volt rail to "pull up" the pin,  but there is a more sophisticated way to do it that saves parts.

 
Built right into the 12F629/675, and many other PICs, is the weak pull-up (WPU) capability.  The WPU is just an internal resistor to the + supply within the PIC that you can set from the code.  It works very well for situations like a configuration jumper and allows you to eliminate the external pull-up resistor. In essence, it replaces the external pull-up resistor with an internal one.
 
The WPU register (page 20) sets the weak pull-ups individually by pin.  But, the GPPU bit (bit 7) of the OPTION_REG register (page 12) must be cleared as a global "enable" bit. 

Note: if you want to test if it's working, the internal pull-up resistor is small enough that it will weakly light an LED on the pin. It is suggested you put a small resistor in series in case you accidentally switched the pin to an output. For example, see the diagram.

 
Circuit by CatsEyes
 
This should glow weakly if you've configured the weak pull-up correctly for that pin.

 If it glows brightly, you're outputting a "1"  !!!

 

 

 

As a simple example, let us suppose that you are trying to use GP1 in a configuration routine.  You need to start off with the GP1 pin tied high (reading as 1) so that when the jumper is capped, the path to ground will be completed and the pin will read as 0 (zero).  The assembler code (which can be embedded in PicBasic Pro with the ASM....ENDASM syntax) looks like this:
 
ASM
 

 

MOVLW

B'0xxxxxxx', W

; GPIO Pull-ups enabled

 

MOVWF

OPTION_REG

 

 

BSF

STATUS, RP0

; Bank 1

 

MOVLW

B'00000010', W

; Pull-up on GP1 enabled

 

MOVWF

WPU

 

 

BCF

STATUS, RP0

; Bank 0

 

ENDASM
 
Replace the "x"s in the first line with whatever else you need to configure in OPTION_REG (TMR0 clock, prescaler, etc.). As shown, bit 7 (first bit) should be zero to enable weak pull-ups on a global basis.
 
Next,  load the WPU register with the particular pins you want weak pull-ups on. The example shows it for GP1 only. Since WPU is in Bank 1, we have to set the bank bit before loading this register and clear it after.