|
||||
The execution of the Interrupt routine takes a lot of time, and it would probably slow down the UART communication to a few hundred bytes per second. This is valid both for polling and interrupt service, as the interrupt for UART must have the lower priority than the OCx Interrupt routine. That is why the UART service i integrated in OCx Interrupt routine. It polls the state of SFR flags and reads/writes bytes to the SFR buffers after each horizontal sync. Routine uart_service does that. It is not placed in the subroutine, but used as macro and (together with Keyboard routine) placed several times in the Interrupt routine. This macro is named EXTRAJOB. You should note that this macro has no arguments and that it might be organized as the subroutine, but reason for using macro is the execution speed. There are two 256-byte (128-word) circular buffers: RX_CIRCULAR and TX_CIRCULAR. They are aligned to the full 256-byte pages in the program. Although UART uses 8-bit communication, circular buffers are organized as 128 words, so the 9-bit UART modes are covered. In fact, PIC24 and dsPIC33 family has 16-bit RX and TX buffers, so the whole 16-bit buffers are read/written from/to the circular buffers. The UART service program is very short and simple, and no UART status bits are serviced by the Interrupt routine. User can check the error status for the whole received packet in the main program, outside the Interrupt routine. UART interface is not initialized in this program. User has to do that, according to his own requirements. Only UART 1 is covered in this routine. UART 2 is ignored. |
||||
|
||||
Note: Sorry, this part of the program was not tested yet. |
||||
Here is the listing for RX_TEST and TX_TEST subroutines:
rx_test: |
||||