Microcontroller Operation:Arithmetic and Logic Unit and Port Registers

Arithmetic and Logic Unit

This is a combinational logic block that takes one or two input binary words and combines them to produce an arithmetic or logical result. In the PIC, it can operate directly on the contents of a register, but if a pair of data bytes is being processed (e.g. added together), one must be in W. The ALU is set up according to the requirements of the instruction being executed by the timing and control block. Typical ALU/register operations are detailed later in this chapter.

Port Registers

Input and output in a microcontroller are achieved by simply reading or writing a port data register. If a binary code is presented to the input pins of the chip by an external device (e.g. a set of switches), the data is latched into the register allocated to that port when it is read in the program. This input data can then be moved (or more accurately, copied) into another register for processing. If a port register is initialized for output, the code moved to its data register is immediately available at the pins of the chip. It can then be displayed externally, for example, on a set of light-emitting diodes (LEDs).

Each port has a ‘data direction’ register associated with its data register. This allows each pin to be set individually as an input or output before the data is read from or written to the port data register. A ‘0’ in the data direction register sets the port bit as an output, and a ‘1’ sets it as an input. These port registers are mapped (addressed) as SFRs, starting from register 05 for port A, 06 for port B, and so on in the original PIC 16 specification. In more recently introduced chips (e.g. 16LF1826), which need more registers, the ports start at 0Ch (h is a suffix indicating a hexadecimal number; see Appendix A). The port data direction registers are mapped into a second register bank (bank 1) with addresses starting at 85h for port A, 86h for port B, and so on.

Leave a comment

Your email address will not be published. Required fields are marked *