PIC16C782 Microchip Technology Inc., PIC16C782 Datasheet - Page 37

no-image

PIC16C782

Manufacturer Part Number
PIC16C782
Description
8-bit Cmos Microcontrollers With A/d, D/a, Opamp, Comparators And Psmc
Manufacturer
Microchip Technology Inc.
Datasheet

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
PIC16C782/JW
Manufacturer:
AD
Quantity:
580
3.3
PORTB is an 8-bit wide, bi-directional port. The corre-
sponding data direction register is TRISB. Setting a
TRISB bit (= 1) makes the corresponding PORTB pin
an input (i.e., puts the corresponding output driver into
a Hi-Impedance mode). Clearing a TRISB bit (= 0)
makes the corresponding PORTB pin an output (i.e.,
puts the contents of the output latch on the selected
pin.
EXAMPLE 3-2:
;* This code block will configure PORT B
;* as follows
;*
;*
;*
;*
;*
The RB0 pin can be configured as:
• Digital I/O
• ADC/Comparator Analog Input (AN4)
• External Interrupt (INT)
• Voltage Reference Output (V
When the pin is used as an analog I/O, the ANSEL reg-
ister must have bit 4 set to configure the RB0 pin as an
analog input.
Pin RB1 is multiplexed with two analog functions: ADC/
Comparator Analog Input AN5, and the output of the
DAC. When the pin is used as an analog I/O, the
ANSEL register must have bit 5 set to configure the
RB1 pin as an analog I/O.
2001 Microchip Technology Inc.
RB<7:6> analog inputs
RB<5:4> digital inputs
RB<3:2> digital inputs
RB<1:0> digital inputs
RA<3:0> digital I/O
BANKSEL
CLRF
BANKSEL
MOVLW
MOVWF
MOVLW
MOVWF
PORTB and the TRISB Register
PORTB
PORTB
TRISB
B’11001111’ ; Digital I/O
TRISB
B’00000011’ ; Analog I/O config
ANSEL
INITIALIZING PORTB
R
; Select Bank 0
; Preset PORTB data
; reg.
; Select Bank 1
;
; Configure PORTB
; digital
; data
; Configure PORTB
; analog
)
config data
Preliminary
Pin RB2 is multiplexed with the analog function ADC/
Comparator Input AN6. When the pin is used as an
analog input, the ANSEL register must have bit 6 to
select the Analog mode for the pin.
The RB3 pin is multiplexed with two analog functions:
ADC/Comparator Analog Input AN7, and the output of
the OPA module. When the pin is used as analog I/O,
the ANSEL register must have bit 7 set to select the
Analog mode of the pin.
Pins RB<7:6> are multiplexed with the outputs of the
two on-board comparators, the outputs of the PSMC
module, and the clock gate input for Timer1. Note,
when enabled, these peripherals override the PORTB
data register; however, TRISB retains control of output
drivers. Therefore, TRISB<7:6> must be programmed
appropriately for Comparator and PSMC outputs to
operate.
3.3.1
Each of the PORTB pins has an internal weak pull-up
resistance, which can be individually enabled from the
WPUB register. A single global enable bit, RBPU
(OPTION_REG<7>), can turn on/off all of the selected
pull-ups. Clearing the RBPU bit (OPTION_REG<7>)
enables the weak pull-up resistors (see Register 3-2).
The weak pull-up is automatically turned off when the
port pin is configured as an output. The pull-ups are dis-
abled on a Power-on Reset.
3.3.2
Each of the PORTB pins, if configured as input, has the
ability to generate an interrupt-on-change. To enable
the interrupt-on-change feature, the corresponding bit
must be set in the IOCB register (see Register 3-3).
The RBIE bit in the INTCON register functions as a glo-
bal enable bit to turn on/off the interrupt-on-change fea-
ture. The selected inputs are compared to the old value
latched on the last read of PORTB. The ”mismatch”
outputs are OR-ed together to generate the RB Port
Change Interrupt with flag bit RBIF (INTCON<0>).
The IOCB interrupt can also awaken the device from
SLEEP. The user, in the Interrupt Service Routine,
must clear the interrupt in the following manner:
a)
b)
A read or write to PORTB. This copies the cur-
rent state into the latch and ends the mismatch
condition.
Clear flag bit RBIF.
PORTB WEAK PULL-UP
PORTB INTERRUPT-ON-CHANGE
PIC16C781/782
DS41171A-page 35

Related parts for PIC16C782