Each of PIC16F877A microcontroller PORTB pins has an internal weak pull-up. A single control bit can turn on all the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak pull-up is automatically turned off when the port pin is configured as an output. The pull-ups are disabled on Power-on Reset.
This small article shows how to enable PIC16F877A PORTB internal pull-ups using CCS C compiler.
The following CCS C compiler line can enable all the internal pull-ups of PORTB:
port_b_pullups(true) ;
And the following line can disable all the internal pull-ups of PORTB:
port_b_pullups(false) ;
Enable PIC16F877A PORTB internal pull-ups example:
This is a simple example shows how to enable and use of the internal pull-ups of PIC16F877A. This example was done using external pull-ups resistors in the following topic:
PIC16F877A PORTB interrupt on change with CCS C compiler
In this example the same circuit is used without the external pull-up resistors as shown in the following circuit schematic:
As we can see in the circuit above there are no external pull-up resistors connected with the microcontroller inputs.
The PIC16F877A microcontroller power pins are #11 & #32 for VDD and #12 & #31 for VSS. A voltage of 5V is applied at VDD and VSS pins (not shown in circuit schematic).
The microcontroller used in this example does not have an internal oscillator, therefor an external crystal of 8 MHz is used as a clock source.
Note that for the PIC16F877A microcontroller only PORTB has weak internal pull-ups.
Hardware Required:
- PIC16F877A microcontroller —> datasheet
- 8 MHz crystal oscillator
- 2 x 22 pF ceramic capacitor
- 4 x LED
- 4 x Push button
- 4 x 330 ohm resistor
- 10k ohm resistor
- Breadboard and jumper wires
- 5V power source
- PIC microcontroller programmer (PICkit 3, PICkit 4…)
Enable PIC16F877A PORTB internal pull-ups CCS C code:
The C code below is for CCS C compiler, it was tested with version 5.051.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // Enable PIC16F877A PORTB internal pull-ups C code // https://simple-circuit.com/ #include <16F877A.h> #use delay(crystal=8000000) byte i; #INT_RB void rb_isr(void) { i = input_b(); output_d(i >> 4); } void main() { set_tris_b(0xF0); port_b_pullups(TRUE); // Enable PORTB internal weak pull-ups clear_interrupt(INT_RB); // Clear RB IOC flag bit enable_interrupts(INT_RB); // Enable RB port IOC enable_interrupts(GLOBAL); // Enable global interrupts while(TRUE) ; // Endless loop } |
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.