Serial Port Complete - Latest Microcontroller projects

(lily) #1
Ports for Embedded Systems

When IPEN = 0:
Bit 7 (GIE) enables or disables all unmasked interrupts.
Bit 6 (PEIE) enables or disables all unmasked peripheral interrupts.
When IPEN = 1:
Bit 7 (GIEH) enables or disables all high-priority interrupts.
Bit 6 (GIEL) enables or disables all low-priority peripheral interrupts.


$
 "

  5
: ":
The peripheral interrupt enable register 1 (PIE1) enables interrupts for a variety
of peripheral sources. Two bits relate to serial ports.
Bit 5 (RCIE) enables the serial-port’s receive interrupt. The interrupt occurs
when the PIR1 register’s RCIF bit = 1.
Bit 4 (TXIE) enables the serial port’s transmit interrupt. The interrupt occurs
when the PIR1 register’s TXIF bit = 1.

6
 


Using a serial port involves the operations of enabling the port, configuring
interrupts if used, and transmitting and receiving data.

    $ 


To enable the asynchronous serial port for transmitting and receiving 8-bit
data, firmware should perform the following tasks:


  1. Select values to configure the chip for the desired bit rate. Set the TXSTA
    register’s BRGH bit and the BAUDCON register’s BRG16 bit to the desired
    values. To set the bit rate, write a value to SPBRG and to SPBRGH if used.

  2. In the TXSTA register, set SYNC = 0 to select asynchronous mode.

  3. In the RCSTA register, set SPEN = 1 to enable the serial port.

Free download pdf