#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
unsigned char HSerin(void);
void HSerout(unsigned char ch), HSerinit(void);
void main(void) // program entry
{
int index = 0;
unsigned char ch;
ADCON1 = 0x6; // Analogue off
HSerinit();
__delay_ms(250);
while(1) // endless Loop
{
//ch = HSerin(); // wait for a character
HSerout; // Echo back
}
}
void HSerinit()
{
TRISC = 0b10000000; // should ideally be set
SPBRG = 129; // 20Mhz xtal 9600 BAUD
TXSTA = 0x24; // TXEN and BRGH
RCSTA = 0x90; // SPEN and CREN
}
void HSerout(unsigned char ch)
{
while(!TXIF); // Wait for module to finish
TXREG = '0'; // ready to send
}
/