Sunday, March 6, 2016

PIC16F84A Enable PORTB internal pull-ups


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 (OPTION<7>). The weak pull-up is automatically turned off when the port pin is configured as an output.
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) ;
PIC16F84A enable PORTB internal pull-ups example:
The following topic shows how to turn on and off 2 LED using 2 pushbuttons where 2 10K resistors are used to pull-up the microcontroller input pins.
PIC16F84A blink LED using push button
Now let's make the same example with the internal pull-ups are enabled and the external ones are removed as shown in the following circuit schematic:
enable pic16f84a internal pull-up ccs pic c
The circuit is simple there 2 LEDs and 2 buttons each button toggles one LED for example when the first push button which is connected to RB0 is pressed, the first LED which is connected to RA0 turns ON, and when the same button pressed again the same LED turns OFF, and the same thing for the second button and the second LED.
Enable PORTB internal pull-ups CCS PIC C code:
// PIC16F84A enable PORTB internal pull-ups example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=4000000)

void main()
{
  port_b_pullups(true);  // Enable PORTB internal weak pull-ups
  output_low(PIN_A0);
  output_low(PIN_A1);
  while(TRUE)
  {
    if(input(PIN_B0) == 0)
    {
      output_toggle(PIN_A0);
      delay_ms(500);
    }
    if(input(PIN_B1) == 0)
    {
      output_toggle(PIN_A1);
      delay_ms(500);
    }
  }
}