First, use code tags, they make your program more readable.
Second, what exactly is the problem?
Third, I've put some NOTE's into the code.
Code:
#include <pic.h>
#include <stdio.h>
#define Fosc (4000000L)
void initUSART (void);
void sendBytes (const char *);
void sendByte (char c);
char getByte ();
const char TXstring[] = "\r\n\n\nCommunication port open.Please type a letter:";
char TXrb0[]= "\r\n\nButton pressed";
char buffer[]=" ";
int main ()
{
TRISB = 1 // for button RB0;
initUSART();
ADFM = 1;
sendBytes(TXstring);
while (1)
{
while(RB0) // loops until button is pressed
{
if (RCIF)
sendByte(getByte());
}
sprintf(buffer,"Received:%x\r\n", (int)((ADRESL>2) + (ADRESH<<6)));
sendBytes(buffer);
}
/* NOTE: function main must return a value */
return 0;
}
void initUSART()
{
BRGH = 1; // high speed data rate "Fosc/(16(X+1))
SYNC = 0; //asnchronous serial port
SPEN = 1; //enable serial port pins
CREN = 1; //enable reception
RCIE = 0; //disable rx interrupts
TXIE = 0; //disable tx interrupts
TX9 = 0; //8-bit transmission
RX9 = 0; //8-bit reception
TXEN =1; //enable transmission
CREN = 1; // enable reception
}
void sendBytes (const char *tx)
{
while (*tx != 0)
{
sendByte (*tx++);
}
}
void sendByte(char c)
{
/* NOTE: if TXIF is a variable, then it is usual
to write while (TXIF == 0) */
while (0 == TXIF)
{
TXREG = c;
}
}
char getByte()
{
if (OERR)
{
CREN = 0;
CREN = 1;
if (RCIF)
return RCREG;
else
return 0x00;
}
}