#pragma code high_vector = 0x8 void interrupt_at_high_vector void // Define the function to execute on an interrupt. _asm goto high_isr _endasm // The ISR function. #pragma interrupt high_isr void high_isr void if PIR1bits.RCIF == 1 && PIE1bits.RCIE == 1 // The serial port has received a byte. // Place code to read and respond to received data here. // Reset the ISR flag. PIR1bits.RCIF = 0; // Check the interrupt flags for any other enabled interrupts. Using Flow Control Microcontrollers typically require firmware support for hardware flow control. When the firmware has data to send, a hardware interrupt or firmware polling can detect when the flow-control input is in the required state. When receiving data, firmware can set the flow-control output as needed to prevent overruns. To use hardware flow control on a hardware serial port, select any two otherwise unused port bits and configure one bit as an input and the other as an output. 256 Ports for Embedded Systems Sending Data When sending data, firmware can read the flow-control input and wait if needed before writing a byte to TXREG. In normal operation, the waits should be short, but it’s always possible the remote computer will malfunction and leave its flow-control output de-asserted for a long time. For efficient operation, firmware should minimize the time devoted to waiting for the flow-control input to change state and provide a way to bail out if the wait goes on too long. Tools that can help include timers, task loops, and hardware interrupts. Firmware with data to send can start a timeout timer and end the wait if the flow-control input isn’t asserted after the timer times out. This approach can work well if the waits are normally short or infrequent. In a task loop, the device performs communications and other tasks as needed in an endless loop. On each pass through the loop, a device with data to send reads the flow-control input. If the input isn’t asserted, firmware moves on to prom-electric.ru