Serial+Recieve

Serial Recieve Routine with required startup conditions. See Global Variables code
 * 1) define NULL   0
 * 2) define BUFFLENGTH   64 // String recvbufer length.


 * 1) include 
 * 2) pragma config WDT = OFF

//Global variables volatile unsigned char recvbuf[BUFFLENGTH]; volatile unsigned char* recvbuf_iPtr; volatile unsigned char* recvbuf_ePtr;

//Function Prototypes void Setup(void); void high_isr(void);

//Interrupt declaration. void interruptHigh(void) {   _asm GOTO high_isr _endasm }
 * 1) pragma code high_vector=0x0008
 * 1) pragma code

//**************************************************************** void main (void) {   recvbuf_iPtr = &recvbuf[0]; //initialise insertion pointer recvbuf_ePtr = &recvbuf[0]; //initialise removal pointer

Setup;

while (1) {   // do nothing. } }

void high_isr(void) {   INTCONbits.GIE = 0;    // Catch interrupt PIR1bits.RCIF = 0;   // Clear RC flag

if (RCREG == 0x0D | RCREG == 0x0A) {   // Place special handling for 'enter' here. }

*recvbuf_iPtr = RCREG;   // Place recieved char into insertion location

recvbuf_iPtr = recvbuf_iPtr++;               // Increment insertion pointer. if (recvbuf_iPtr >= recvbuf + BUFFLENGTH) {       recvbuf_iPtr = recvbuf; }

INTCONbits.GIE = 1;       // reset interrupt - clear flag etc. }

void Setup(void) {   TXSTAbits.BRGH = 1; SPBRG = 25;               // Baud rate at 9600

TRISCbits.TRISC6 = 0;   // PortC 6 is input

TXSTAbits.SYNC = 0;       // Asynchronous mode RCSTAbits.SPEN = 1;       // Enable serial port

// Initialise RS232 RC - with interrupts

PIR1bits.RCIF = 0;       // Clear RC flag PIE1bits.RCIE = 1;       // Enable RC interrupt. IPR1bits.RCIP = 1;       // High Priority for RC interrupts

RCSTAbits.CREN = 1;       // Enable RC

INTCONbits.PEIE = 1; INTCONbits.GIE = 1;       // Enabling interrupts

} code