//
// UART Echo Example without putc and getc
// By PEK '2004
//
// MCU: 16F877
// Clock: 10 MHz
//
// To be used with the CCS compiler
//

#include <16F877.h>
#use delay(clock=10000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io(B)

// Registers in hardware
#BYTE RCSTA = 0x0018
#BYTE TXREG = 0x0019
#BYTE RCREG = 0x001A

// Bits in hardware
#bit CREN = 0x0018.4


#int_RDA
void RDA_isr()
{
   // Check for errors
   if(RCSTA & 0x06)
   {
      CREN = 0;   // Clear error status
      CREN = 1;

      output_high(PIN_B0); // Tells the user about the error
   }
   else
   {
      TXREG = RCREG + 1;
   }
}


void main()
{
   output_low(PIN_B0);  // No errors from the beginning
   set_tris_b(0xFE);    // Set pin 0 as output

   enable_interrupts(INT_RDA);   // Enable Rx interrupt
   enable_interrupts(GLOBAL);    // Enable Global interrupts

   while(1);
}

