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 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.
Schematic Diagram |
The lower nibble is an input to the higher nibble that connect to four LED(s).
void main() { PORTB=0x00; // Clear portb TRISB=0x0F; // RB0-RB3 input RB4-RB7 output ANSELH=0x00; // Disable Analog Function OPTION_REG.NOT_RBPU=0; // Enable weak pullups on portb WPUB=0x0F; // Enable Weak pullups on RB0:RB3 while(1) PORTB=PORTB<<4; // Shift left 4 times }
No comments:
Post a Comment