#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#pragma config "FOSC=XT"
#pragma config "WDTE=OFF"
#pragma config "BOREN=OFF"
#pragma config "LVP=OFF"
#pragma config "DEBUG=OFF"
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif
#define BAUDRATE 9600
void InitUART (void);
/*
*
*/
int main(int argc, char** argv)
{
unsigned char ReceiveChar;
//
InitUART();
//
while(1)
{
if(RCIF==1)
{
ReceiveChar=RCREG;
if(TXIF==1)
{
TXREG=ReceiveChar+0x01;
}
}
}
return (EXIT_SUCCESS);
}
void InitUART (void)
{
SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) -1;
BRGH = 1; //Baud Rate Generator High Speed 1
SYNC = 0; //Asynchronous mode 0
SPEN = 1; //Serial Port Enable Bit 1
CREN = 1; //Continuous Receive Enable Bit Enable continuous receive 1
SREN = 0; //dont care in asynchronous mode
TXIE = 0; //USART Transmit Interrupt Enable Bit , disable the USART transmit interrupt
RCIE = 0; //USART Receive Interrupt Enable Bit , Enable the USART receive interrupt
TX9 = 0; // 9bit transmit enable bit 0 select 8bit tran
RX9 = 0; // 9bit receive enable bit 0 select 8bit recep
TXEN = 0; // Transmit Enable Bit Transmit disabled 0
TXEN = 1; // Transmit Enable Bit Transmit enable 1
TRISCbits.TRISC6 = 0; // This sets pin RC6 to output (USART asynchronous transmit or synchronous clock)
TRISCbits.TRISC7 = 1; // This sets pin RC7 to input (USART asynchronous receive or synchronous data)
GIE = 0 ;//Global Interrupt Enable Bit: 1 Enables all unmasked interrupts
PEIE = 0 ;//Peripheral Interrupt Enable Bit : 1 Enables all unmasked peripherals interrupts
}