Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 11


This code sets up an ISR to respond to received serial-port data:
// Interrupt vector for high-priority interrupts.

#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.
}

. 
 
 


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.
Free download pdf