Thursday, October 8, 2020

Using PORTB internal resistors of PIC16F887 in MikroC

Overview Of PortB and its associate's 

PortB of PIC16F887 is a bi-directional digital I/O. PORTB is its I/O register. It's an 8-bit read/write register. 


The corresponding directional control of PORTB is TRISB (PORTB Tri-State Register) register. Clearing this register to make an output port.


The analog input function is partially multiplexed with this port. The ANSELH (Analog Select High Register) associates with this port in the input operation.


The weak pull up resistors built inside the MCU could be individually turning on by software setting. The WPUB (Weak Pull-Up PORTB Register) turn on and off the internal resistor of PORTB individually.


The RBPU (PortB Pull-up Enable) bit of the OPTION register is the global switch of WPUB. Clearing this bit to enable this feature.

Programming in MikroC

In this example, I use the lower nibble of PORTB as a digital input. This nibble is turned on high by its internal weak pull up resistor configured in software.

Using PORTB internal resistors of PIC16F887 in MikroC
Schematic Diagram

The lower nibble is an input to the higher nibble that connect to four LED(s). 

  1. void main() {
  2. PORTB=0x00; // Clear portb
  3. TRISB=0x0F; // RB0-RB3 input RB4-RB7 output
  4. ANSELH=0x00; // Disable Analog Function
  5. OPTION_REG.NOT_RBPU=0; // Enable weak pullups on portb
  6. WPUB=0x0F; // Enable Weak pullups on RB0:RB3
  7. while(1)
  8. PORTB=PORTB<<4; // Shift left 4 times
  9. }

No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)