Here it is...........
Rich (BB code):
include <pic.h> // pic specific identifiers
#define _XTAL_FREQ 20000000 // Xtal speed
__CONFIG(0x3F71); // Config bits // Required prototypes.. each function needs to be declared // if called BEFORE definition.
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(150);
while(1) // endless Loop
{ ch = HSerin(); // wait for a character HSerout(ch); // 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 = ch; // ready to send
}
unsigned char HSerin()
{ while(!RCIF); // Wait for a character
return RCREG; // return character
}