Why both LATB and PORTB? Because reading PORTB always reads the state of the pin, whether the pin is an input or output. If the pin is configured as an output, then writing to either the LATB or PORTB registers will change the state of the output pin. If the pin is configured as an input, then reading the port will read the state of the pin. So only the device that is set to 0 (ground) actively controls the line. When the open-drain output is set to 1, it is put into a high-impedance state, same as an input. Why open-drain? One reason is it allows several devices to drive the same line, which is connected to a pull-up resistor. Setting the associated bit in ODCB makes the pin open-drain, and setting it to 0 makes it push-pull. Push-pull means the pin can both "source" voltage (set the output to a high voltage equal to Vcc), or sink current the same as an open-drain output. it can control an output already connected to a positive voltage, such as an LED, or other I/O peripheral connected to Vcc (the system voltage) by turning it off. Open-drain means the pin only "sinks" current, i.e. This is done with the ODCB register (open drain control register), Setting the associated bit in TRISB makes the pin an input, and setting it to 0 makes it an output.Įach pin, if configured as an output, can also be configured as either open-drain or push-pull. I think DDR is a better name for this register then TRIS.) (On some other microcontrollers, this is called a Data Direction register, or DDR - DDRB in the case of PORT B. The TRISB register determines whether each PORT B pin is an input or output. TRIS states for tri-state, which is a condition where a pin is put into a high impedance state and cannot drive any outputs. The configuration of the port is done via the TRISB and ODCB registers. These registers associated with PORT B in the PIC24FJ64A004 are: Which scheme is used is historical, back in the 1970's Intel started using the separate I/O addressing scheme, and Motorola among others chose to put both I/O and RAM addresses into the same memory space. INP and OUT) which only access these registers. The other scheme, is to have a special address space for I/O registers, and have special instructions (i.e. The advantage here is that all of the instructions that operate on RAM will also work with the I/O registers. There are other microcontrollers in this same processor family that come in a 44-pin package, where additional register pins are defined (RA7-RA10, and RC0-RC9.Īs mentioned earlier, the ports are manipulated through various registers.ĭepending on the type of processor, the registers may appear in the same memory map as the processor's memory (RAM) in this case the addresses are reserved for this purpose and that segment of RAM is not implemented. PORT A which has 5 bits implemented, RA0 through RA4. There is another port that is partially populated, i.e. That is PORT B, and the pins are colored in red in the diagram above. Since this particular chip has only 28-pins, there is only one register that can be fully implemented, that is has pins corresponding to all 16 bits in the I/O register. As shown in the above diagram, the port pins do not necessarily have to be grouped together. Other common data widths (and thus port widths) in microcontrollers are 8 and 32. This processor has a 16-bit architecture, so the ports and registers are all 16-bits wide. Take, for example, this 28-pin microcontroller, which happens to be a PIC24FJ64A004: There is a one-to-one correspondence between the pins on the microcontroller and the bits in its registers. Ports are represented by registers inside the microcontroller, and allow the program (firmware) to control the state of the pins, or conversely, read the state of the pins if they are configured as inputs. The pins are what stick out of an IC, and connect electrically to the outside world.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |