Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 11


!   "


To use the transmit and received interrupts without using interrupt priority:


  1. In the PIE1 register, set TXIE = 1 and RCIE = 1.

  2. In the INTCON register, set GIE = 1 and PIE = 1.
    To use the transmit and received interrupts with interrupt priority:

  3. In the RCON register, set IPEN = 1.

  4. In the PIE1 register, set TXIE = 1 and RCIE = 1.

  5. In the IPR1 register, set the interrupt priority in RCIP and TXIP as desired.

  6. In the INTCON register, set GIEH and GIEH to enable interrupts as appro-
    priate for the IPR1 settings.




To transmit a byte, firmware performs these tasks:


  1. To enable transmitting, in the TXSTA register, set TXEN = 1.

  2. If using hardware flow control, check the state of the firmware-defined
    flow-control input bit and wait as needed for permission to transmit.

  3. Write a byte to transmit to TXREG. The byte transfers to the TSR. When
    TXREG is empty, in the PIR1 register, TXIF = 1. On the TX pin, the TSR
    transmits a Start bit, the byte of data, and a Stop bit.
    Firmware can write another byte to TXEN as soon as TXIF = 1. If using inter-
    rupts, firmware will jump to the ISR when TXIF = 1.


5 
To receive a byte, firmware performs these tasks:


  1. To enable receiving, in the RCSTA register, set CREN = 1.

  2. If using hardware flow control, set the firmware-defined flow-control output
    bit to enable receiving.

  3. In the PIR1 register, wait for RCIF = 1, indicating the receive buffer contains
    as least one byte. If using interrupts, firmware will jump to the ISR when RCIF
    = 1.

  4. In the RCSTA register, check the framing error (FERR) and overrun
    (OERR) bits.

  5. Read the received byte in RCREG. Reading the register clears RCIF. If FERR
    = 1, firmware will likely want to discard the received byte.

Free download pdf