|
|||||||||||||||||||||||||||||||||||||||||
►Ports
All port pins can be designated as input or
output, according to the needs of a device that's being developed. In
order to define a pin as input or output pin, the right combination of
zeros and ones must be written in TRIS register. If the appropriate bit of
TRIS register contains logical "1", then that pin is an input pin, and if
the opposite is true, it's an output pin. Every port has its proper TRIS
register. Thus, port A has TRISA, and port B has TRISB. Pin direction can
be changed during the course of work which is particularly fitting for
one-line communication where data flow constantly changes direction. PORTA
and PORTB state registers are located in bank 0, while TRISA and TRISB pin
direction registers are located in bank 1.
Each
PORTB pin has a weak internal pull-up resistor (resistor which defines a
line to logic one) which can be activated by resetting the seventh bit
RBPU in OPTION register. These 'pull-up' resistors are automatically being
turned off when port pin is configured as an output. When a
microcontroller is started, pull-ups are disabled.
The above example shows how pins 0, 1, 2, and 3 are designated input, and pins 4, 5, 6, and 7 for output, after which PORTB output pins are set to one. 2.
PORTA and TRISA It is important to note that PORTA pin RA4 can be input only. On that pin is also situated an external input for timer TMR0. Whether RA4 will be a standard input or an input for a counter depends on T0CS bit (TMR0 Clock Source Select bit). This pin enables the timer TMR0 to increment either from internal oscillator or via external impulses on RA4/T0CKI pin. NOTE: RA4 pin can be designated output, but in that case it has to be externally connected to PULL-UP resistor. Configuring port A:
Example shows how pins 0, 1, 2, 3, and 4 are designated input, and pins 5, 6, and 7 output. After this, it is possible to read the pins RA2, RA3, RA4, and to set logical zero or one to pins RA0 and RA1.
|
|||||||||||||||||||||||||||||||||||||||||