Special Function Registers (SFR registers)
In addition to the registers which do not have
any special and predetermined function, every
microcontroller has also a number of registers
whose function is predetermined by the
manufacturer. Their bits are connected (literally)
to internal circuits such as timers, A/D
converter, oscillators and others, which means
that they are directly in command of the
operation of the microcontroller. If you imagine
that as eight switches which are in command of
some smaller circuit within the microcontroller-
you are right! SFRs do exactly that!
Input / Output ports
In order that the microcontroller is of any use, it has to be connected to additional electronics, i.e.
peripherals. For that reason, each microcontroller has one or more registers (called “port” in this case)
connected to the microcontroller pins. Why input/output? Because you can change the pin’s function as you
wish. For example, suppose you want your device to turn on and off three signal LEDs and simultaneously
monitor logic state of five sensors or push buttons. In accordance with that, some of ports should be
configured so that there are three outputs (connected to LEDs) and five inputs (connected to sensors). It is
simply performed by software, which means that pin’s function can be changed during operation.
One of more important feature of I/O pins is maximal current they can give/get. For the most
microcontrollers, current obtained from one pin is sufficient to activate a LED or other similar low-current
consumer (10-20 mA). If the microcontroller has many I/O pins, then maximal current of one pin is lower.
Simply, you cannot expect all pins to give maximal current if there are more than 80 of them on one
microcontroller.
Another important pin feature is to (or not to) have pull-up resistors. These resistors connect pin to positive
power supply voltage and their effect is visible when the pin is configured as input connected to mechanical
switch or push button. The later versions of the microcontrollers have pull-up resistors connected to and
disconnected from the pins by software.
Usually, each I/O port is under control of another
SFR, which means that each bit of that register
determines state of the corresponding microcontroller
pin. For example, by writing logic one (1) to one bit of
that control register SFR, the appropriate port pin is
automatically configured as input. It means that
voltage brought to that pin can be read as logic 0 or 1.
Otherwise, by writing zero to the SFR, the appropriate
port pin is configured as output. Its voltage (0V or 5V)
corresponds to the state of the appropriate bit of the
port register.
Chia sẻ với bạn bè của bạn: |